]> git.lyx.org Git - features.git/blob - src/lyxfind.h
AdvSearch - next patch from Tommaso.
[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 & search,
47                                  docstring const & replace,
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 find(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  */
64 void replace(BufferView * bv, FuncRequest const &, bool has_deleted = false);
65
66 /// find the next change in the buffer
67 bool findNextChange(BufferView * bv);
68
69 class FindAdvOptions {
70 public:
71         FindAdvOptions(
72                 docstring const & search,
73                 bool casesensitive,
74                 bool matchword,
75                 bool forward,
76                 bool expandmacros,
77                 bool ignoreformat,
78                 bool regexp
79         );
80         FindAdvOptions() {  }
81         docstring search;
82         bool casesensitive;
83         bool matchword;
84         bool forward;
85         bool expandmacros;
86         bool ignoreformat;
87         bool regexp;
88 };
89
90 /// Write a FindAdvOptions instance to a stringstream
91 std::ostringstream & operator<<(std::ostringstream & os, lyx::FindAdvOptions const & opt);
92
93 /// Read a FindAdvOptions instance from a stringstream
94 std::istringstream & operator>>(std::istringstream & is, lyx::FindAdvOptions & opt);
95
96 /// Dispatch a LFUN_WORD_FINDADV command request
97 void findAdv(BufferView * bv, FuncRequest const & ev);
98
99 /// Perform a FindAdv operation.
100 bool findAdv(BufferView * bv, FindAdvOptions const & opt);
101         
102 /** Computes the simple-text or LaTeX export (depending on opt) of buf starting
103  ** from cur and ending len positions after cur, if len is positive, or at the
104  ** paragraph or innermost inset end if len is -1.
105  **
106  ** This is useful for computing opt.search from the SearchAdvDialog controller (ControlSearchAdv).
107  ** Ideally, this should not be needed, and the opt.search field should become a Text const &.
108  **/
109 docstring stringifyFromForSearch(
110         FindAdvOptions const & opt,
111         DocIterator const & cur,
112         int len = -1);
113
114 } // namespace lyx
115
116 #endif // LYXFIND_H