re-add search dialog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2634 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2001-08-31 02:34:10 +00:00
parent 74728503e4
commit 417a4da175
7 changed files with 214 additions and 213 deletions

View File

@ -1,3 +1,10 @@
2001-08-31 John Levon <moz@compsoc.man.ac.uk>
* Dialogs.C:
* QSearch.[Ch]:
* QSearchDialog.[Ch]:
* ui/QSearchDialog.ui: add search back
2001-08-29 John Levon <moz@compsoc.man.ac.uk>
* Dialogs.C:

View File

@ -28,6 +28,7 @@
#include "QPreambleDialog.h"
#include "QPrintDialog.h"
#include "QRefDialog.h"
#include "QSearchDialog.h"
#include "QTabularCreateDialog.h"
#include "QThesaurusDialog.h"
#include "QURLDialog.h"
@ -80,6 +81,7 @@
#include "controllers/ControlPreamble.h"
#include "controllers/ControlPrint.h"
#include "controllers/ControlRef.h"
#include "controllers/ControlSearch.h"
#include "controllers/ControlSplash.h"
#include "controllers/ControlTabularCreate.h"
#include "controllers/ControlThesaurus.h"
@ -91,7 +93,6 @@
#include "controllers/ControlFloat.h"
#include "controllers/ControlLabel.h"
#include "controllers/ControlRef.h"
#include "controllers/ControlSearch.h"
#include "controllers/ControlSpellchecker.h"
#include "controllers/ControlToc.h"
#endif
@ -123,6 +124,7 @@ Dialogs::Dialogs(LyXView * lv)
add(new GUIPreamble<QPreamble, Qt2BC>(*lv, *this));
add(new GUIPrint<QPrint, Qt2BC>(*lv, *this));
add(new GUIRef<QRef, Qt2BC>(*lv, *this));
add(new GUISearch<QSearch, Qt2BC>(*lv, *this));
add(new GUITabularCreate<QTabularCreate, Qt2BC>(*lv, *this));
add(new GUIThesaurus<QThesaurus, Qt2BC>(*lv, *this));
add(new GUIUrl<QURL, Qt2BC>(*lv, *this));

View File

@ -1,111 +1,63 @@
/**
* \file QSearch.C
* Copyright 2001 The LyX Team.
* See the file COPYING.
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author Edwin Leuven
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#include <config.h>
#include <fstream>
#include "gettext.h"
#ifdef __GNUG__
#pragma implementation
#endif
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include "QSearchDialog.h"
#include "QSearch.h"
#include "Dialogs.h"
#include "Liason.h"
#include "Qt2BC.h"
#include "gettext.h"
#include "QtLyXView.h"
#include "buffer.h"
#include "lyxfind.h"
#include "support/lstrings.h"
#include "BufferView.h"
#include "ControlSearch.h"
using Liason::setMinibuffer;
typedef Qt2CB<ControlSearch, Qt2DB<QSearchDialog> > base_class;
QSearch::QSearch(LyXView *v, Dialogs *d)
: dialog_(0), lv_(v), d_(d), h_(0), u_(0)
QSearch::QSearch(ControlSearch & c)
: base_class(c, _("Search"))
{
d->showSearch.connect(SigC::slot(this, &QSearch::show));
// perhaps in the future we'd like a
// "search again" button/keybinding
// d->searchAgain.connect(slot(this, &QSearch::FindNext));
}
QSearch::~QSearch()
void QSearch::build_dialog()
{
delete dialog_;
dialog_.reset(new QSearchDialog(this));
bc().setCancel(dialog_->closePB);
bc().addReadOnly(dialog_->replaceCO);
bc().addReadOnly(dialog_->replacePB);
bc().addReadOnly(dialog_->replaceallPB);
bc().addReadOnly(dialog_->caseCB);
bc().addReadOnly(dialog_->wordsCB);
bc().addReadOnly(dialog_->backwardsCB);
dialog_->replacePB->setEnabled(false);
dialog_->replaceallPB->setEnabled(false);
}
void QSearch::show()
void QSearch::find(string const & str, bool casesens, bool words, bool backwards)
{
if (!dialog_) {
dialog_ = new QSearchDialog(this, 0, _("Find and Replace"), false);
}
if (!dialog_->isVisible()) {
h_ = d_->hideBufferDependent.connect(SigC::slot(this, &QSearch::hide));
u_ = d_->updateBufferDependent.connect(SigC::slot(this, &QSearch::update));
}
dialog_->raise();
dialog_->setActiveWindow();
update();
dialog_->show();
controller().find(str, casesens, words, !backwards);
}
void QSearch::find(string const & searchstr, bool const & casesensitive,
bool const & matchword, bool const & searchback)
void QSearch::replace(string const & findstr, string const & replacestr,
bool casesens, bool words, bool all)
{
bool const found = LyXFind(lv_->view(), searchstr, searchback,
casesensitive, matchword);
if (!found)
setMinibuffer(lv_, _("String not found!"));
}
void QSearch::replace(string const & searchstr, string const & replacestr,
bool const & casesensitive, bool const & matchword,
bool const & searchback, bool const & replaceall)
{
int replace_count = LyXReplace(lv_->view(), searchstr, replacestr,
searchback, casesensitive, matchword,
replaceall);
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());
}
}
}
void QSearch::close()
{
h_.disconnect();
u_.disconnect();
}
void QSearch::hide()
{
dialog_->hide();
close();
}
void QSearch::update(bool)
{
if (!lv_->view()->available())
return;
dialog_->setReadOnly(lv_->buffer()->isReadonly());
controller().replace(findstr, replacestr, casesens, words, all);
}

View File

@ -1,63 +1,48 @@
// -*- C++ -*-
/**
/**
* \file QSearch.h
* Copyright 2001 The LyX Team.
* See the file COPYING.
*
* \author Edwin Leuven
* Copyright 2001 the LyX Team
* Read the file COPYING
*
* \author John Levon <moz@compsoc.man.ac.uk>
*/
#ifndef QSEARCH_H
#define QSEARCH_H
#include "DialogBase.h"
#include "LString.h"
#include "support/lstrings.h"
#ifdef __GNUG__
#pragma interface
#endif
class LyXView;
class Dialogs;
#include "Qt2Base.h"
class ControlSearch;
class QSearchDialog;
class QSearch : public DialogBase {
///
class QSearch
: public Qt2CB<ControlSearch, Qt2DB<QSearchDialog> >
{
public:
///
QSearch(LyXView *, Dialogs *);
friend class QSearchDialog;
///
~QSearch();
/// Close connections.
void close();
/// find stuff (we need access to lv_).
void find(string const &, bool const &, bool const &, bool const &);
/// replace stuff (we need access to lv_).
void replace(string const &, string const &,
bool const &, bool const &, bool const &, bool const &);
private:
/// Show the dialog.
void show();
/// Hide the dialog.
void hide();
/// Update the dialog.
void update(bool switched = false);
/// Real GUI implementation.
QSearchDialog * dialog_;
/// the LyXView we belong to.
LyXView * lv_;
/** Which Dialogs do we belong to?
* Used so we can get at the signals we have to connect to.
*/
Dialogs * d_;
/// Hide connection.
SigC::Connection h_;
QSearch(ControlSearch &);
private:
/// Apply changes
virtual void apply() {};
/// update
virtual void update_contents() {};
/// build the dialog
virtual void build_dialog();
void find(string const & str, bool casesens, bool words, bool backwards);
void replace(string const & findstr, string const & replacestr,
bool casesens, bool words, bool all);
/// Update connection.
SigC::Connection u_;
};
#endif // QSEARCH_H

View File

@ -8,57 +8,71 @@
#include <config.h>
#include "ControlSearch.h"
#include "QSearchDialog.h"
#include "debug.h"
#include <qpushbutton.h>
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qlabel.h>
QSearchDialog::QSearchDialog(QSearch * form, QWidget * parent, const char * name, bool modal, WFlags fl)
: QSearchDialogBase(parent, name, modal, fl),
QSearchDialog::QSearchDialog(QSearch * form)
: QSearchDialogBase(0, 0, false, 0),
form_(form)
{
setCaption(name);
connect(closePB, SIGNAL(clicked()),
form_, SLOT(slotClose()));
}
QSearchDialog::~QSearchDialog()
{
}
void QSearchDialog::closeEvent(QCloseEvent * e)
{
form_->close();
form_->slotWMHide();
e->accept();
}
void QSearchDialog::setReadOnly(bool readonly)
void QSearchDialog::findChanged()
{
replace->setEnabled(!readonly);
replaceLabel->setEnabled(!readonly);
replacePB->setEnabled(!readonly);
replaceAllPB->setEnabled(!readonly);
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());
}
}
void QSearchDialog::findClicked()
{
string const find(findCO->currentText().latin1());
form_->find(find,
caseCB->isChecked(),
wordsCB->isChecked(),
backwardsCB->isChecked());
}
void QSearchDialog::Find()
void QSearchDialog::replaceClicked()
{
form_->find(tostr(find->currentText()).c_str(),
caseSensitive->isChecked(),
matchWord->isChecked(),
!searchBack->isChecked());
string const find(findCO->currentText().latin1());
string const replace(replaceCO->currentText().latin1());
form_->replace(find, replace,
caseCB->isChecked(),
wordsCB->isChecked(),
false);
}
void QSearchDialog::Replace(bool replaceall)
void QSearchDialog::replaceallClicked()
{
form_->replace(tostr(find->currentText()).c_str(),
tostr(replace->currentText()).c_str(),
caseSensitive->isChecked(),
matchWord->isChecked(),
!searchBack->isChecked(),
replaceall);
form_->replace(findCO->currentText().latin1(),
replaceCO->currentText().latin1(),
caseCB->isChecked(),
wordsCB->isChecked(),
true);
}

View File

@ -15,40 +15,29 @@
#include "QSearch.h"
class QCloseEvent;
class QComboBox;
class QSearchDialog : public QSearchDialogBase
{ Q_OBJECT
public:
QSearchDialog(QSearch * form, QWidget * parent = 0, const char * name = 0, bool modal = FALSE, WFlags fl = 0);
~QSearchDialog();
QSearchDialog(QSearch * form);
void setReadOnly(bool);
void Replace(bool replaceall = false);
protected slots:
void findChanged();
void findClicked();
void replaceClicked();
void replaceallClicked();
protected:
void closeEvent(QCloseEvent * e);
private:
// add a string to the combo if needed
void QSearchDialog::remember(string const & find, QComboBox & combo);
QSearch * form_;
protected slots:
void Find();
void Replace() {
Replace(false);
};
void ReplaceAll() {
Replace(true);
};
void cancel_adaptor() {
form_->close();
hide();
}
};
#endif // QSEARCHDIALOG_H

View File

@ -13,13 +13,13 @@
<rect>
<x>0</x>
<y>0</y>
<width>384</width>
<width>379</width>
<height>168</height>
</rect>
</property>
<property stdset="1">
<name>caption</name>
<string>Form1</string>
<string>Search and replace</string>
</property>
<property stdset="1">
<name>sizeGripEnabled</name>
@ -44,18 +44,22 @@
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>findStrLabel</cstring>
<cstring>findLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Find:</string>
<string>&amp;Find:</string>
</property>
<property>
<name>buddy</name>
<cstring>findCO</cstring>
</property>
</widget>
<widget row="0" column="1" rowspan="1" colspan="2" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>find</cstring>
<cstring>findCO</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
@ -74,25 +78,41 @@
</property>
<property stdset="1">
<name>duplicatesEnabled</name>
<bool>false</bool>
</property>
<property stdset="1">
<name>insertionPolicy</name>
<enum>AtTop</enum>
</property>
<property stdset="1">
<name>autoCompletion</name>
<bool>true</bool>
</property>
<property stdset="1">
<name>maxCount</name>
<number>10</number>
</property>
</widget>
<widget row="1" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>replaceLabel</cstring>
<cstring>replaceLA</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Replace with:</string>
<string>Replace &amp;with:</string>
</property>
<property>
<name>buddy</name>
<cstring>replaceCO</cstring>
</property>
</widget>
<widget row="1" column="1" rowspan="1" colspan="2" >
<class>QComboBox</class>
<property stdset="1">
<name>name</name>
<cstring>replace</cstring>
<cstring>replaceCO</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
@ -105,23 +125,39 @@
<name>editable</name>
<bool>true</bool>
</property>
<property stdset="1">
<name>insertionPolicy</name>
<enum>AtTop</enum>
</property>
<property stdset="1">
<name>duplicatesEnabled</name>
<bool>false</bool>
</property>
<property stdset="1">
<name>autoCompletion</name>
<bool>true</bool>
</property>
<property stdset="1">
<name>maxCount</name>
<number>10</number>
</property>
</widget>
<widget row="2" column="0" rowspan="1" colspan="2" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>caseSensitive</cstring>
<cstring>caseCB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Case sensitive</string>
<string>Case &amp;sensitive</string>
</property>
</widget>
<widget row="3" column="0" rowspan="2" colspan="2" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>matchWord</cstring>
<cstring>wordsCB</cstring>
</property>
<property stdset="1">
<name>text</name>
@ -201,6 +237,14 @@
<name>text</name>
<string>Find &amp;Next</string>
</property>
<property stdset="1">
<name>default</name>
<bool>true</bool>
</property>
<property stdset="1">
<name>enabled</name>
<bool>false</bool>
</property>
</widget>
<widget row="1" column="3" >
<class>QPushButton</class>
@ -212,23 +256,31 @@
<name>text</name>
<string>&amp;Replace</string>
</property>
<property stdset="1">
<name>enabled</name>
<bool>false</bool>
</property>
</widget>
<widget row="2" column="3" rowspan="2" colspan="1" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>replaceAllPB</cstring>
<cstring>replaceallPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Replace &amp;All </string>
</property>
<property stdset="1">
<name>enabled</name>
<bool>false</bool>
</property>
</widget>
<widget row="5" column="0" rowspan="1" colspan="2" >
<class>QCheckBox</class>
<property stdset="1">
<name>name</name>
<cstring>searchBack</cstring>
<cstring>backwardsCB</cstring>
</property>
<property stdset="1">
<name>text</name>
@ -239,11 +291,11 @@
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>cancelPB</cstring>
<cstring>closePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Cancel</string>
<string>&amp;Close</string>
</property>
</widget>
</grid>
@ -253,40 +305,40 @@
<sender>findPB</sender>
<signal>clicked()</signal>
<receiver>QSearchDialogBase</receiver>
<slot>Find()</slot>
<slot>findClicked()</slot>
</connection>
<connection>
<sender>replacePB</sender>
<signal>clicked()</signal>
<receiver>QSearchDialogBase</receiver>
<slot>Replace()</slot>
<slot>replaceClicked()</slot>
</connection>
<connection>
<sender>replaceAllPB</sender>
<sender>replaceallPB</sender>
<signal>clicked()</signal>
<receiver>QSearchDialogBase</receiver>
<slot>ReplaceAll()</slot>
<slot>replaceallClicked()</slot>
</connection>
<connection>
<sender>cancelPB</sender>
<signal>clicked()</signal>
<sender>findCO</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>QSearchDialogBase</receiver>
<slot>cancel_adaptor()</slot>
<slot>findChanged()</slot>
</connection>
<slot access="protected">Find()</slot>
<slot access="protected">Replace()</slot>
<slot access="protected">ReplaceAll()</slot>
<slot access="protected">cancel_adaptor()</slot>
<slot access="protected">findClicked()</slot>
<slot access="public">findChanged()</slot>
<slot access="protected">replaceClicked()</slot>
<slot access="protected">replaceallClicked()</slot>
</connections>
<tabstops>
<tabstop>find</tabstop>
<tabstop>replace</tabstop>
<tabstop>caseSensitive</tabstop>
<tabstop>matchWord</tabstop>
<tabstop>searchBack</tabstop>
<tabstop>findCO</tabstop>
<tabstop>replaceCO</tabstop>
<tabstop>caseCB</tabstop>
<tabstop>wordsCB</tabstop>
<tabstop>backwardsCB</tabstop>
<tabstop>findPB</tabstop>
<tabstop>replacePB</tabstop>
<tabstop>replaceAllPB</tabstop>
<tabstop>cancelPB</tabstop>
<tabstop>replaceallPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops>
</UI>