2001-03-26 15:25:37 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* \file ControlSearch.C
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-04-26 18:40:38 +00:00
|
|
|
#include "ViewBase.h"
|
|
|
|
#include "ButtonControllerBase.h"
|
2001-03-26 15:25:37 +00:00
|
|
|
#include "ControlSearch.h"
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "Liason.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyxfind.h"
|
|
|
|
#include "debug.h"
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "gettext.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2001-03-26 15:25:37 +00:00
|
|
|
|
|
|
|
using Liason::setMinibuffer;
|
|
|
|
using SigC::slot;
|
|
|
|
|
|
|
|
ControlSearch::ControlSearch(LyXView & lv, Dialogs & d)
|
2002-01-16 14:47:58 +00:00
|
|
|
: ControlDialogBD(lv, d)
|
2001-03-26 15:25:37 +00:00
|
|
|
{
|
|
|
|
d_.showSearch.connect(SigC::slot(this, &ControlSearch::show));
|
|
|
|
|
|
|
|
// perhaps in the future we'd like a
|
|
|
|
// "search again" button/keybinding
|
|
|
|
// d_.searchAgain.connect(SigC::slot(this, &ControlSearch::FindNext));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlSearch::find(string const & search,
|
|
|
|
bool casesensitive, bool matchword, bool forward) const
|
|
|
|
{
|
2001-07-20 14:18:48 +00:00
|
|
|
bool const found = LyXFind(lv_.view(), search,
|
|
|
|
forward, false, casesensitive, matchword);
|
2001-03-26 15:25:37 +00:00
|
|
|
|
|
|
|
if (!found)
|
|
|
|
setMinibuffer(&lv_, _("String not found!"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ControlSearch::replace(string const & search, string const & replace,
|
|
|
|
bool casesensitive, bool matchword, bool all) const
|
|
|
|
{
|
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
|
|
|
|
bool const once = !all;
|
2001-03-26 15:25:37 +00:00
|
|
|
int const replace_count = LyXReplace(lv_.view(),
|
2001-07-20 14:18:48 +00:00
|
|
|
search, replace, true, casesensitive,
|
2001-09-07 17:52:50 +00:00
|
|
|
matchword, all, once);
|
2001-03-26 15:25:37 +00:00
|
|
|
|
|
|
|
if (replace_count == 0) {
|
|
|
|
setMinibuffer(&lv_, _("String not found!"));
|
|
|
|
} else {
|
|
|
|
if (replace_count == 1) {
|
|
|
|
setMinibuffer(&lv_, _("String has been replaced."));
|
|
|
|
} else {
|
|
|
|
string str = tostr(replace_count);
|
|
|
|
str += _(" strings have been replaced.");
|
|
|
|
setMinibuffer(&lv_, str.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|