]> git.lyx.org Git - features.git/blob - src/lyxfind.h
#8055 correct processing of LFUN_WORD_FIND option flags for repeated search operations
[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 /** Parse the string encoding of the replace request that is found in
67  *  \c ev.argument and act on it.
68  * The string is encoded by \c replace2string.
69  * \return whether we did anything
70  */
71 bool lyxreplace(BufferView * bv, FuncRequest const &);
72
73 /// find the next change in the buffer
74 bool findNextChange(BufferView * bv);
75
76 /// find the previous change in the buffer
77 bool findPreviousChange(BufferView * bv);
78
79 /// select change under the cursor
80 bool selectChange(Cursor & cur, bool forward = true);
81
82
83 class FindAndReplaceOptions {
84 public:
85         typedef enum {
86                 S_BUFFER,
87                 S_DOCUMENT,
88                 S_OPEN_BUFFERS,
89                 S_ALL_MANUALS
90         } SearchScope;
91         typedef enum {
92                 R_EVERYTHING,
93                 R_ONLY_MATHS
94         } SearchRestriction;
95         FindAndReplaceOptions(
96                 docstring const & find_buf_name,
97                 bool casesensitive,
98                 bool matchword,
99                 bool forward,
100                 bool expandmacros,
101                 bool ignoreformat,
102                 docstring const & repl_buf_name,
103                 bool keep_case,
104                 SearchScope scope = S_BUFFER,
105                 SearchRestriction restr = R_EVERYTHING,
106                 bool replace_all = false
107         );
108
109         FindAndReplaceOptions() {}
110
111         docstring find_buf_name;
112         bool casesensitive = false;
113         bool matchword = false;
114         bool forward = false;
115         bool matchAtStart = false;
116         bool expandmacros = false;
117         bool ignoreformat = false;
118         /// This is docstring() if no replace was requested
119         docstring repl_buf_name;
120         bool keep_case = false;
121         SearchScope scope = S_BUFFER;
122         SearchRestriction restr = R_EVERYTHING;
123         bool replace_all = false;
124 };
125
126 /// Set the formats that should be ignored
127 void setIgnoreFormat(std::string const & type, bool value);
128
129 /// Write a FindAdvOptions instance to a stringstream
130 std::ostringstream & operator<<(std::ostringstream & os, lyx::FindAndReplaceOptions const & opt);
131
132 /// Read a FindAdvOptions instance from a stringstream
133 std::istringstream & operator>>(std::istringstream & is, lyx::FindAndReplaceOptions & opt);
134
135 /// Perform a FindAdv operation.
136 bool findAdv(BufferView * bv, FindAndReplaceOptions & opt);
137
138 /** Computes the simple-text or LaTeX export (depending on opt) of buf starting
139  ** from cur and ending len positions after cur, if len is positive, or at the
140  ** paragraph or innermost inset end if len is -1.
141  **
142  ** This is useful for computing opt.search from the SearchAdvDialog controller (ControlSearchAdv).
143  ** Ideally, this should not be needed, and the opt.search field should become a Text const &.
144  **/
145 docstring stringifyFromForSearch(
146         FindAndReplaceOptions const & opt,
147         DocIterator const & cur,
148         int len = -1);
149
150
151 } // namespace lyx
152
153 #endif // LYXFIND_H