From 852c5178de9c3c9cdcbfd27040826be991978c37 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 23 Dec 2008 08:18:11 +0000 Subject: [PATCH] FindAndReplace by Tommaso: - solves some issues related to the dialog set-up (overlapping of dialog title with upper sub-widget), by "borrowing" the widget structure from ViewSource.{h,cpp} - reduces the default occupation of the dialog (in particular, it was "colliding" with the ViewSource itself); - proposes to introduce a tabbed-panel in the F&R dialog, so as to have a "basic" and "advanced" tabs; (one option could be to make the dialog even smaller by moving all of the replace-related stuff into a separate "Replace" tab) - recovers the eventFilter functionality back, so as to catch "Enter" or "Esc" key presses while in the Search Work Area git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27967 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/FindAndReplace.cpp | 108 ++-- src/frontends/qt4/FindAndReplace.h | 76 ++- src/frontends/qt4/ui/FindAndReplaceUi.ui | 620 ++++++++++++----------- 3 files changed, 457 insertions(+), 347 deletions(-) diff --git a/src/frontends/qt4/FindAndReplace.cpp b/src/frontends/qt4/FindAndReplace.cpp index 09ff2f257a..9f32ad9bf8 100644 --- a/src/frontends/qt4/FindAndReplace.cpp +++ b/src/frontends/qt4/FindAndReplace.cpp @@ -43,21 +43,22 @@ using namespace lyx::support; namespace lyx { namespace frontend { -FindAndReplace::FindAndReplace(GuiView & parent) - : DockView(parent, "Find LyX", "Find LyX Dialog", Qt::RightDockWidgetArea) + +FindAndReplaceWidget::FindAndReplaceWidget(GuiView & view) + : view_(view) { setupUi(this); - find_work_area_->setGuiView(parent); + find_work_area_->setGuiView(view_); find_work_area_->init(); setFocusProxy(find_work_area_); - replace_work_area_->setGuiView(parent); + replace_work_area_->setGuiView(view_); replace_work_area_->init(); // We don't want two cursors blinking. replace_work_area_->stopBlinkingCursor(); } -bool FindAndReplace::eventFilter(QObject *obj, QEvent *event) +bool FindAndReplaceWidget::eventFilter(QObject *obj, QEvent *event) { LYXERR(Debug::DEBUG, "FindAndReplace::eventFilter()" << std::endl); if (obj == find_work_area_ && event->type() == QEvent::KeyPress) { @@ -76,11 +77,11 @@ bool FindAndReplace::eventFilter(QObject *obj, QEvent *event) } } // standard event processing - return QObject::eventFilter(obj, event); + return QWidget::eventFilter(obj, event); } -void FindAndReplace::findAdv(bool casesensitive, +void FindAndReplaceWidget::findAdv(bool casesensitive, bool matchword, bool backwards, bool expandmacros, bool ignoreformat) { @@ -113,7 +114,7 @@ void FindAndReplace::findAdv(bool casesensitive, runparams.linelen = 100000; //lyxrc.plaintext_linelen; runparams.dryrun = true; for (; it != end; ++it) { - LYXERR0("Adding to search string: '" << it->asString(false) << "'"); + LYXERR(Debug::DEBUG, "Adding to search string: '" << it->asString(false) << "'"); searchString += it->stringify(pos_type(0), it->size(), AS_STR_INSETS, runparams); } } @@ -125,45 +126,33 @@ void FindAndReplace::findAdv(bool casesensitive, bool const regexp = to_utf8(searchString).find("\\regexp") != std::string::npos; FindAdvOptions opt(searchString, casesensitive, matchword, ! backwards, expandmacros, ignoreformat, regexp); - std::cerr << "Dispatching LFUN_WORD_FINDADV" << std::endl; + LYXERR(Debug::DEBUG, "Dispatching LFUN_WORD_FINDADV" << std::endl); std::ostringstream oss; oss << opt; - std::cerr << "Dispatching LFUN_WORD_FINDADV" << std::endl; + LYXERR(Debug::DEBUG, "Dispatching LFUN_WORD_FINDADV" << std::endl); dispatch(FuncRequest(LFUN_WORD_FINDADV, from_utf8(oss.str()))); // findAdv(&theApp()->currentView()->currentWorkArea()->bufferView(), // searchString, len, casesensitive, matchword, ! backwards, expandmacros); } -bool FindAndReplace::initialiseParams(std::string const &) -{ - find_work_area_->redraw(); - replace_work_area_->setEnabled(true); - replace_work_area_->redraw(); - find_work_area_->setFocus(); - dispatch(FuncRequest(LFUN_BUFFER_BEGIN)); - dispatch(FuncRequest(LFUN_BUFFER_END_SELECT)); - return true; -} - -void FindAndReplace::find(bool backwards) +void FindAndReplaceWidget::find(bool backwards) { // FIXME: create a Dialog::returnFocus() or something instead of this: - GuiView & gv = const_cast(lyxview()); - gv.setCurrentWorkArea(gv.currentMainWorkArea()); + view_.setCurrentWorkArea(view_.currentMainWorkArea()); // FIXME: This should be an LFUN. findAdv(caseCB->isChecked(), wordsCB->isChecked(), backwards, expandMacrosCB->isChecked(), ignoreFormatCB->isChecked()); - gv.currentMainWorkArea()->redraw(); + view_.currentMainWorkArea()->redraw(); find_work_area_->setFocus(); } -void FindAndReplace::on_regexpInsertCombo_currentIndexChanged(int index) +void FindAndReplaceWidget::on_regexpInsertCombo_currentIndexChanged(int index) { static char const * regexps[] = { ".*", ".+", "[a-z]+", "[0-9]+" @@ -180,34 +169,89 @@ void FindAndReplace::on_regexpInsertCombo_currentIndexChanged(int index) } -void FindAndReplace::on_closePB_clicked() +void FindAndReplaceWidget::on_closePB_clicked() { dispatch(FuncRequest(LFUN_DIALOG_TOGGLE, "findreplaceadv")); } -void FindAndReplace::on_findNextPB_clicked() { +void FindAndReplaceWidget::on_findNextPB_clicked() { find(false); } -void FindAndReplace::on_findPrevPB_clicked() { +void FindAndReplaceWidget::on_findPrevPB_clicked() { find(true); } -void FindAndReplace::on_replacePB_clicked() +void FindAndReplaceWidget::on_replacePB_clicked() { } -void FindAndReplace::on_replaceallPB_clicked() +void FindAndReplaceWidget::on_replaceallPB_clicked() +{ +} + + +void FindAndReplaceWidget::showEvent(QShowEvent *ev) +{ + replace_work_area_->setEnabled(true); + replace_work_area_->redraw(); + find_work_area_->setFocus(); + dispatch(FuncRequest(LFUN_BUFFER_BEGIN)); + dispatch(FuncRequest(LFUN_BUFFER_END_SELECT)); + find_work_area_->redraw(); + find_work_area_->installEventFilter(this); +} + + +void FindAndReplaceWidget::hideEvent(QHideEvent *ev) { + find_work_area_->removeEventFilter(this); + this->QWidget::hideEvent(ev); } + +bool FindAndReplaceWidget::initialiseParams(std::string const & params) +{ + find_work_area_->redraw(); + replace_work_area_->setEnabled(true); + replace_work_area_->redraw(); + find_work_area_->setFocus(); + dispatch(FuncRequest(LFUN_BUFFER_BEGIN)); + dispatch(FuncRequest(LFUN_BUFFER_END_SELECT)); + return true; +} + + +FindAndReplace::FindAndReplace(GuiView & parent, + Qt::DockWidgetArea area, Qt::WindowFlags flags) + : DockView(parent, "Find LyX", qt_("Find LyX Dialog"), area, flags) +{ + widget_ = new FindAndReplaceWidget(parent); + setWidget(widget_); + setFocusProxy(widget_); +} + + +FindAndReplace::~FindAndReplace() +{ + setFocusProxy(0); + delete widget_; +} + + +bool FindAndReplace::initialiseParams(std::string const & params) +{ + return widget_->initialiseParams(params); +} + + Dialog * createGuiSearchAdv(GuiView & lv) { - return new FindAndReplace(lv); + return new FindAndReplace(lv, Qt::RightDockWidgetArea); } diff --git a/src/frontends/qt4/FindAndReplace.h b/src/frontends/qt4/FindAndReplace.h index 62b2b738a0..87a7328678 100644 --- a/src/frontends/qt4/FindAndReplace.h +++ b/src/frontends/qt4/FindAndReplace.h @@ -30,21 +30,34 @@ namespace lyx { namespace frontend { -class FindAndReplace : public DockView, public Ui::FindAndReplaceUi +class FindAndReplaceWidget : public QWidget, public Ui::FindAndReplaceUi { Q_OBJECT + public: - FindAndReplace(GuiView & parent); + FindAndReplaceWidget(GuiView & view); + bool initialiseParams(std::string const & params); - bool initialiseParams(std::string const &); - void clearParams() {} - void dispatchParams() {} - bool isBufferDependent() const { return true; } - void selectAll(); +private: + /// + GuiView & view_; - /// update - void updateView() {} - //virtual void update_contents() {} + // add a string to the combo if needed + void remember(std::string const & find, QComboBox & combo); + void findAdv(bool casesensitive, + bool matchword, bool backwards, + bool expandmacros, bool ignoreformat); + void find(docstring const & str, int len, bool casesens, + bool words, bool backwards, bool expandmacros); + void find(bool backwards); + + void replace(docstring const & findstr, + docstring const & replacestr, + bool casesens, bool words, bool backwards, bool expandmacros, bool all); + bool eventFilter(QObject *obj, QEvent *event); + + void virtual showEvent(QShowEvent *ev); + void virtual hideEvent(QHideEvent *ev); protected Q_SLOTS: void on_findNextPB_clicked(); @@ -53,29 +66,36 @@ protected Q_SLOTS: void on_replaceallPB_clicked(); void on_closePB_clicked(); void on_regexpInsertCombo_currentIndexChanged(int index); +}; -protected: - void find(bool backwards); - virtual bool wantInitialFocus() const { return true; } -private: - // add a string to the combo if needed - void remember(std::string const & find, QComboBox & combo); - void findAdv(bool casesensitive, - bool matchword, bool backwards, - bool expandmacros, bool ignoreformat); +class FindAndReplace : public DockView +{ + Q_OBJECT +public: + FindAndReplace( + GuiView & parent, ///< the main window where to dock. + Qt::DockWidgetArea area = Qt::RightDockWidgetArea, ///< Position of the dock (and also drawer) + Qt::WindowFlags flags = 0); -private: - /// Apply changes - virtual void apply() {} + ~FindAndReplace(); - void find(docstring const & str, int len, bool casesens, - bool words, bool backwards, bool expandmacros); + bool initialiseParams(std::string const &); + void clearParams() {} + void dispatchParams() {} + bool isBufferDependent() const { return true; } + void selectAll(); - void replace(docstring const & findstr, - docstring const & replacestr, - bool casesens, bool words, bool backwards, bool expandmacros, bool all); - bool eventFilter(QObject *obj, QEvent *event); + /// update + void updateView() {} + //virtual void update_contents() {} + +protected: + virtual bool wantInitialFocus() const { return true; } + +private: + /// The encapsulated widget. + FindAndReplaceWidget * widget_; }; diff --git a/src/frontends/qt4/ui/FindAndReplaceUi.ui b/src/frontends/qt4/ui/FindAndReplaceUi.ui index 08440d2355..2b675109d9 100644 --- a/src/frontends/qt4/ui/FindAndReplaceUi.ui +++ b/src/frontends/qt4/ui/FindAndReplaceUi.ui @@ -6,11 +6,11 @@ 0 0 240 - 432 + 400 - + 0 0 @@ -33,307 +33,353 @@ - + - 20 - 20 - 212 - 404 + 0 + 0 + 231 + 381 - - - - - true - - - - - 0 - 0 - 208 - 69 - - - - - - - - - false - - - &Expand macros - - - - - - - Case &sensitive - - - - - - - false - - - Whole words onl&y - - - - - - - true - - - Ignore For&mat - - - true - - - - - - - true - - - Find &Next - - - true - - - - - - - true - - - Find &Prev - - - true - - - - - - - false - - - &Replace - - - - - - - false - - - Replace &All - - - - - - - &Close - - - - - - - false - - - - 0 - 0 - - - - - 0 - 111 - - - - Sco&pe - - - - - 10 - 40 - 121 - 23 - - - - Current buffer only - - - Buffer - - - true - - - - - - 10 - 60 - 121 - 23 - - - - Current file and all included files - - - Document - - - - - - 10 - 20 - 121 - 23 - - - - Current paragraph only - - - Paragraph - - - false - - - - - - 10 - 80 - 121 - 23 - - - - All open buffers - - - Open buffers - - - - - - - - true - - - - 0 - 0 - - - - - 0 - 111 - - - - RegExp + + + 0 + 0 + + + + 0 + + + + + 0 + 0 + + + + Basic + + + + + 0 + 0 + 227 + 351 + + + + + QLayout::SetNoConstraint - - - true - - - - 10 - 52 - 101 - 20 - - - - - 0 - 0 - - - + + + + + 0 + 128 + + + + true + + + + + 0 + 0 + 221 + 85 + + + + + + + + + false + - Match... + Whole &words + + + + + + + true - - - Anything + Find &Next + + + true + + + + + + + false - - - Any non-empty + Replace Ne&xt + + + + + + + false - - - Any word + Replace &All - - + + + + - Any number + &Close - - - - - - - - true - - - - - 0 - 0 - 208 - 69 - - - - - - - replace_work_area_ + + + + + + + 0 + 128 + + + + true + + + + + 0 + 0 + 221 + 85 + + + + + + + + + true + + + Find &Prev + + + true + + + + + + + false + + + Replace P&rev + + + + + + + Case &sensitive + + + + + + + true + + + Ignore For&mat + + + true + + + + + + + true + + + + 0 + 0 + + + + + Match... + + + + + Anything + + + + + Any non-empty + + + + + Any word + + + + + Any number + + + + + + + + + + + 0 + 0 + + + + Advanced + + + + + 0 + 0 + 221 + 143 + + + + + + + false + + + + 0 + 0 + + + + + 0 + 111 + + + + Sco&pe + + + + + 10 + 40 + 121 + 23 + + + + Current buffer only + + + Buffer + + + true + + + + + + 10 + 60 + 121 + 23 + + + + Current file and all included files + + + Document + + + + + + 10 + 20 + 121 + 23 + + + + Current paragraph only + + + Paragraph + + + false + + + + + + 10 + 80 + 121 + 23 + + + + All open buffers + + + Open buffers + + + + + + + + false + + + &Expand macros + + + + + + - layoutWidget - replace_work_area_ - groupBox_3 -- 2.39.2