2001-06-14 08:20:41 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
/**
|
|
|
|
* \file lyxfind.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
2003-11-04 12:01:15 +00:00
|
|
|
* \author Alfredo Braunstein
|
2008-11-15 23:30:27 +00:00
|
|
|
* \author Tommaso Cucinotta
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2001-03-06 10:20:33 +00:00
|
|
|
#ifndef LYXFIND_H
|
|
|
|
#define LYXFIND_H
|
|
|
|
|
2007-10-31 22:40:34 +00:00
|
|
|
#include "support/strfwd.h"
|
2003-10-07 06:45:25 +00:00
|
|
|
|
2008-11-15 23:30:27 +00:00
|
|
|
// FIXME
|
|
|
|
#include "support/docstring.h"
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2014-10-14 07:58:40 +00:00
|
|
|
class Cursor;
|
2001-03-06 10:20:33 +00:00
|
|
|
class BufferView;
|
2008-11-15 23:30:27 +00:00
|
|
|
class DocIterator;
|
2004-01-07 17:00:03 +00:00
|
|
|
class FuncRequest;
|
2001-03-06 10:20:33 +00:00
|
|
|
|
2021-02-12 21:20:02 +00:00
|
|
|
/** Decode the \c argument to extract search plus options from a string
|
|
|
|
* that came to the LyX core in a FuncRequest wrapper.
|
|
|
|
*/
|
|
|
|
docstring const string2find(docstring const & argument,
|
|
|
|
bool &casesensitive,
|
|
|
|
bool &matchword,
|
2021-02-15 10:30:03 +00:00
|
|
|
bool &forward,
|
2021-02-15 13:12:07 +00:00
|
|
|
bool &wrap,
|
2021-02-16 07:11:09 +00:00
|
|
|
bool &instant,
|
|
|
|
bool &onlysel);
|
2021-02-12 21:20:02 +00:00
|
|
|
|
2004-01-07 17:00:03 +00:00
|
|
|
/** Encode the parameters needed to find \c search as a string
|
|
|
|
* that can be dispatched to the LyX core in a FuncRequest wrapper.
|
2003-11-04 12:01:15 +00:00
|
|
|
*/
|
2006-12-10 11:52:46 +00:00
|
|
|
docstring const find2string(docstring const & search,
|
2004-01-07 17:00:03 +00:00
|
|
|
bool casesensitive,
|
|
|
|
bool matchword,
|
2021-02-15 10:30:03 +00:00
|
|
|
bool forward,
|
2021-02-15 13:12:07 +00:00
|
|
|
bool wrap,
|
2021-02-16 07:11:09 +00:00
|
|
|
bool instant,
|
|
|
|
bool onlysel);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2004-01-07 17:00:03 +00:00
|
|
|
/** Encode the parameters needed to replace \c search with \c replace
|
|
|
|
* as a string that can be dispatched to the LyX core in a FuncRequest
|
|
|
|
* wrapper.
|
2002-06-18 15:44:30 +00:00
|
|
|
*/
|
2009-07-04 23:02:27 +00:00
|
|
|
docstring const replace2string(docstring const & replace,
|
|
|
|
docstring const & search,
|
2004-01-07 17:00:03 +00:00
|
|
|
bool casesensitive,
|
|
|
|
bool matchword,
|
|
|
|
bool all,
|
2011-05-18 20:33:57 +00:00
|
|
|
bool forward,
|
2021-02-15 10:30:03 +00:00
|
|
|
bool findnext = true,
|
2021-02-16 07:11:09 +00:00
|
|
|
bool wrap = true,
|
|
|
|
bool onlysel = false);
|
2003-11-04 12:01:15 +00:00
|
|
|
|
2004-01-07 17:00:03 +00:00
|
|
|
/** Parse the string encoding of the find request that is found in
|
|
|
|
* \c ev.argument and act on it.
|
|
|
|
* The string is encoded by \c find2string.
|
2008-02-10 18:52:32 +00:00
|
|
|
* \return true if the string was found.
|
2002-06-18 15:44:30 +00:00
|
|
|
*/
|
2010-10-13 18:53:41 +00:00
|
|
|
bool lyxfind(BufferView * bv, FuncRequest const & ev);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2021-02-14 08:08:23 +00:00
|
|
|
bool findOne(BufferView * bv, docstring const & searchstr,
|
|
|
|
bool case_sens, bool whole, bool forward,
|
2021-02-15 10:30:03 +00:00
|
|
|
bool find_del = true, bool check_wrap = false,
|
2021-06-02 03:59:40 +00:00
|
|
|
bool const auto_wrap = false, bool instant = false,
|
2021-02-16 07:11:09 +00:00
|
|
|
bool onlysel = false);
|
2021-02-14 08:08:23 +00:00
|
|
|
|
2004-01-07 17:00:03 +00:00
|
|
|
/** Parse the string encoding of the replace request that is found in
|
|
|
|
* \c ev.argument and act on it.
|
|
|
|
* The string is encoded by \c replace2string.
|
2010-10-13 18:53:41 +00:00
|
|
|
* \return whether we did anything
|
2004-01-07 17:00:03 +00:00
|
|
|
*/
|
2021-01-12 15:13:47 +00:00
|
|
|
bool lyxreplace(BufferView * bv, FuncRequest const &);
|
2001-03-06 10:20:33 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
/// find the next change in the buffer
|
|
|
|
bool findNextChange(BufferView * bv);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2009-04-05 19:11:25 +00:00
|
|
|
/// find the previous change in the buffer
|
|
|
|
bool findPreviousChange(BufferView * bv);
|
|
|
|
|
2014-10-14 07:58:40 +00:00
|
|
|
/// select change under the cursor
|
|
|
|
bool selectChange(Cursor & cur, bool forward = true);
|
|
|
|
|
|
|
|
|
2009-01-14 15:34:56 +00:00
|
|
|
class FindAndReplaceOptions {
|
2008-11-15 23:30:27 +00:00
|
|
|
public:
|
2009-12-30 18:40:18 +00:00
|
|
|
typedef enum {
|
|
|
|
S_BUFFER,
|
|
|
|
S_DOCUMENT,
|
|
|
|
S_OPEN_BUFFERS,
|
2010-01-09 22:49:35 +00:00
|
|
|
S_ALL_MANUALS
|
2009-12-30 18:40:18 +00:00
|
|
|
} SearchScope;
|
2013-08-23 19:36:50 +00:00
|
|
|
typedef enum {
|
|
|
|
R_EVERYTHING,
|
|
|
|
R_ONLY_MATHS
|
|
|
|
} SearchRestriction;
|
2009-01-14 15:34:56 +00:00
|
|
|
FindAndReplaceOptions(
|
2011-02-07 23:55:02 +00:00
|
|
|
docstring const & find_buf_name,
|
2008-12-20 16:00:47 +00:00
|
|
|
bool casesensitive,
|
|
|
|
bool matchword,
|
|
|
|
bool forward,
|
|
|
|
bool expandmacros,
|
|
|
|
bool ignoreformat,
|
2011-02-07 23:55:02 +00:00
|
|
|
docstring const & repl_buf_name,
|
2009-12-30 18:40:18 +00:00
|
|
|
bool keep_case,
|
2013-08-23 19:36:50 +00:00
|
|
|
SearchScope scope = S_BUFFER,
|
2019-03-13 13:06:18 +00:00
|
|
|
SearchRestriction restr = R_EVERYTHING,
|
|
|
|
bool replace_all = false
|
2008-12-20 16:00:47 +00:00
|
|
|
);
|
2021-01-29 17:35:38 +00:00
|
|
|
|
|
|
|
FindAndReplaceOptions() {}
|
|
|
|
|
2011-02-07 23:55:02 +00:00
|
|
|
docstring find_buf_name;
|
2021-01-29 17:35:38 +00:00
|
|
|
bool casesensitive = false;
|
|
|
|
bool matchword = false;
|
|
|
|
bool forward = false;
|
|
|
|
bool matchAtStart = false;
|
|
|
|
bool expandmacros = false;
|
|
|
|
bool ignoreformat = false;
|
2011-02-07 23:55:02 +00:00
|
|
|
/// This is docstring() if no replace was requested
|
|
|
|
docstring repl_buf_name;
|
2021-01-29 17:35:38 +00:00
|
|
|
bool keep_case = false;
|
|
|
|
SearchScope scope = S_BUFFER;
|
|
|
|
SearchRestriction restr = R_EVERYTHING;
|
|
|
|
bool replace_all = false;
|
2008-11-15 23:30:27 +00:00
|
|
|
};
|
|
|
|
|
2018-11-09 05:07:17 +00:00
|
|
|
/// Set the formats that should be ignored
|
2021-02-13 15:19:45 +00:00
|
|
|
void setIgnoreFormat(std::string const & type, bool value, bool fromUser = true);
|
2018-11-09 05:07:17 +00:00
|
|
|
|
2008-11-15 23:30:27 +00:00
|
|
|
/// Write a FindAdvOptions instance to a stringstream
|
2009-01-14 15:34:56 +00:00
|
|
|
std::ostringstream & operator<<(std::ostringstream & os, lyx::FindAndReplaceOptions const & opt);
|
2008-11-15 23:30:27 +00:00
|
|
|
|
|
|
|
/// Read a FindAdvOptions instance from a stringstream
|
2009-01-14 15:34:56 +00:00
|
|
|
std::istringstream & operator>>(std::istringstream & is, lyx::FindAndReplaceOptions & opt);
|
2008-11-15 23:30:27 +00:00
|
|
|
|
|
|
|
/// Perform a FindAdv operation.
|
2021-01-10 21:58:58 +00:00
|
|
|
bool findAdv(BufferView * bv, FindAndReplaceOptions & opt);
|
2017-07-03 17:45:58 +00:00
|
|
|
|
2008-11-15 23:30:27 +00:00
|
|
|
/** Computes the simple-text or LaTeX export (depending on opt) of buf starting
|
|
|
|
** from cur and ending len positions after cur, if len is positive, or at the
|
|
|
|
** paragraph or innermost inset end if len is -1.
|
|
|
|
**
|
|
|
|
** This is useful for computing opt.search from the SearchAdvDialog controller (ControlSearchAdv).
|
|
|
|
** Ideally, this should not be needed, and the opt.search field should become a Text const &.
|
|
|
|
**/
|
2008-12-20 16:00:47 +00:00
|
|
|
docstring stringifyFromForSearch(
|
2009-01-14 15:34:56 +00:00
|
|
|
FindAndReplaceOptions const & opt,
|
2008-12-20 16:00:47 +00:00
|
|
|
DocIterator const & cur,
|
|
|
|
int len = -1);
|
2008-11-15 23:30:27 +00:00
|
|
|
|
2018-10-28 18:40:14 +00:00
|
|
|
|
2003-07-27 12:02:58 +00:00
|
|
|
} // namespace lyx
|
2003-03-04 09:27:27 +00:00
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
#endif // LYXFIND_H
|