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
|
2006-03-05 17:24:44 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiSearch.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
#include "ControlSearch.h"
|
2007-04-24 13:27:23 +00:00
|
|
|
#include "qt_helpers.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-04-24 13:27:23 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QCloseEvent>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < box->count(); ++i) {
|
|
|
|
if (box->itemText(i) == text)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
box->addItem(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
GuiSearchDialog::GuiSearchDialog(LyXView & lv)
|
|
|
|
: GuiDialog(lv, "findreplace")
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
setController(new ControlSearch(*this));
|
|
|
|
setViewTitle(_("Find and Replace"));
|
2007-04-24 13:27:23 +00:00
|
|
|
|
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()));
|
|
|
|
connect(findCO, SIGNAL(editTextChanged(const 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-09-11 18:33:42 +00:00
|
|
|
ControlSearch & GuiSearchDialog::controller()
|
2007-09-05 20:33:29 +00:00
|
|
|
{
|
2007-09-10 22:32:59 +00:00
|
|
|
return static_cast<ControlSearch &>(GuiDialog::controller());
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 20:28:26 +00:00
|
|
|
void GuiSearchDialog::showView()
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
|
|
|
findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
|
2007-09-09 15:56:58 +00:00
|
|
|
GuiDialog::showView();
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearchDialog::closeEvent(QCloseEvent * e)
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
2007-09-11 17:06:15 +00:00
|
|
|
slotClose();
|
2007-09-27 14:37:36 +00:00
|
|
|
GuiDialog::closeEvent(e);
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearchDialog::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-09-11 18:33:42 +00:00
|
|
|
replacePB->setEnabled(!controller().isBufferReadonly());
|
|
|
|
replaceallPB->setEnabled(!controller().isBufferReadonly());
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearchDialog::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-04-24 13:27:23 +00:00
|
|
|
backwardsCB->isChecked());
|
|
|
|
uniqueInsert(findCO, findCO->currentText());
|
2007-08-30 01:26:18 +00:00
|
|
|
findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
|
2007-04-24 13:27:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearchDialog::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-04-24 13:27:23 +00:00
|
|
|
backwardsCB->isChecked(), false);
|
|
|
|
uniqueInsert(findCO, findCO->currentText());
|
|
|
|
uniqueInsert(replaceCO, replaceCO->currentText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearchDialog::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-09-05 20:33:29 +00:00
|
|
|
caseCB->isChecked(), wordsCB->isChecked(), false, true);
|
2007-04-24 13:27:23 +00:00
|
|
|
uniqueInsert(findCO, findCO->currentText());
|
|
|
|
uniqueInsert(replaceCO, replaceCO->currentText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
void GuiSearchDialog::find(docstring const & str, bool casesens,
|
|
|
|
bool words, bool backwards)
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
controller().find(str, casesens, words, !backwards);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
void GuiSearchDialog::replace(docstring const & findstr,
|
|
|
|
docstring const & replacestr,
|
2006-03-05 17:24:44 +00:00
|
|
|
bool casesens, bool words, bool backwards, bool all)
|
|
|
|
{
|
|
|
|
controller().replace(findstr, replacestr, casesens, words,
|
|
|
|
!backwards, all);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 13:27:23 +00:00
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiSearch_moc.cpp"
|