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