/**
* \file FormSearch.C
- * Copyright 2001 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
* \author Edwin Leuven
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
#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"
-
-#ifdef CXX_WORKING_NAMESPACES
-using Liason::setMinibuffer;
-#endif
-
-
-FormSearch::FormSearch(LyXView * lv, Dialogs * d)
- : FormBaseBD(lv, d, _("LyX: Find and Replace"), new NoRepeatedApplyReadOnlyPolicy),
- dialog_(0)
-{
- // 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));
-}
+#include "ControlSearch.h"
+#include "forms/form_search.h"
+#include "Tooltips.h"
+#include "xforms_helpers.h"
+#include "xformsBC.h"
-FormSearch::~FormSearch()
-{
- delete dialog_;
-}
+#include "lyx_forms.h"
-FL_FORM * FormSearch::form() const
-{
- if (dialog_)
- return dialog_->form;
- return 0;
-}
+using std::string;
-void FormSearch::build()
-{
- dialog_ = build_search();
- // Workaround dumb xforms sizing bug
- minw_ = form()->w;
- minh_ = form()->h;
-
- // 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()
-{
- if (!dialog_)
- return;
+typedef FormCB<ControlSearch, FormDB<FD_search> > base_class;
- bc_.readOnly(lv_->buffer()->isReadonly());
-}
+FormSearch::FormSearch()
+ : base_class(_("Find and Replace"))
+{}
-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;
-}
-void FormSearch::Find(bool const next)
+void FormSearch::build()
{
- 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!"));
+ dialog_.reset(build_search(this));
+
+ // Manage the ok, apply and cancel/close buttons
+ bcview().setCancel(dialog_->button_close);
+
+ // disable for read-only documents
+ bcview().addReadOnly(dialog_->input_replace);
+ bcview().addReadOnly(dialog_->button_replace);
+ bcview().addReadOnly(dialog_->button_replaceall);
+
+ // set up the tooltips
+ string str = _("Enter the string you want to find.");
+ tooltips().init(dialog_->input_search, str);
+ str = _("Enter the replacement string.");
+ tooltips().init(dialog_->input_replace, str);
+ str = _("Continue to next search result.");
+ tooltips().init(dialog_->button_findnext, str);
+ str = _("Replace search result by replacement string.");
+ tooltips().init(dialog_->button_replace, str);
+ str = _("Replace all by replacement string.");
+ tooltips().init(dialog_->button_replaceall, str);
+ str = _("Do case sensitive search.");
+ tooltips().init(dialog_->check_casesensitive, str);
+ str = _("Search only matching words.");
+ tooltips().init(dialog_->check_matchword, str);
+ str = _("Search backwards.");
+ tooltips().init(dialog_->check_searchbackwards, str);
}
-void FormSearch::Replace(bool const all)
+void FormSearch::update()
{
- 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());
- }
- }
+ fl_set_input_selected(dialog_->input_search, true);
+ fl_set_focus_object(dialog_->form, dialog_->input_search);
}
+ButtonPolicy::SMInput FormSearch::input(FL_OBJECT * ob, long)
+{
+ if (ob == dialog_->button_findnext) {
+ controller().find(getString(dialog_->input_search),
+ fl_get_button(dialog_->check_casesensitive),
+ fl_get_button(dialog_->check_matchword),
+ !fl_get_button(dialog_->check_searchbackwards));
+
+ } else if (ob == dialog_->button_replace || ob == dialog_->button_replaceall) {
+ bool const all = (ob == dialog_->button_replaceall);
+
+ controller().replace(getString(dialog_->input_search),
+ getString(dialog_->input_replace),
+ fl_get_button(dialog_->check_casesensitive),
+ fl_get_button(dialog_->check_matchword),
+ !fl_get_button(dialog_->check_searchbackwards),
+ all);
+ }
+
+ return ButtonPolicy::SMI_VALID;
+}