From 3f894b2bb595929b0c1ac110b89aea85ff1ee33d Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 6 Mar 2001 14:23:02 +0000 Subject: [PATCH] qt2 find&replace git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1692 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 8 + src/frontends/qt2/Dialogs.C | 2 + src/frontends/qt2/FormSearch.C | 109 +++++++++++ src/frontends/qt2/FormSearch.h | 64 +++++++ src/frontends/qt2/Makefile.am | 22 ++- src/frontends/qt2/searchdlg.C | 148 +++++++++++++++ src/frontends/qt2/searchdlg.h | 52 ++++++ src/frontends/qt2/searchdlg.ui | 290 ++++++++++++++++++++++++++++++ src/frontends/qt2/searchdlgimpl.C | 59 ++++++ src/frontends/qt2/searchdlgimpl.h | 51 ++++++ 10 files changed, 804 insertions(+), 1 deletion(-) create mode 100644 src/frontends/qt2/FormSearch.C create mode 100644 src/frontends/qt2/FormSearch.h create mode 100644 src/frontends/qt2/searchdlg.C create mode 100644 src/frontends/qt2/searchdlg.h create mode 100644 src/frontends/qt2/searchdlg.ui create mode 100644 src/frontends/qt2/searchdlgimpl.C create mode 100644 src/frontends/qt2/searchdlgimpl.h diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index f31e4090a2..099fcfdbd5 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,11 @@ +2001-03-06 Edwin Leuven + + * Search dialog added: + * FormSearch.[Ch] + * searchdlg.ui + * searchdlg.[Ch] + * searchdlgimpl.[Ch] + 2001-02-16 Edwin Leuven * remove inheritance from noncopyable in Form*.h diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index 1f6b9cfb02..b4ba40154c 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -23,6 +23,7 @@ #include "FormPreferences.h" #include "FormPrint.h" #include "FormRef.h" +#include "FormSearch.h" #include "FormTabular.h" #include "FormTabularCreate.h" #include "FormToc.h" @@ -56,6 +57,7 @@ Dialogs::Dialogs(LyXView * lv) dialogs_.push_back(new FormPreferences(lv, this)); dialogs_.push_back(new FormPrint(lv, this)); dialogs_.push_back(new FormRef(lv, this)); + dialogs_.push_back(new FormSearch(lv, this)); dialogs_.push_back(new FormTabular(lv, this)); dialogs_.push_back(new FormTabularCreate(lv, this)); dialogs_.push_back(new FormToc(lv, this)); diff --git a/src/frontends/qt2/FormSearch.C b/src/frontends/qt2/FormSearch.C new file mode 100644 index 0000000000..5d9a3eba32 --- /dev/null +++ b/src/frontends/qt2/FormSearch.C @@ -0,0 +1,109 @@ +/** + * \file FormSearch.C + * Copyright 2001 The LyX Team. + * See the file COPYING. + * + * \author Edwin Leuven + */ + +#include + +#include "searchdlgimpl.h" +#include "FormSearch.h" +#include "Dialogs.h" +#include "Liason.h" +#include "QtLyXView.h" +#include "buffer.h" +//#include "lyxtext.h" +#include "lyxfind.h" +//#include "language.h" +#include "support/lstrings.h" + +#ifdef CXX_WORKING_NAMESPACES +using Liason::setMinibuffer; +#endif + +FormSearch::FormSearch(LyXView *v, Dialogs *d) + : dialog_(0), lv_(v), d_(d), h_(0), u_(0) +{ + // let the popup be shown + // This is a permanent connection so we won't bother + // storing a copy because we won't be disconnecting. + d->showSearch.connect(slot(this, &FormSearch::show)); + // perhaps in the future we'd like a + // "search again" button/keybinding +// d->searchAgain.connect(slot(this, &FormSearch::FindNext)); +} + + +FormSearch::~FormSearch() +{ + delete dialog_; +} + +void FormSearch::show() +{ + if (!dialog_) { + dialog_ = new SearchDlgImpl(this, 0, _("Find and Replace"), false); + } + + if (!dialog_->isVisible()) { + h_ = d_->hideBufferDependent.connect(slot(this, &FormSearch::hide)); + u_ = d_->updateBufferDependent.connect(slot(this, &FormSearch::update)); + } + + dialog_->raise(); + dialog_->setActiveWindow(); + update(); + dialog_->show(); +} + +void FormSearch::find(string const & searchstr, bool const & casesensitive, + bool const & matchword, bool const & searchback) +{ + bool found = LyXFind(lv_->view(), searchstr, casesensitive, matchword, + searchback); + + if (!found) + setMinibuffer(lv_, _("String not found!")); + +} +void FormSearch::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, + casesensitive, matchword, searchback, + 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 FormSearch::close() +{ + h_.disconnect(); + u_.disconnect(); +} + +void FormSearch::hide() +{ + dialog_->hide(); + close(); +} + +void FormSearch::update(bool) +{ + if (!lv_->view()->available()) + return; + + dialog_->setReadOnly(lv_->buffer()->isReadonly()); +} diff --git a/src/frontends/qt2/FormSearch.h b/src/frontends/qt2/FormSearch.h new file mode 100644 index 0000000000..3ab63ac5b1 --- /dev/null +++ b/src/frontends/qt2/FormSearch.h @@ -0,0 +1,64 @@ +/** + * \file FormSearch.h + * Copyright 2001 The LyX Team. + * See the file COPYING. + * + * \author Edwin Leuven + */ + +#ifndef FORM_SEARCH_H +#define FORM_SEARCH_H + +#include "DialogBase.h" +#include "LString.h" +#include "support/lstrings.h" + +class LyXView; +class Dialogs; +class SearchDlgImpl; + +class FormSearch : public DialogBase { +public: + /// + FormSearch(LyXView *, Dialogs *); + /// + ~FormSearch(); + + /// 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. + SearchDlgImpl * 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. + Connection h_; + + /// Update connection. + Connection u_; + +}; + +#endif diff --git a/src/frontends/qt2/Makefile.am b/src/frontends/qt2/Makefile.am index 46e5d6f852..f029fbf535 100644 --- a/src/frontends/qt2/Makefile.am +++ b/src/frontends/qt2/Makefile.am @@ -17,6 +17,8 @@ BUILTSOURCES = moc_FormCopyrightDialogBase.C \ moc_paragraphdlgimpl.C \ moc_printdlg.C \ moc_printdlgimpl.C \ + moc_searchdlg.C \ + moc_searchdlgimpl.C \ moc_tabularcreatedlg.C \ moc_tabularcreatedlgimpl.C \ moc_emptytable.C @@ -35,6 +37,7 @@ libqt2_la_OBJADD = \ ../xforms/FormGraphics.lo \ ../xforms/FormIndex.lo \ ../xforms/FormInset.lo \ + ../xforms/FormPreamble.lo \ ../xforms/FormPreferences.lo \ ../xforms/FormRef.lo \ ../xforms/FormTabular.lo \ @@ -50,13 +53,14 @@ libqt2_la_OBJADD = \ ../xforms/form_error.lo \ ../xforms/form_index.lo \ ../xforms/form_graphics.lo \ + ../xforms/form_preamble.lo \ ../xforms/form_preferences.lo \ ../xforms/form_ref.lo \ ../xforms/form_tabular.lo \ ../xforms/form_toc.lo \ ../xforms/form_url.lo \ ../xforms/input_validators.lo \ - ../xforms/xform_helpers.lo + ../xforms/xforms_helpers.lo LIBS= LDFLAGS= $(libqt2_la_OBJADD) @@ -92,6 +96,12 @@ libqt2_la_SOURCES = \ printdlgimpl.h \ emptytable.C \ emptytable.h \ + FormSearch.C \ + FormSearch.h \ + searchdlg.C \ + searchdlg.h \ + searchdlgimpl.C \ + searchdlgimpl.h \ FormTabularCreate.C \ FormTabularCreate.h \ tabularcreatedlg.C \ @@ -165,3 +175,13 @@ moc_chardlg.C: chardlg.h moc_chardlgimpl.C: chardlgimpl.h $(MOC) -o $@ $< +FormSearch.C: searchdlg.h +searchdlg.h: searchdlg.ui + $(UIC) -o $@ $< +searchdlg.C: searchdlg.ui + $(UIC) -impl searchdlg.h -o $@ $< +moc_searchdlg.C: searchdlg.h + $(MOC) -o $@ $< +moc_searchdlgimpl.C: searchdlgimpl.h + $(MOC) -o $@ $< + diff --git a/src/frontends/qt2/searchdlg.C b/src/frontends/qt2/searchdlg.C new file mode 100644 index 0000000000..11d8221b03 --- /dev/null +++ b/src/frontends/qt2/searchdlg.C @@ -0,0 +1,148 @@ +/**************************************************************************** +** Form implementation generated from reading ui file 'searchdlg.ui' +** +** Created: Sun Mar 4 21:52:22 2001 +** by: The User Interface Compiler (uic) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ +#include "searchdlg.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Constructs a SearchDlg which is a child of 'parent', with the + * name 'name' and widget flags set to 'f' + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +SearchDlg::SearchDlg( QWidget* parent, const char* name, bool modal, WFlags fl ) + : QDialog( parent, name, modal, fl ) +{ + if ( !name ) + setName( "SearchDlg" ); + resize( 379, 168 ); + setCaption( tr( "Form1" ) ); + setSizeGripEnabled( TRUE ); + SearchDlgLayout = new QGridLayout( this ); + SearchDlgLayout->setSpacing( 6 ); + SearchDlgLayout->setMargin( 11 ); + + findStrLabel = new QLabel( this, "findStrLabel" ); + findStrLabel->setText( tr( "Find:" ) ); + + SearchDlgLayout->addWidget( findStrLabel, 0, 0 ); + + find = new QComboBox( FALSE, this, "find" ); + find->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, find->sizePolicy().hasHeightForWidth() ) ); + find->setEditable( TRUE ); + find->setDuplicatesEnabled( TRUE ); + find->setFocusPolicy( QComboBox::StrongFocus ); + + SearchDlgLayout->addMultiCellWidget( find, 0, 0, 1, 2 ); + + replaceLabel = new QLabel( this, "replaceLabel" ); + replaceLabel->setText( tr( "Replace with:" ) ); + + SearchDlgLayout->addWidget( replaceLabel, 1, 0 ); + + replace = new QComboBox( FALSE, this, "replace" ); + replace->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, replace->sizePolicy().hasHeightForWidth() ) ); + replace->setEditable( TRUE ); + + SearchDlgLayout->addMultiCellWidget( replace, 1, 1, 1, 2 ); + + caseSensitive = new QCheckBox( this, "caseSensitive" ); + caseSensitive->setText( tr( "&Case sensitive" ) ); + + SearchDlgLayout->addMultiCellWidget( caseSensitive, 2, 2, 0, 1 ); + + matchWord = new QCheckBox( this, "matchWord" ); + matchWord->setText( tr( "Match whole words onl&y" ) ); + + SearchDlgLayout->addMultiCellWidget( matchWord, 3, 4, 0, 1 ); + QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); + SearchDlgLayout->addItem( spacer, 2, 2 ); + QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); + SearchDlgLayout->addMultiCell( spacer_2, 6, 6, 0, 1 ); + QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); + SearchDlgLayout->addItem( spacer_3, 6, 3 ); + + findPB = new QPushButton( this, "findPB" ); + findPB->setText( tr( "Find &Next" ) ); + + SearchDlgLayout->addWidget( findPB, 0, 3 ); + + replacePB = new QPushButton( this, "replacePB" ); + replacePB->setText( tr( "&Replace" ) ); + + SearchDlgLayout->addWidget( replacePB, 1, 3 ); + + replaceAllPB = new QPushButton( this, "replaceAllPB" ); + replaceAllPB->setText( tr( "Replace &All " ) ); + + SearchDlgLayout->addMultiCellWidget( replaceAllPB, 2, 3, 3, 3 ); + + searchBack = new QCheckBox( this, "searchBack" ); + searchBack->setText( tr( "Search &backwards" ) ); + + SearchDlgLayout->addMultiCellWidget( searchBack, 5, 5, 0, 1 ); + + cancelPB = new QPushButton( this, "cancelPB" ); + cancelPB->setText( tr( "&Cancel" ) ); + + SearchDlgLayout->addMultiCellWidget( cancelPB, 4, 5, 3, 3 ); + + // signals and slots connections + connect( findPB, SIGNAL( clicked() ), this, SLOT( Find() ) ); + connect( replacePB, SIGNAL( clicked() ), this, SLOT( Replace() ) ); + connect( replaceAllPB, SIGNAL( clicked() ), this, SLOT( ReplaceAll() ) ); + connect( cancelPB, SIGNAL( clicked() ), this, SLOT( cancel_adaptor() ) ); + + // tab order + setTabOrder( find, replace ); + setTabOrder( replace, caseSensitive ); + setTabOrder( caseSensitive, matchWord ); + setTabOrder( matchWord, searchBack ); + setTabOrder( searchBack, findPB ); + setTabOrder( findPB, replacePB ); + setTabOrder( replacePB, replaceAllPB ); + setTabOrder( replaceAllPB, cancelPB ); +} + +/* + * Destroys the object and frees any allocated resources + */ +SearchDlg::~SearchDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +void SearchDlg::Find() +{ + qWarning( "SearchDlg::Find(): Not implemented yet!" ); +} + +void SearchDlg::Replace() +{ + qWarning( "SearchDlg::Replace(): Not implemented yet!" ); +} + +void SearchDlg::ReplaceAll() +{ + qWarning( "SearchDlg::ReplaceAll(): Not implemented yet!" ); +} + +void SearchDlg::cancel_adaptor() +{ + qWarning( "SearchDlg::cancel_adaptor(): Not implemented yet!" ); +} + diff --git a/src/frontends/qt2/searchdlg.h b/src/frontends/qt2/searchdlg.h new file mode 100644 index 0000000000..b0df71a720 --- /dev/null +++ b/src/frontends/qt2/searchdlg.h @@ -0,0 +1,52 @@ +/**************************************************************************** +** Form interface generated from reading ui file 'searchdlg.ui' +** +** Created: Sun Mar 4 21:52:20 2001 +** by: The User Interface Compiler (uic) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ +#ifndef SEARCHDLG_H +#define SEARCHDLG_H + +#include +#include +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class QCheckBox; +class QComboBox; +class QLabel; +class QPushButton; + +class SearchDlg : public QDialog +{ + Q_OBJECT + +public: + SearchDlg( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~SearchDlg(); + + QLabel* findStrLabel; + QComboBox* find; + QLabel* replaceLabel; + QComboBox* replace; + QCheckBox* caseSensitive; + QCheckBox* matchWord; + QPushButton* findPB; + QPushButton* replacePB; + QPushButton* replaceAllPB; + QCheckBox* searchBack; + QPushButton* cancelPB; + +protected slots: + virtual void Find(); + virtual void Replace(); + virtual void ReplaceAll(); + virtual void cancel_adaptor(); + +protected: + QGridLayout* SearchDlgLayout; +}; + +#endif // SEARCHDLG_H diff --git a/src/frontends/qt2/searchdlg.ui b/src/frontends/qt2/searchdlg.ui new file mode 100644 index 0000000000..12d5f3480a --- /dev/null +++ b/src/frontends/qt2/searchdlg.ui @@ -0,0 +1,290 @@ + +SearchDlg + + QDialog + + name + SearchDlg + + + geometry + + 0 + 0 + 379 + 168 + + + + caption + Form1 + + + sizeGripEnabled + true + + + layoutMargin + + + layoutSpacing + + + + margin + 11 + + + spacing + 6 + + + QLabel + + name + findStrLabel + + + text + Find: + + + + QComboBox + + name + find + + + sizePolicy + + 3 + 0 + + + + editable + true + + + duplicatesEnabled + true + + + focusPolicy + StrongFocus + + + + QLabel + + name + replaceLabel + + + text + Replace with: + + + + QComboBox + + name + replace + + + sizePolicy + + 3 + 0 + + + + editable + true + + + + QCheckBox + + name + caseSensitive + + + text + &Case sensitive + + + + QCheckBox + + name + matchWord + + + text + Match whole words onl&y + + + + + name + HSpacer1 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + name + VSpacer1 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + name + VSpacer2 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton + + name + findPB + + + text + Find &Next + + + + QPushButton + + name + replacePB + + + text + &Replace + + + + QPushButton + + name + replaceAllPB + + + text + Replace &All + + + + QCheckBox + + name + searchBack + + + text + Search &backwards + + + + QPushButton + + name + cancelPB + + + text + &Cancel + + + + + + + findPB + clicked() + SearchDlg + Find() + + + replacePB + clicked() + SearchDlg + Replace() + + + replaceAllPB + clicked() + SearchDlg + ReplaceAll() + + + cancelPB + clicked() + SearchDlg + cancel_adaptor() + + Find() + Replace() + ReplaceAll() + cancel_adaptor() + + + find + replace + caseSensitive + matchWord + searchBack + findPB + replacePB + replaceAllPB + cancelPB + + diff --git a/src/frontends/qt2/searchdlgimpl.C b/src/frontends/qt2/searchdlgimpl.C new file mode 100644 index 0000000000..3bd75d2aab --- /dev/null +++ b/src/frontends/qt2/searchdlgimpl.C @@ -0,0 +1,59 @@ +/** + * \file searchdlgimpl.h + * Copyright 2001 The LyX Team. + * See the file COPYING. + * + * \author Edwin Leuven + */ + +#include "searchdlgimpl.h" + +#include +#include +#include +#include + + +SearchDlgImpl::SearchDlgImpl(FormSearch* form, QWidget* parent, const char* name, bool modal, WFlags fl ) + : SearchDlg( parent, name, modal, fl ), form_(form) +{ + setCaption(name); +} + +SearchDlgImpl::~SearchDlgImpl() +{ +} + +void SearchDlgImpl::closeEvent(QCloseEvent * e) +{ + form_->close(); + e->accept(); +} + +void SearchDlgImpl::setReadOnly(bool readonly) +{ + replace->setEnabled(!readonly); + replaceLabel->setEnabled(!readonly); + replacePB->setEnabled(!readonly); + replaceAllPB->setEnabled(!readonly); +} + +void SearchDlgImpl::Find() +{ + form_->find(tostr(find->currentText()).c_str(), + caseSensitive->isChecked(), + matchWord->isChecked(), + !searchBack->isChecked()); +} + +void SearchDlgImpl::Replace(bool replaceall = false) +{ + form_->replace(tostr(find->currentText()).c_str(), + tostr(replace->currentText()).c_str(), + caseSensitive->isChecked(), + matchWord->isChecked(), + !searchBack->isChecked(), + replaceall); +} + + diff --git a/src/frontends/qt2/searchdlgimpl.h b/src/frontends/qt2/searchdlgimpl.h new file mode 100644 index 0000000000..f99ffacc1c --- /dev/null +++ b/src/frontends/qt2/searchdlgimpl.h @@ -0,0 +1,51 @@ +#ifndef SEARCHDLGIMPL_H +#define SEARCHDLGIMPL_H + +#include "searchdlg.h" +#include "FormSearch.h" + +class QCloseEvent; + +class SearchDlgImpl : public SearchDlg +{ + Q_OBJECT + + + public: + + SearchDlgImpl(FormSearch * form, QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + + ~SearchDlgImpl(); + + void setReadOnly(bool); + + void Replace(bool); + + protected: + + void closeEvent(QCloseEvent * e); + + private: + + FormSearch * form_; + + protected slots: + + void Find(); + + void Replace() { + Replace(false); + }; + + void ReplaceAll() { + Replace(true); + }; + + void cancel_adaptor() { + form_->close(); + hide(); + } + +}; + +#endif // SEARCHDLGIMPL_H -- 2.39.5