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