]> git.lyx.org Git - features.git/blob - src/lyxfind.h
FindAdv: Use global declaration for findOne() to be usefull for unit tests
[features.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 /** Decode the \c argument to extract search plus options from a string
32  *  that came to the LyX core in a FuncRequest wrapper.
33  */
34 docstring const string2find(docstring const & argument,
35                               bool &casesensitive,
36                               bool &matchword,
37                               bool &forward);
38
39 /** Encode the parameters needed to find \c search as a string
40  *  that can be dispatched to the LyX core in a FuncRequest wrapper.
41  */
42 docstring const find2string(docstring const & search,
43                               bool casesensitive,
44                               bool matchword,
45                               bool forward);
46
47 /** Encode the parameters needed to replace \c search with \c replace
48  *  as a string that can be dispatched to the LyX core in a FuncRequest
49  *  wrapper.
50  */
51 docstring const replace2string(docstring const & replace,
52                                  docstring const & search,
53                                  bool casesensitive,
54                                  bool matchword,
55                                  bool all,
56                                  bool forward,
57                                  bool findnext = true);
58
59 /** Parse the string encoding of the find request that is found in
60  *  \c ev.argument and act on it.
61  * The string is encoded by \c find2string.
62  * \return true if the string was found.
63  */
64 bool lyxfind(BufferView * bv, FuncRequest const & ev);
65
66 bool findOne(BufferView * bv, docstring const & searchstr,
67              bool case_sens, bool whole, bool forward,
68              bool find_del = true, bool check_wrap = false);
69
70 /** Parse the string encoding of the replace request that is found in
71  *  \c ev.argument and act on it.
72  * The string is encoded by \c replace2string.
73  * \return whether we did anything
74  */
75 bool lyxreplace(BufferView * bv, FuncRequest const &);
76
77 /// find the next change in the buffer
78 bool findNextChange(BufferView * bv);
79
80 /// find the previous change in the buffer
81 bool findPreviousChange(BufferView * bv);
82
83 /// select change under the cursor
84 bool selectChange(Cursor & cur, bool forward = true);
85
86
87 class FindAndReplaceOptions {
88 public:
89         typedef enum {
90                 S_BUFFER,
91                 S_DOCUMENT,
92                 S_OPEN_BUFFERS,
93                 S_ALL_MANUALS
94         } SearchScope;
95         typedef enum {
96                 R_EVERYTHING,
97                 R_ONLY_MATHS
98         } SearchRestriction;
99         FindAndReplaceOptions(
100                 docstring const & find_buf_name,
101                 bool casesensitive,
102                 bool matchword,
103                 bool forward,
104                 bool expandmacros,
105                 bool ignoreformat,
106                 docstring const & repl_buf_name,
107                 bool keep_case,
108                 SearchScope scope = S_BUFFER,
109                 SearchRestriction restr = R_EVERYTHING,
110                 bool replace_all = false
111         );
112
113         FindAndReplaceOptions() {}
114
115         docstring find_buf_name;
116         bool casesensitive = false;
117         bool matchword = false;
118         bool forward = false;
119         bool matchAtStart = false;
120         bool expandmacros = false;
121         bool ignoreformat = false;
122         /// This is docstring() if no replace was requested
123         docstring repl_buf_name;
124         bool keep_case = false;
125         SearchScope scope = S_BUFFER;
126         SearchRestriction restr = R_EVERYTHING;
127         bool replace_all = false;
128 };
129
130 /// Set the formats that should be ignored
131 void setIgnoreFormat(std::string const & type, bool value, bool fromUser = true);
132
133 /// Write a FindAdvOptions instance to a stringstream
134 std::ostringstream & operator<<(std::ostringstream & os, lyx::FindAndReplaceOptions const & opt);
135
136 /// Read a FindAdvOptions instance from a stringstream
137 std::istringstream & operator>>(std::istringstream & is, lyx::FindAndReplaceOptions & opt);
138
139 /// Perform a FindAdv operation.
140 bool findAdv(BufferView * bv, FindAndReplaceOptions & opt);
141
142 /** Computes the simple-text or LaTeX export (depending on opt) of buf starting
143  ** from cur and ending len positions after cur, if len is positive, or at the
144  ** paragraph or innermost inset end if len is -1.
145  **
146  ** This is useful for computing opt.search from the SearchAdvDialog controller (ControlSearchAdv).
147  ** Ideally, this should not be needed, and the opt.search field should become a Text const &.
148  **/
149 docstring stringifyFromForSearch(
150         FindAndReplaceOptions const & opt,
151         DocIterator const & cur,
152         int len = -1);
153
154
155 } // namespace lyx
156
157 #endif // LYXFIND_H