]> git.lyx.org Git - lyx.git/blob - src/lyxfind.h
Remove 3rdparty/boost/Makefile.am
[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,
64                 FuncRequest const &, bool has_deleted = false);
65
66 /// find the next change in the buffer
67 bool findNextChange(BufferView * bv);
68
69 /// find the previous change in the buffer
70 bool findPreviousChange(BufferView * bv);
71
72 /// select change under the cursor
73 bool selectChange(Cursor & cur, bool forward = true);
74
75
76 class FindAndReplaceOptions {
77 public:
78         typedef enum {
79                 S_BUFFER,
80                 S_DOCUMENT,
81                 S_OPEN_BUFFERS,
82                 S_ALL_MANUALS
83         } SearchScope;
84         typedef enum {
85                 R_EVERYTHING,
86                 R_ONLY_MATHS
87         } SearchRestriction;
88         FindAndReplaceOptions(
89                 docstring const & find_buf_name,
90                 bool casesensitive,
91                 bool matchword,
92                 bool forward,
93                 bool expandmacros,
94                 bool ignoreformat,
95                 docstring const & repl_buf_name,
96                 bool keep_case,
97                 SearchScope scope = S_BUFFER,
98                 SearchRestriction restr = R_EVERYTHING,
99                 bool replace_all = false
100         );
101         FindAndReplaceOptions() : casesensitive(false), matchword(false), forward(false),
102                                   expandmacros(false), ignoreformat(false),
103                                   keep_case(false), scope(S_BUFFER), restr(R_EVERYTHING), replace_all(false) {}
104         docstring find_buf_name;
105         bool casesensitive;
106         bool matchword;
107         bool forward;
108         bool expandmacros;
109         bool ignoreformat;
110         /// This is docstring() if no replace was requested
111         docstring repl_buf_name;
112         bool keep_case;
113         SearchScope scope;
114         SearchRestriction restr;
115         bool replace_all;
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 const & 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