2002-09-05 14:10:50 +00:00
|
|
|
/**
|
|
|
|
* \file ControlSearch.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-03-26 15:25:37 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Angus Leeming
|
2001-03-26 15:25:37 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-03-26 15:25:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
#include "ControlSearch.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
#include "lyxfind.h"
|
2002-05-29 16:21:03 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
#include "frontends/LyXView.h"
|
2002-05-29 16:21:03 +00:00
|
|
|
|
2003-05-13 14:36:24 +00:00
|
|
|
#include "support/tostr.h"
|
2001-03-26 15:25:37 +00:00
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
2001-03-26 15:25:37 +00:00
|
|
|
ControlSearch::ControlSearch(LyXView & lv, Dialogs & d)
|
2002-01-16 14:47:58 +00:00
|
|
|
: ControlDialogBD(lv, d)
|
2002-06-18 15:44:30 +00:00
|
|
|
{}
|
2001-03-26 15:25:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ControlSearch::find(string const & search,
|
2002-08-12 20:17:41 +00:00
|
|
|
bool casesensitive, bool matchword, bool forward)
|
2001-03-26 15:25:37 +00:00
|
|
|
{
|
2003-07-27 12:02:58 +00:00
|
|
|
bool const found = lyx::find::find(bufferview(), search,
|
2003-11-04 12:01:15 +00:00
|
|
|
casesensitive, matchword,
|
|
|
|
forward);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-26 15:25:37 +00:00
|
|
|
if (!found)
|
2002-10-20 01:48:28 +00:00
|
|
|
lv_.message(_("String not found!"));
|
2001-03-26 15:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlSearch::replace(string const & search, string const & replace,
|
2003-11-04 12:01:15 +00:00
|
|
|
bool casesensitive, bool matchword,
|
|
|
|
bool forward, bool all)
|
2001-03-26 15:25:37 +00:00
|
|
|
{
|
2001-09-07 17:52:50 +00:00
|
|
|
// If not replacing all instances of the word, then do not
|
|
|
|
// move on to the next instance once the present instance has been
|
|
|
|
// changed
|
2003-11-04 12:01:15 +00:00
|
|
|
int const replace_count = all ?
|
|
|
|
lyx::find::replaceAll(bufferview(), search, replace,
|
|
|
|
casesensitive, matchword)
|
|
|
|
: lyx::find::replace(bufferview(), search, replace,
|
|
|
|
casesensitive, matchword, forward);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-26 15:25:37 +00:00
|
|
|
if (replace_count == 0) {
|
2002-10-20 01:48:28 +00:00
|
|
|
lv_.message(_("String not found!"));
|
2001-03-26 15:25:37 +00:00
|
|
|
} else {
|
|
|
|
if (replace_count == 1) {
|
2002-10-20 01:48:28 +00:00
|
|
|
lv_.message(_("String has been replaced."));
|
2001-03-26 15:25:37 +00:00
|
|
|
} else {
|
|
|
|
string str = tostr(replace_count);
|
|
|
|
str += _(" strings have been replaced.");
|
2002-10-24 12:56:44 +00:00
|
|
|
lv_.message(str);
|
2001-03-26 15:25:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|