+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:
#include "QPreambleDialog.h"
#include "QPrintDialog.h"
#include "QRefDialog.h"
+#include "QSearchDialog.h"
#include "QTabularCreateDialog.h"
#include "QThesaurusDialog.h"
#include "QURLDialog.h"
#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"
#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
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));
/**
* \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));
-
-void QSearch::show()
-{
- if (!dialog_) {
- dialog_ = new QSearchDialog(this, 0, _("Find and Replace"), false);
- }
+ 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);
- 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();
+ dialog_->replacePB->setEnabled(false);
+ dialog_->replaceallPB->setEnabled(false);
}
-void QSearch::find(string const & searchstr, bool const & casesensitive,
- bool const & matchword, bool const & searchback)
+void QSearch::find(string const & str, bool casesens, bool words, bool backwards)
{
- bool const found = LyXFind(lv_->view(), searchstr, searchback,
- casesensitive, matchword);
-
- if (!found)
- setMinibuffer(lv_, _("String not found!"));
+ controller().find(str, casesens, words, !backwards);
}
-void QSearch::replace(string const & searchstr, string const & replacestr,
- bool const & casesensitive, bool const & matchword,
- bool const & searchback, bool const & replaceall)
+void QSearch::replace(string const & findstr, string const & replacestr,
+ bool casesens, bool words, bool all)
{
- 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);
}
// -*- 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 &);
-
+ QSearch(ControlSearch &);
+
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_;
-
- /// Update connection.
- SigC::Connection u_;
-
+ /// 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);
+
};
#endif // QSEARCH_H
#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_->slotWMHide();
+ e->accept();
}
-void QSearchDialog::closeEvent(QCloseEvent * e)
+void QSearchDialog::findChanged()
{
- form_->close();
- e->accept();
+ 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::setReadOnly(bool readonly)
+
+void QSearchDialog::findClicked()
{
- replace->setEnabled(!readonly);
- replaceLabel->setEnabled(!readonly);
- replacePB->setEnabled(!readonly);
- replaceAllPB->setEnabled(!readonly);
+ 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);
}
#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
<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>
<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>&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>
</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 &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>
<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>&Case sensitive</string>
+ <string>Case &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>
<name>text</name>
<string>Find &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>
<name>text</name>
<string>&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 &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>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
- <cstring>cancelPB</cstring>
+ <cstring>closePB</cstring>
</property>
<property stdset="1">
<name>text</name>
- <string>&Cancel</string>
+ <string>&Close</string>
</property>
</widget>
</grid>
<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&)</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>