]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormSearch.C
Compile fixes for DEC cxx, John's maths and keymap patches.
[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 using Liason::setMinibuffer;
27 using SigC::slot;
28
29 FormSearch::FormSearch(LyXView * lv, Dialogs * d)
30         : FormBaseBD(lv, d, _("LyX: Find and Replace"))
31 {
32     // let the popup be shown
33     // This is a permanent connection so we won't bother
34     // storing a copy because we won't be disconnecting.
35     d->showSearch.connect(slot(this, &FormSearch::show));
36    // perhaps in the future we'd like a
37    // "search again" button/keybinding
38 //    d->searchAgain.connect(slot(this, &FormSearch::FindNext));
39 }
40
41
42 FL_FORM * FormSearch::form() const
43 {
44     if (dialog_.get()) 
45             return dialog_->form;
46     return 0;
47 }
48
49 void FormSearch::build()
50 {
51    dialog_.reset(build_search());
52    // Workaround dumb xforms sizing bug
53    minw_ = form()->w;
54    minh_ = form()->h;
55         
56    // Manage the ok, apply and cancel/close buttons
57    bc_.setCancel(dialog_->button_cancel);
58    bc_.addReadOnly(dialog_->input_replace);
59    bc_.addReadOnly(dialog_->replace);
60    bc_.addReadOnly(dialog_->replaceall);
61    bc_.refresh();
62 }
63
64 void FormSearch::update()
65 {
66    if (!dialog_.get())
67      return;
68
69    bc_.readOnly(lv_->buffer()->isReadonly());
70 }
71
72 bool FormSearch::input(FL_OBJECT * obj, long)
73 {
74    if (obj == dialog_->findnext)
75      Find();
76    else if (obj == dialog_->findprev)
77      Find(false);
78    else if (obj == dialog_->replace)
79      Replace();
80    else if (obj == dialog_->replaceall)
81      Replace(true);
82    
83    return 0;
84 }
85
86 void FormSearch::Find(bool const next)
87 {
88    bool found = LyXFind(lv_->view(),
89                         fl_get_input(dialog_->input_search),
90                         fl_get_button(dialog_->casesensitive),
91                         fl_get_button(dialog_->matchword),
92                         next);
93    
94    if (!found)
95      setMinibuffer(lv_, _("String not found!"));
96 }
97
98
99 void FormSearch::Replace(bool const all)
100 {
101    int replace_count = LyXReplace(lv_->view(),
102                                   fl_get_input(dialog_->input_search),
103                                   fl_get_input(dialog_->input_replace),
104                                   fl_get_button(dialog_->casesensitive),
105                                   fl_get_button(dialog_->matchword), 
106                                   true, 
107                                   all);
108                                   
109    if (replace_count == 0) {
110       setMinibuffer(lv_, _("String not found!"));
111    } else {
112       if (replace_count == 1) {
113          setMinibuffer(lv_, _("String has been replaced."));
114       } else {
115          string str = tostr(replace_count);
116          str += _(" strings have been replaced.");
117          setMinibuffer(lv_, str.c_str());
118       }
119    }
120 }
121
122