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