2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiSearch.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
2007-04-24 13:27:23 +00:00
|
|
|
* \author Edwin Leuven
|
2007-10-06 20:54:31 +00:00
|
|
|
* \author Angus Leeming
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2013-07-21 16:51:53 +00:00
|
|
|
#include "lyxfind.h"
|
2008-02-11 07:12:06 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-10-06 20:54:31 +00:00
|
|
|
#include "FuncRequest.h"
|
2013-07-21 16:51:53 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "Cursor.h"
|
|
|
|
#include "GuiSearch.h"
|
|
|
|
#include "GuiView.h"
|
|
|
|
|
|
|
|
#include "support/gettext.h"
|
|
|
|
#include "frontends/alert.h"
|
2007-10-06 20:54:31 +00:00
|
|
|
|
2008-02-11 07:12:06 +00:00
|
|
|
#include <QLineEdit>
|
2007-12-09 22:35:04 +00:00
|
|
|
#include <QShowEvent>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-04-24 13:27:23 +00:00
|
|
|
static void uniqueInsert(QComboBox * box, QString const & text)
|
|
|
|
{
|
2007-10-09 21:21:01 +00:00
|
|
|
for (int i = box->count(); --i >= 0; )
|
2007-04-24 13:27:23 +00:00
|
|
|
if (box->itemText(i) == text)
|
|
|
|
return;
|
|
|
|
|
2008-09-09 13:20:44 +00:00
|
|
|
box->insertItem(0, text);
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiSearch::GuiSearch(GuiView & lv)
|
2008-02-05 12:43:19 +00:00
|
|
|
: GuiDialog(lv, "findreplace", qt_("Find and Replace"))
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
|
2007-08-12 12:44:42 +00:00
|
|
|
connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
|
|
|
|
connect(replacePB, SIGNAL(clicked()), this, SLOT(replaceClicked()));
|
|
|
|
connect(replaceallPB, SIGNAL(clicked()), this, SLOT(replaceallClicked()));
|
2007-10-09 19:34:27 +00:00
|
|
|
connect(findCO, SIGNAL(editTextChanged(QString)),
|
2007-04-24 13:27:23 +00:00
|
|
|
this, SLOT(findChanged()));
|
|
|
|
|
|
|
|
setFocusProxy(findCO);
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
bc().addReadOnly(replaceCO);
|
|
|
|
bc().addReadOnly(replacePB);
|
|
|
|
bc().addReadOnly(replaceallPB);
|
|
|
|
|
|
|
|
replacePB->setEnabled(false);
|
|
|
|
replaceallPB->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-09 22:35:04 +00:00
|
|
|
void GuiSearch::showEvent(QShowEvent * e)
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
2008-03-12 16:17:25 +00:00
|
|
|
findPB->setFocus();
|
2007-10-30 13:16:45 +00:00
|
|
|
findCO->lineEdit()->selectAll();
|
2007-12-09 22:35:04 +00:00
|
|
|
GuiDialog::showEvent(e);
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:54:31 +00:00
|
|
|
void GuiSearch::findChanged()
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
|
|
|
if (findCO->currentText().isEmpty()) {
|
|
|
|
findPB->setEnabled(false);
|
|
|
|
replacePB->setEnabled(false);
|
|
|
|
replaceallPB->setEnabled(false);
|
|
|
|
} else {
|
|
|
|
findPB->setEnabled(true);
|
2007-10-09 21:21:01 +00:00
|
|
|
replacePB->setEnabled(!isBufferReadonly());
|
|
|
|
replaceallPB->setEnabled(!isBufferReadonly());
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:54:31 +00:00
|
|
|
void GuiSearch::findClicked()
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
docstring const needle = qstring_to_ucs4(findCO->currentText());
|
|
|
|
find(needle, caseCB->isChecked(), wordsCB->isChecked(),
|
2007-10-06 20:54:31 +00:00
|
|
|
!backwardsCB->isChecked());
|
2007-04-24 13:27:23 +00:00
|
|
|
uniqueInsert(findCO, findCO->currentText());
|
2007-10-30 13:16:45 +00:00
|
|
|
findCO->lineEdit()->selectAll();
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:54:31 +00:00
|
|
|
void GuiSearch::replaceClicked()
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
docstring const needle = qstring_to_ucs4(findCO->currentText());
|
|
|
|
docstring const repl = qstring_to_ucs4(replaceCO->currentText());
|
|
|
|
replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(),
|
2007-10-06 20:54:31 +00:00
|
|
|
!backwardsCB->isChecked(), false);
|
2007-04-24 13:27:23 +00:00
|
|
|
uniqueInsert(findCO, findCO->currentText());
|
|
|
|
uniqueInsert(replaceCO, replaceCO->currentText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:54:31 +00:00
|
|
|
void GuiSearch::replaceallClicked()
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
replace(qstring_to_ucs4(findCO->currentText()),
|
2007-04-24 13:27:23 +00:00
|
|
|
qstring_to_ucs4(replaceCO->currentText()),
|
2007-10-06 20:54:31 +00:00
|
|
|
caseCB->isChecked(), wordsCB->isChecked(), true, true);
|
2007-04-24 13:27:23 +00:00
|
|
|
uniqueInsert(findCO, findCO->currentText());
|
|
|
|
uniqueInsert(replaceCO, replaceCO->currentText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:54:31 +00:00
|
|
|
void GuiSearch::find(docstring const & search, bool casesensitive,
|
|
|
|
bool matchword, bool forward)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-09 21:21:01 +00:00
|
|
|
docstring const data =
|
|
|
|
find2string(search, casesensitive, matchword, forward);
|
2016-09-14 08:23:39 +00:00
|
|
|
dispatch(FuncRequest(LFUN_WORD_FIND, data));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 20:54:31 +00:00
|
|
|
void GuiSearch::replace(docstring const & search, docstring const & replace,
|
|
|
|
bool casesensitive, bool matchword,
|
|
|
|
bool forward, bool all)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-06 20:54:31 +00:00
|
|
|
docstring const data =
|
2009-07-04 23:02:27 +00:00
|
|
|
replace2string(replace, search, casesensitive,
|
2007-10-06 20:54:31 +00:00
|
|
|
matchword, all, forward);
|
2016-09-14 08:23:39 +00:00
|
|
|
dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2013-07-21 16:51:53 +00:00
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiSearch(GuiView & lv) { return new GuiSearch(lv); }
|
2007-10-06 20:54:31 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 13:27:23 +00:00
|
|
|
|
|
|
|
|
2008-11-14 14:28:50 +00:00
|
|
|
#include "moc_GuiSearch.cpp"
|