]> git.lyx.org Git - lyx.git/blob - src/lyxfind.h
ChangesMonitor: beware of exceptions in destructor
[lyx.git] / src / lyxfind.h
1 // -*- C++ -*-
2 /**
3  * \file lyxfind.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author John Levon
9  * \author Jürgen Vigna
10  * \author Alfredo Braunstein
11  * \author Tommaso Cucinotta
12  *
13  * Full author contact details are available in file CREDITS.
14  */
15
16 #ifndef LYXFIND_H
17 #define LYXFIND_H
18
19 #include "support/strfwd.h"
20
21 // FIXME
22 #include "support/docstring.h"
23
24 namespace lyx {
25
26 class Cursor;
27 class BufferView;
28 class DocIterator;
29 class FuncRequest;
30
31 /** Encode the parameters needed to find \c search as a string
32  *  that can be dispatched to the LyX core in a FuncRequest wrapper.
33  */
34 docstring const find2string(docstring const & search,
35                               bool casesensitive,
36                               bool matchword,
37                               bool forward);
38
39 /** Encode the parameters needed to replace \c search with \c replace
40  *  as a string that can be dispatched to the LyX core in a FuncRequest
41  *  wrapper.
42  */
43 docstring const replace2string(docstring const & replace,
44                                  docstring const & search,
45                                  bool casesensitive,
46                                  bool matchword,
47                                  bool all,
48                                  bool forward,
49                                  bool findnext = true);
50
51 /** Parse the string encoding of the find request that is found in
52  *  \c ev.argument and act on it.
53  * The string is encoded by \c find2string.
54  * \return true if the string was found.
55  */
56 bool lyxfind(BufferView * bv, FuncRequest const & ev);
57
58 /** Parse the string encoding of the replace request that is found in
59  *  \c ev.argument and act on it.
60  * The string is encoded by \c replace2string.
61  * \return whether we did anything
62  */
63 bool lyxreplace(BufferView * bv, FuncRequest const &);
64
65 /// find the next change in the buffer
66 bool findNextChange(BufferView * bv);
67
68 /// find the previous change in the buffer
69 bool findPreviousChange(BufferView * bv);
70
71 /// select change under the cursor
72 bool selectChange(Cursor & cur, bool forward = true);
73
74
75 class FindAndReplaceOptions {
76 public:
77         typedef enum {
78                 S_BUFFER,
79                 S_DOCUMENT,
80                 S_OPEN_BUFFERS,
81                 S_ALL_MANUALS
82         } SearchScope;
83         typedef enum {
84                 R_EVERYTHING,
85                 R_ONLY_MATHS
86         } SearchRestriction;
87         FindAndReplaceOptions(
88                 docstring const & find_buf_name,
89                 bool casesensitive,
90                 bool matchword,
91                 bool forward,
92                 bool expandmacros,
93                 bool ignoreformat,
94                 docstring const & repl_buf_name,
95                 bool keep_case,
96                 SearchScope scope = S_BUFFER,
97                 SearchRestriction restr = R_EVERYTHING,
98                 bool replace_all = false
99         );
100
101         FindAndReplaceOptions() {}
102
103         docstring find_buf_name;
104         bool casesensitive = false;
105         bool matchword = false;
106         bool forward = false;
107         bool matchAtStart = false;
108         bool expandmacros = false;
109         bool ignoreformat = false;
110         /// This is docstring() if no replace was requested
111         docstring repl_buf_name;
112         bool keep_case = false;
113         SearchScope scope = S_BUFFER;
114         SearchRestriction restr = R_EVERYTHING;
115         bool replace_all = false;
116 };
117
118 /// Set the formats that should be ignored
119 void setIgnoreFormat(std::string const & type, bool value);
120
121 /// Write a FindAdvOptions instance to a stringstream
122 std::ostringstream & operator<<(std::ostringstream & os, lyx::FindAndReplaceOptions const & opt);
123
124 /// Read a FindAdvOptions instance from a stringstream
125 std::istringstream & operator>>(std::istringstream & is, lyx::FindAndReplaceOptions & opt);
126
127 /// Perform a FindAdv operation.
128 bool findAdv(BufferView * bv, FindAndReplaceOptions & opt);
129
130 /** Computes the simple-text or LaTeX export (depending on opt) of buf starting
131  ** from cur and ending len positions after cur, if len is positive, or at the
132  ** paragraph or innermost inset end if len is -1.
133  **
134  ** This is useful for computing opt.search from the SearchAdvDialog controller (ControlSearchAdv).
135  ** Ideally, this should not be needed, and the opt.search field should become a Text const &.
136  **/
137 docstring stringifyFromForSearch(
138         FindAndReplaceOptions const & opt,
139         DocIterator const & cur,
140         int len = -1);
141
142
143 } // namespace lyx
144
145 #endif // LYXFIND_H