From 417a4da1758756827b591118630220547401f1f7 Mon Sep 17 00:00:00 2001 From: John Levon Date: Fri, 31 Aug 2001 02:34:10 +0000 Subject: [PATCH] re-add search dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2634 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 7 ++ src/frontends/qt2/Dialogs.C | 4 +- src/frontends/qt2/QSearch.C | 118 ++++++++------------------ src/frontends/qt2/QSearch.h | 77 +++++++---------- src/frontends/qt2/QSearchDialog.C | 66 ++++++++------ src/frontends/qt2/QSearchDialog.h | 31 +++---- src/frontends/qt2/ui/QSearchDialog.ui | 118 +++++++++++++++++++------- 7 files changed, 211 insertions(+), 210 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 62e381dfd3..fce542250f 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,10 @@ +2001-08-31 John Levon + + * Dialogs.C: + * QSearch.[Ch]: + * QSearchDialog.[Ch]: + * ui/QSearchDialog.ui: add search back + 2001-08-29 John Levon * Dialogs.C: diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 629f992e28..c9a015b527 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -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(*lv, *this)); add(new GUIPrint(*lv, *this)); add(new GUIRef(*lv, *this)); + add(new GUISearch(*lv, *this)); add(new GUITabularCreate(*lv, *this)); add(new GUIThesaurus(*lv, *this)); add(new GUIUrl(*lv, *this)); diff --git a/src/frontends/qt2/QSearch.C b/src/frontends/qt2/QSearch.C index 1e9fc2dbf2..becd8ecd8c 100644 --- a/src/frontends/qt2/QSearch.C +++ b/src/frontends/qt2/QSearch.C @@ -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 */ #include +#include -#include "gettext.h" +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include +#include + #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 > 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); } diff --git a/src/frontends/qt2/QSearch.h b/src/frontends/qt2/QSearch.h index 5c62c03175..df6df73f18 100644 --- a/src/frontends/qt2/QSearch.h +++ b/src/frontends/qt2/QSearch.h @@ -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 */ #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 > +{ 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 diff --git a/src/frontends/qt2/QSearchDialog.C b/src/frontends/qt2/QSearchDialog.C index 682ec23fdc..bf8bd9ddb0 100644 --- a/src/frontends/qt2/QSearchDialog.C +++ b/src/frontends/qt2/QSearchDialog.C @@ -8,57 +8,71 @@ #include +#include "ControlSearch.h" #include "QSearchDialog.h" +#include "debug.h" #include #include #include #include -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); } diff --git a/src/frontends/qt2/QSearchDialog.h b/src/frontends/qt2/QSearchDialog.h index 972dd1c424..00f59a833f 100644 --- a/src/frontends/qt2/QSearchDialog.h +++ b/src/frontends/qt2/QSearchDialog.h @@ -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 diff --git a/src/frontends/qt2/ui/QSearchDialog.ui b/src/frontends/qt2/ui/QSearchDialog.ui index 965652a36d..22ce1c201d 100644 --- a/src/frontends/qt2/ui/QSearchDialog.ui +++ b/src/frontends/qt2/ui/QSearchDialog.ui @@ -13,13 +13,13 @@ 0 0 - 384 + 379 168 caption - Form1 + Search and replace sizeGripEnabled @@ -44,18 +44,22 @@ QLabel name - findStrLabel + findLA text - Find: + &Find: + + + buddy + findCO QComboBox name - find + findCO sizePolicy @@ -74,25 +78,41 @@ duplicatesEnabled + false + + + insertionPolicy + AtTop + + + autoCompletion true + + maxCount + 10 + QLabel name - replaceLabel + replaceLA text - Replace with: + Replace &with: + + + buddy + replaceCO QComboBox name - replace + replaceCO sizePolicy @@ -105,23 +125,39 @@ editable true + + insertionPolicy + AtTop + + + duplicatesEnabled + false + + + autoCompletion + true + + + maxCount + 10 + QCheckBox name - caseSensitive + caseCB text - &Case sensitive + Case &sensitive QCheckBox name - matchWord + wordsCB text @@ -201,6 +237,14 @@ text Find &Next + + default + true + + + enabled + false + QPushButton @@ -212,23 +256,31 @@ text &Replace + + enabled + false + QPushButton name - replaceAllPB + replaceallPB text Replace &All + + enabled + false + QCheckBox name - searchBack + backwardsCB text @@ -239,11 +291,11 @@ QPushButton name - cancelPB + closePB text - &Cancel + &Close @@ -253,40 +305,40 @@ findPB clicked() QSearchDialogBase - Find() + findClicked() replacePB clicked() QSearchDialogBase - Replace() + replaceClicked() - replaceAllPB + replaceallPB clicked() QSearchDialogBase - ReplaceAll() + replaceallClicked() - cancelPB - clicked() + findCO + textChanged(const QString&) QSearchDialogBase - cancel_adaptor() + findChanged() - Find() - Replace() - ReplaceAll() - cancel_adaptor() + findClicked() + findChanged() + replaceClicked() + replaceallClicked() - find - replace - caseSensitive - matchWord - searchBack + findCO + replaceCO + caseCB + wordsCB + backwardsCB findPB replacePB - replaceAllPB - cancelPB + replaceallPB + closePB -- 2.39.2