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