2001-03-06 10:20:33 +00:00
|
|
|
/**
|
|
|
|
* \file FormSearch.C
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-03-15 13:37:04 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
#include "FormSearch.h"
|
|
|
|
#include "form_search.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "Liason.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyxfind.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
using Liason::setMinibuffer;
|
2001-03-16 12:08:14 +00:00
|
|
|
using SigC::slot;
|
2001-03-06 10:20:33 +00:00
|
|
|
|
|
|
|
FormSearch::FormSearch(LyXView * lv, Dialogs * d)
|
2001-03-15 13:37:04 +00:00
|
|
|
: FormBaseBD(lv, d, _("LyX: Find and Replace"))
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
|
|
|
// let the popup be shown
|
|
|
|
// This is a permanent connection so we won't bother
|
|
|
|
// storing a copy because we won't be disconnecting.
|
|
|
|
d->showSearch.connect(slot(this, &FormSearch::show));
|
|
|
|
// perhaps in the future we'd like a
|
|
|
|
// "search again" button/keybinding
|
|
|
|
// d->searchAgain.connect(slot(this, &FormSearch::FindNext));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FL_FORM * FormSearch::form() const
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
if (dialog_.get())
|
|
|
|
return dialog_->form;
|
2001-03-06 10:20:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormSearch::build()
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
dialog_.reset(build_search());
|
2001-03-06 10:20:33 +00:00
|
|
|
|
|
|
|
// Manage the ok, apply and cancel/close buttons
|
|
|
|
bc_.setCancel(dialog_->button_cancel);
|
|
|
|
bc_.addReadOnly(dialog_->input_replace);
|
|
|
|
bc_.addReadOnly(dialog_->replace);
|
|
|
|
bc_.addReadOnly(dialog_->replaceall);
|
|
|
|
bc_.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormSearch::update()
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
if (!dialog_.get())
|
2001-03-06 10:20:33 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bc_.readOnly(lv_->buffer()->isReadonly());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FormSearch::input(FL_OBJECT * obj, long)
|
|
|
|
{
|
|
|
|
if (obj == dialog_->findnext)
|
|
|
|
Find();
|
|
|
|
else if (obj == dialog_->findprev)
|
|
|
|
Find(false);
|
|
|
|
else if (obj == dialog_->replace)
|
|
|
|
Replace();
|
|
|
|
else if (obj == dialog_->replaceall)
|
|
|
|
Replace(true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-06 11:05:15 +00:00
|
|
|
void FormSearch::Find(bool const next)
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
|
|
|
bool found = LyXFind(lv_->view(),
|
|
|
|
fl_get_input(dialog_->input_search),
|
|
|
|
fl_get_button(dialog_->casesensitive),
|
|
|
|
fl_get_button(dialog_->matchword),
|
|
|
|
next);
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
setMinibuffer(lv_, _("String not found!"));
|
2001-03-06 11:05:15 +00:00
|
|
|
}
|
2001-03-06 10:20:33 +00:00
|
|
|
|
|
|
|
|
2001-03-06 11:05:15 +00:00
|
|
|
void FormSearch::Replace(bool const all)
|
2001-03-06 10:20:33 +00:00
|
|
|
{
|
|
|
|
int replace_count = LyXReplace(lv_->view(),
|
|
|
|
fl_get_input(dialog_->input_search),
|
|
|
|
fl_get_input(dialog_->input_replace),
|
|
|
|
fl_get_button(dialog_->casesensitive),
|
|
|
|
fl_get_button(dialog_->matchword),
|
|
|
|
true,
|
|
|
|
all);
|
|
|
|
|
|
|
|
if (replace_count == 0) {
|
|
|
|
setMinibuffer(lv_, _("String not found!"));
|
|
|
|
} else {
|
|
|
|
if (replace_count == 1) {
|
|
|
|
setMinibuffer(lv_, _("String has been replaced."));
|
|
|
|
} else {
|
|
|
|
string str = tostr(replace_count);
|
|
|
|
str += _(" strings have been replaced.");
|
|
|
|
setMinibuffer(lv_, str.c_str());
|
|
|
|
}
|
|
|
|
}
|
2001-03-06 11:05:15 +00:00
|
|
|
}
|
2001-03-06 10:20:33 +00:00
|
|
|
|
|
|
|
|