]> git.lyx.org Git - lyx.git/blob - src/lyxfind.h
Added possibility to retrieve internal buffers (by their tmp file-name) from the...
[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
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, 
66                 FuncRequest const &, bool has_deleted = false);
67
68 /// find the next change in the buffer
69 bool findNextChange(BufferView * bv);
70
71 /// find the previous change in the buffer
72 bool findPreviousChange(BufferView * bv);
73
74 /// find the change in the buffer
75 /// \param next true to find the next change, otherwise the previous
76 bool findChange(BufferView * bv, bool next);
77
78 // Hopefully, nobody will ever replace with something like this
79 #define LYX_FR_NULL_STRING "__LYX__F&R__NULL__STRING__"
80
81 class FindAndReplaceOptions {
82 public:
83         typedef enum {
84                 S_BUFFER,
85                 S_DOCUMENT,
86                 S_OPEN_BUFFERS,
87                 S_ALL_MANUALS
88         } SearchScope;
89         FindAndReplaceOptions(
90                 docstring const & search,
91                 bool casesensitive,
92                 bool matchword,
93                 bool forward,
94                 bool expandmacros,
95                 bool ignoreformat,
96                 bool regexp,
97                 docstring const & replace,
98                 bool keep_case,
99                 SearchScope scope = S_BUFFER
100         );
101         FindAndReplaceOptions() {  }
102         docstring search;
103         bool casesensitive;
104         bool matchword;
105         bool forward;
106         bool expandmacros;
107         bool ignoreformat;
108         bool regexp;
109         docstring replace;
110         bool keep_case;
111         SearchScope scope;
112 };
113
114 /// Write a FindAdvOptions instance to a stringstream
115 std::ostringstream & operator<<(std::ostringstream & os, lyx::FindAndReplaceOptions const & opt);
116
117 /// Read a FindAdvOptions instance from a stringstream
118 std::istringstream & operator>>(std::istringstream & is, lyx::FindAndReplaceOptions & opt);
119
120 /// Perform a FindAdv operation.
121 bool findAdv(BufferView * bv, FindAndReplaceOptions const & opt);
122         
123 /** Computes the simple-text or LaTeX export (depending on opt) of buf starting
124  ** from cur and ending len positions after cur, if len is positive, or at the
125  ** paragraph or innermost inset end if len is -1.
126  **
127  ** This is useful for computing opt.search from the SearchAdvDialog controller (ControlSearchAdv).
128  ** Ideally, this should not be needed, and the opt.search field should become a Text const &.
129  **/
130 docstring stringifyFromForSearch(
131         FindAndReplaceOptions const & opt,
132         DocIterator const & cur,
133         int len = -1);
134
135 } // namespace lyx
136
137 #endif // LYXFIND_H