]> git.lyx.org Git - features.git/blob - src/lyxfind.h
Change how some of the updating stuff is handled in lyxfind. I had no
[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
27
28 class Buffer;
29 class BufferView;
30 class DocIterator;
31 class FuncRequest;
32 class Text;
33
34 /** Encode the parameters needed to find \c search as a string
35  *  that can be dispatched to the LyX core in a FuncRequest wrapper.
36  */
37 docstring const find2string(docstring const & search,
38                               bool casesensitive,
39                               bool matchword,
40                               bool forward);
41
42 /** Encode the parameters needed to replace \c search with \c replace
43  *  as a string that can be dispatched to the LyX core in a FuncRequest
44  *  wrapper.
45  */
46 docstring const replace2string(docstring const & replace,
47                                  docstring const & search,
48                                  bool casesensitive,
49                                  bool matchword,
50                                  bool all,
51                                  bool forward);
52
53 /** Parse the string encoding of the find request that is found in
54  *  \c ev.argument and act on it.
55  * The string is encoded by \c find2string.
56  * \return true if the string was found.
57  */
58 bool lyxfind(BufferView * bv, FuncRequest const & ev);
59
60 /** Parse the string encoding of the replace request that is found in
61  *  \c ev.argument and act on it.
62  * The string is encoded by \c replace2string.
63  * \return whether we did anything
64  */
65 bool lyxreplace(BufferView * bv, FuncRequest const &, bool has_deleted = false);
66
67 /// find the next change in the buffer
68 bool findNextChange(BufferView * bv);
69
70 /// find the previous change in the buffer
71 bool findPreviousChange(BufferView * bv);
72
73 /// find the change in the buffer
74 /// \param next true to find the next change, otherwise the previous
75 bool findChange(BufferView * bv, bool next);
76
77 // Hopefully, nobody will ever replace with something like this
78 #define LYX_FR_NULL_STRING "__LYX__F&R__NULL__STRING__"
79
80 class FindAndReplaceOptions {
81 public:
82         typedef enum {
83                 S_BUFFER,
84                 S_DOCUMENT,
85                 S_OPEN_BUFFERS,
86                 S_ALL_MANUALS
87         } SearchScope;
88         FindAndReplaceOptions(
89                 docstring const & search,
90                 bool casesensitive,
91                 bool matchword,
92                 bool forward,
93                 bool expandmacros,
94                 bool ignoreformat,
95                 bool regexp,
96                 docstring const & replace,
97                 bool keep_case,
98                 SearchScope scope = S_BUFFER
99         );
100         FindAndReplaceOptions() {  }
101         docstring search;
102         bool casesensitive;
103         bool matchword;
104         bool forward;
105         bool expandmacros;
106         bool ignoreformat;
107         bool regexp;
108         docstring replace;
109         bool keep_case;
110         SearchScope scope;
111 };
112
113 /// Write a FindAdvOptions instance to a stringstream
114 std::ostringstream & operator<<(std::ostringstream & os, lyx::FindAndReplaceOptions const & opt);
115
116 /// Read a FindAdvOptions instance from a stringstream
117 std::istringstream & operator>>(std::istringstream & is, lyx::FindAndReplaceOptions & opt);
118
119 /// Perform a FindAdv operation.
120 bool findAdv(BufferView * bv, FindAndReplaceOptions const & opt);
121         
122 /** Computes the simple-text or LaTeX export (depending on opt) of buf starting
123  ** from cur and ending len positions after cur, if len is positive, or at the
124  ** paragraph or innermost inset end if len is -1.
125  **
126  ** This is useful for computing opt.search from the SearchAdvDialog controller (ControlSearchAdv).
127  ** Ideally, this should not be needed, and the opt.search field should become a Text const &.
128  **/
129 docstring stringifyFromForSearch(
130         FindAndReplaceOptions const & opt,
131         DocIterator const & cur,
132         int len = -1);
133
134 } // namespace lyx
135
136 #endif // LYXFIND_H