]> git.lyx.org Git - features.git/commitdiff
re-add search dialog
authorJohn Levon <levon@movementarian.org>
Fri, 31 Aug 2001 02:34:10 +0000 (02:34 +0000)
committerJohn Levon <levon@movementarian.org>
Fri, 31 Aug 2001 02:34:10 +0000 (02:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2634 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/Dialogs.C
src/frontends/qt2/QSearch.C
src/frontends/qt2/QSearch.h
src/frontends/qt2/QSearchDialog.C
src/frontends/qt2/QSearchDialog.h
src/frontends/qt2/ui/QSearchDialog.ui

index 62e381dfd3918c63316996e43658a87ded972295..fce542250f03e9a05b5e7ddbf8a19f41d5e7ae29 100644 (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:
index 629f992e289b4efa67863e418bb8adc319c059c3..c9a015b527f9403e1124ad114921c152a5227862 100644 (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));
index 1e9fc2dbf2d1be97e00fc270bf2a46c10e09168c..becd8ecd8c966373b1229686492724943ea82ac2 100644 (file)
 /**
  * \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);
 }
index 5c62c03175940e7d8626a1bfb713fa29d07917cd..df6df73f18c54c6f091659ddede92be6d345d09c 100644 (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 &);
-       
+       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
index 682ec23fdc67cc8a9640e91ee817c7856c1b5dcf..bf8bd9ddb0c2f7b644f9060b3e48985858dbf420 100644 (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_->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);
 }
index 972dd1c4240f3b311b8986e2629ad2927f2dccee..00f59a833f44470c7b588cac00b110103b568e8d 100644 (file)
 #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
index 965652a36dbb7806118a67bb9abfb2d3d254ab25..22ce1c201d51b122e14a5d35e81caba4cf8a0e12 100644 (file)
         <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>&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>
             </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>
                 <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>
                 <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>
                 <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>
             <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>
         <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>