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-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;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-04-24 13:27:23 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiSearchDialog
|
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-08-31 05:53:55 +00:00
|
|
|
GuiSearchDialog::GuiSearchDialog(GuiSearch * form)
|
2007-04-24 13:27:23 +00:00
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
connect(closePB, SIGNAL(clicked()), form_, 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-08-31 05:53:55 +00:00
|
|
|
void GuiSearchDialog::show()
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
|
|
|
QDialog::show();
|
|
|
|
findCO->lineEdit()->setSelection(0, findCO->lineEdit()->text().length());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearchDialog::closeEvent(QCloseEvent * e)
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
|
|
|
form_->slotWMHide();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
replacePB->setEnabled(!form_->readOnly());
|
|
|
|
replaceallPB->setEnabled(!form_->readOnly());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearchDialog::findClicked()
|
2007-04-24 13:27:23 +00:00
|
|
|
{
|
|
|
|
docstring const find = qstring_to_ucs4(findCO->currentText());
|
|
|
|
form_->find(find,
|
|
|
|
caseCB->isChecked(),
|
|
|
|
wordsCB->isChecked(),
|
|
|
|
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
|
|
|
{
|
|
|
|
docstring const find = qstring_to_ucs4(findCO->currentText());
|
|
|
|
docstring const replace = qstring_to_ucs4(replaceCO->currentText());
|
|
|
|
form_->replace(find, replace,
|
|
|
|
caseCB->isChecked(),
|
|
|
|
wordsCB->isChecked(),
|
|
|
|
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
|
|
|
{
|
|
|
|
form_->replace(qstring_to_ucs4(findCO->currentText()),
|
|
|
|
qstring_to_ucs4(replaceCO->currentText()),
|
|
|
|
caseCB->isChecked(),
|
|
|
|
wordsCB->isChecked(),
|
|
|
|
false, true);
|
|
|
|
uniqueInsert(findCO, findCO->currentText());
|
|
|
|
uniqueInsert(replaceCO, replaceCO->currentText());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2007-08-31 05:53:55 +00:00
|
|
|
// GuiSearch
|
2007-04-24 13:27:23 +00:00
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
GuiSearch::GuiSearch(GuiDialog & parent)
|
2007-08-31 22:16:11 +00:00
|
|
|
: GuiView<GuiSearchDialog>(parent, _("Find and Replace"))
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearch::build_dialog()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-08-31 05:53:55 +00:00
|
|
|
dialog_.reset(new GuiSearchDialog(this));
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-09-03 05:59:32 +00:00
|
|
|
bc().setCancel(dialog_->closePB);
|
|
|
|
bc().addReadOnly(dialog_->replaceCO);
|
|
|
|
bc().addReadOnly(dialog_->replacePB);
|
|
|
|
bc().addReadOnly(dialog_->replaceallPB);
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
dialog_->replacePB->setEnabled(false);
|
|
|
|
dialog_->replaceallPB->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearch::find(docstring const & str, bool casesens,
|
2006-03-05 17:24:44 +00:00
|
|
|
bool words, bool backwards)
|
|
|
|
{
|
|
|
|
controller().find(str, casesens, words, !backwards);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
void GuiSearch::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"
|