]> git.lyx.org Git - lyx.git/blob - src/lyxfind.h
Add Benjamin Piwowarski to contributors. Welcome to 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 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                                  bool findnext = true);
53
54 /** Parse the string encoding of the find request that is found in
55  *  \c ev.argument and act on it.
56  * The string is encoded by \c find2string.
57  * \return true if the string was found.
58  */
59 bool lyxfind(BufferView * bv, FuncRequest const & ev);
60
61 /** Parse the string encoding of the replace request that is found in
62  *  \c ev.argument and act on it.
63  * The string is encoded by \c replace2string.
64  * \return whether we did anything
65  */
66 bool lyxreplace(BufferView * bv, 
67                 FuncRequest const &, bool has_deleted = false);
68
69 /// find the next change in the buffer
70 bool findNextChange(BufferView * bv);
71
72 /// find the previous change in the buffer
73 bool findPreviousChange(BufferView * bv);
74
75 /// find the change in the buffer
76 /// \param next true to find the next change, otherwise the previous
77 bool findChange(BufferView * bv, bool next);
78
79 class FindAndReplaceOptions {
80 public:
81         typedef enum {
82                 S_BUFFER,
83                 S_DOCUMENT,
84                 S_OPEN_BUFFERS,
85                 S_ALL_MANUALS
86         } SearchScope;
87         FindAndReplaceOptions(
88                 docstring const & find_buf_name,
89                 bool casesensitive,
90                 bool matchword,
91                 bool forward,
92                 bool expandmacros,
93                 bool ignoreformat,
94                 docstring const & repl_buf_name,
95                 bool keep_case,
96                 SearchScope scope = S_BUFFER
97         );
98         FindAndReplaceOptions() {  }
99         docstring find_buf_name;
100         bool casesensitive;
101         bool matchword;
102         bool forward;
103         bool expandmacros;
104         bool ignoreformat;
105         /// This is docstring() if no replace was requested
106         docstring repl_buf_name;
107         bool keep_case;
108         SearchScope scope;
109 };
110
111 /// Write a FindAdvOptions instance to a stringstream
112 std::ostringstream & operator<<(std::ostringstream & os, lyx::FindAndReplaceOptions const & opt);
113
114 /// Read a FindAdvOptions instance from a stringstream
115 std::istringstream & operator>>(std::istringstream & is, lyx::FindAndReplaceOptions & opt);
116
117 /// Perform a FindAdv operation.
118 bool findAdv(BufferView * bv, FindAndReplaceOptions const & opt);
119         
120 /** Computes the simple-text or LaTeX export (depending on opt) of buf starting
121  ** from cur and ending len positions after cur, if len is positive, or at the
122  ** paragraph or innermost inset end if len is -1.
123  **
124  ** This is useful for computing opt.search from the SearchAdvDialog controller (ControlSearchAdv).
125  ** Ideally, this should not be needed, and the opt.search field should become a Text const &.
126  **/
127 docstring stringifyFromForSearch(
128         FindAndReplaceOptions const & opt,
129         DocIterator const & cur,
130         int len = -1);
131
132 } // namespace lyx
133
134 #endif // LYXFIND_H