]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormSearch.C
Merging BRANCH_MVC back into HEAD.
[lyx.git] / src / frontends / xforms / FormSearch.C
1 /**
2  * \file FormSearch.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Edwin Leuven
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "FormSearch.h"
16 #include "form_search.h"
17 #include "gettext.h"
18 #include "Dialogs.h"
19 #include "Liason.h"
20 #include "LyXView.h"
21 #include "buffer.h"
22 #include "gettext.h"
23 #include "lyxfind.h"
24 #include "debug.h"
25
26 #ifdef CXX_WORKING_NAMESPACES
27 using Liason::setMinibuffer;
28 #endif
29
30
31 FormSearch::FormSearch(LyXView * lv, Dialogs * d)
32         : FormBaseBD(lv, d, _("LyX: Find and Replace"))
33 {
34     // let the popup be shown
35     // This is a permanent connection so we won't bother
36     // storing a copy because we won't be disconnecting.
37     d->showSearch.connect(slot(this, &FormSearch::show));
38    // perhaps in the future we'd like a
39    // "search again" button/keybinding
40 //    d->searchAgain.connect(slot(this, &FormSearch::FindNext));
41 }
42
43
44 FL_FORM * FormSearch::form() const
45 {
46     if (dialog_.get()) 
47             return dialog_->form;
48     return 0;
49 }
50
51 void FormSearch::build()
52 {
53    dialog_.reset(build_search());
54    // Workaround dumb xforms sizing bug
55    minw_ = form()->w;
56    minh_ = form()->h;
57         
58    // Manage the ok, apply and cancel/close buttons
59    bc_.setCancel(dialog_->button_cancel);
60    bc_.addReadOnly(dialog_->input_replace);
61    bc_.addReadOnly(dialog_->replace);
62    bc_.addReadOnly(dialog_->replaceall);
63    bc_.refresh();
64 }
65
66 void FormSearch::update()
67 {
68    if (!dialog_.get())
69      return;
70
71    bc_.readOnly(lv_->buffer()->isReadonly());
72 }
73
74 bool FormSearch::input(FL_OBJECT * obj, long)
75 {
76    if (obj == dialog_->findnext)
77      Find();
78    else if (obj == dialog_->findprev)
79      Find(false);
80    else if (obj == dialog_->replace)
81      Replace();
82    else if (obj == dialog_->replaceall)
83      Replace(true);
84    
85    return 0;
86 }
87
88 void FormSearch::Find(bool const next)
89 {
90    bool found = LyXFind(lv_->view(),
91                         fl_get_input(dialog_->input_search),
92                         fl_get_button(dialog_->casesensitive),
93                         fl_get_button(dialog_->matchword),
94                         next);
95    
96    if (!found)
97      setMinibuffer(lv_, _("String not found!"));
98 }
99
100
101 void FormSearch::Replace(bool const all)
102 {
103    int replace_count = LyXReplace(lv_->view(),
104                                   fl_get_input(dialog_->input_search),
105                                   fl_get_input(dialog_->input_replace),
106                                   fl_get_button(dialog_->casesensitive),
107                                   fl_get_button(dialog_->matchword), 
108                                   true, 
109                                   all);
110                                   
111    if (replace_count == 0) {
112       setMinibuffer(lv_, _("String not found!"));
113    } else {
114       if (replace_count == 1) {
115          setMinibuffer(lv_, _("String has been replaced."));
116       } else {
117          string str = tostr(replace_count);
118          str += _(" strings have been replaced.");
119          setMinibuffer(lv_, str.c_str());
120       }
121    }
122 }
123
124