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