]> git.lyx.org Git - features.git/commitdiff
ref dialog, more updates (BC stuff should now be OK along with the coming
authorJohn Levon <levon@movementarian.org>
Sun, 26 Aug 2001 00:29:39 +0000 (00:29 +0000)
committerJohn Levon <levon@movementarian.org>
Sun, 26 Aug 2001 00:29:39 +0000 (00:29 +0000)
controllers/ patch)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2586 a592a061-630c-0410-9148-cb99ea01b6c8

22 files changed:
src/frontends/qt2/ChangeLog
src/frontends/qt2/Dialogs.C
src/frontends/qt2/QAbout.C
src/frontends/qt2/QAbout.h
src/frontends/qt2/QCitation.C
src/frontends/qt2/QCitation.h
src/frontends/qt2/QCitationDialog.C
src/frontends/qt2/QDocument.C
src/frontends/qt2/QDocument.h
src/frontends/qt2/QIndex.C
src/frontends/qt2/QIndex.h
src/frontends/qt2/QRef.C
src/frontends/qt2/QRef.h
src/frontends/qt2/QRefDialog.C
src/frontends/qt2/QRefDialog.h
src/frontends/qt2/QURL.C
src/frontends/qt2/QURL.h
src/frontends/qt2/Qt2BC.C
src/frontends/qt2/Qt2Base.C
src/frontends/qt2/Qt2Base.h
src/frontends/qt2/README
src/frontends/qt2/ui/QRefDialog.ui

index fc88887c017ada2958ab7a1b89a5ee351d9d37e0..db1ff7b015e1cf26a44f8ab1deaab18cdb1bb2ad 100644 (file)
@@ -1,3 +1,20 @@
+2001-08-26  John Levon  <moz@compsoc.man.ac.uk>
+
+       * Dialogs.C: 
+       * QRef.[Ch]:
+       * ui/QRefDialog.ui: add Ref dialog back
+
+       * QAbout.[Ch]:
+       * QCitation.[Ch]: 
+       * QDocument.[Ch]: 
+       * QIndex.[Ch]: 
+       * QURL.[Ch]:
+       * Qt2Base.h: protect build() with updating_ too 
+
+       * QCitationDialog.C: use Qt2Base::readOnly
+
+       * README: update
+        
 2001-08-25  John Levon  <moz@compsoc.man.ac.uk>
 
        * Dialogs.C: add URL
index 9aeb6129f0e8a9731f2a05643e3c1e7af38e528b..dc5928e6d14782cdfe2f21662bd3e3ba9ae0c396 100644 (file)
 #include "QAboutDialog.h"
 #include "QCitationDialog.h"
 #include "QIndexDialog.h"
+#include "QRefDialog.h"
 #include "QURLDialog.h"
  
-// the controller interface
 #include "QAbout.h"
 #include "QCharacter.h"
 #include "QCitation.h"
 #include "QIndex.h"
 #include "QParagraph.h"
 #include "QPrint.h"
+#include "QRef.h"
 #include "QSearch.h"
 #include "QSplash.h"
 #include "QTabularCreate.h"
@@ -45,6 +46,7 @@
 #include "controllers/ControlAboutlyx.h"
 #include "controllers/ControlCitation.h"
 #include "controllers/ControlIndex.h"
+#include "controllers/ControlRef.h"
 #include "controllers/ControlSplash.h"
 #include "controllers/ControlUrl.h" 
 #if 0
@@ -90,6 +92,7 @@ Dialogs::Dialogs(LyXView * lv)
        add(new GUICitation<QCitation, Qt2BC>(*lv, *this));
        add(new GUIAboutlyx<QAbout, Qt2BC>(*lv, *this));
        add(new GUIIndex<QIndex, Qt2BC>(*lv, *this));
+       add(new GUIRef<QRef, Qt2BC>(*lv, *this));
        add(new GUIUrl<QURL, Qt2BC>(*lv, *this));
 
        // reduce the number of connections needed in
index f5c2432b1de9d56faf1f12ac9658f656b02f824f..e4a296ca3e9aa011e632ebecf43851db6f100ce5 100644 (file)
@@ -32,7 +32,7 @@ QAbout::QAbout(ControlAboutlyx & c)
 }
 
 
-void QAbout::build()
+void QAbout::build_dialog()
 {
        dialog_.reset(new QAboutDialog());
        connect(dialog_.get()->closePB, SIGNAL(clicked()),
index eafe752b6c21e04172ff4aff0092af71da705921..525038b6834c8a47b8f160be50569c390c6bfa8e 100644 (file)
@@ -30,7 +30,7 @@ private:
        /// not needed
        virtual void update_contents() {}
        // build the dialog
-       virtual void build();
+       virtual void build_dialog();
 };
 
 #endif // FORMABOUT_H
index cf15eba6d9bb1b80217b6142a4129f96064b4552..0d1770dedaf688a8f6647282e07d4714dcca995e 100644 (file)
@@ -65,13 +65,13 @@ void QCitation::hide()
 }
 
 
-void QCitation::build()
+void QCitation::build_dialog()
 {
        dialog_.reset(new QCitationDialog(this));
 
        dialog_->searchTypeCB->setChecked(false);
        dialog_->searchCaseCB->setChecked(false);
-       
+
        // Manage the ok, apply, restore and cancel/close buttons
        bc().setOK(dialog_->okPB);
        bc().setApply(dialog_->applyPB);
index 4713784fb86ddfc927ce27163c85bf2ac61948b9..248337f71432a25ca89a6b0a69bfb748e706ca0c 100644 (file)
@@ -42,7 +42,7 @@ private:
        /// Set the Params variable for the Controller.
        virtual void apply();
        /// Build the dialog.
-       virtual void build();
+       virtual void build_dialog();
        /// Hide the dialog.
        virtual void hide();
        /// Update dialog before/whilst showing it.
index 3e1a15b2a8ddfad4c2d2c05da4e33b4b5824373b..1aefb79d0db413ac371923ae506f48277b83c66d 100644 (file)
@@ -62,7 +62,7 @@ void QCitationDialog::slotBibSelected(int sel)
 {
        slotBibHighlighted(sel);
  
-       if (form_->controller().isReadonly()) 
+       if (form_->readOnly()) 
                return;
  
        slotAddClicked();
@@ -98,7 +98,7 @@ void QCitationDialog::slotBibHighlighted(int sel)
                citeLB->setTopItem(n);
        }
 
-       if (!form_->controller().isReadonly()) {
+       if (!form_->readOnly()) {
                if (cit != form_->citekeys.end()) {
                        form_->setBibButtons(QCitation::OFF);
                        form_->setCiteButtons(QCitation::ON);
@@ -119,7 +119,7 @@ void QCitationDialog::slotCiteHighlighted(int sel)
                return;
        }
 
-       if (!form_->controller().isReadonly()) {
+       if (!form_->readOnly()) {
                form_->setBibButtons(QCitation::OFF);
                form_->setCiteButtons(QCitation::ON);
        }
index aeea3dc2065152f4a873f989484ed55ec2fe8388..1bf777f30419aff0267fe5a138e376d15a61cc4e 100644 (file)
@@ -49,7 +49,7 @@ QDocument::QDocument(ControlDocument & c)
 #endif 
 
 
-void QDocument::build()
+void QDocument::build_dialog()
 {
        int n;
 
index f8aa0265a7158dc5dd00071a3385c93f53516a79..c58f4a5b89ffbad09cb18b0a893972b08c106926 100644 (file)
@@ -71,7 +71,7 @@ private:
        /// Pointer to the actual instantiation of the ButtonController.
        virtual Qt2BC & bc();
        /// Build the dialog
-       virtual void build();
+       virtual void build_dialog();
 //     /// Filter the inputs
 //     virtual bool input( FL_OBJECT *, long );
        /// Update the dialog.
index e684e7722543ee55f1e251cc2b3280488617b9b7..d99e60407f3382c208a32068016938dff30b1e26 100644 (file)
 
 #include "QIndexDialog.h"
 #include "ControlIndex.h"
-#include "QtLyXView.h" 
-#include "BufferView.h"
-
-#include "Dialogs.h"
-#include "Qt2BC.h"
 #include "QIndex.h"
+#include "Qt2BC.h"
 #include "gettext.h"
-#include "buffer.h"
-#include "lyxfunc.h" 
 
 #include <qlineedit.h>
 #include <qpushbutton.h>
@@ -31,7 +25,7 @@ QIndex::QIndex(ControlIndex & c)
 }
 
 
-void QIndex::build()
+void QIndex::build_dialog()
 {
        dialog_.reset(new QIndexDialog(this));
 
index d77b82bcf2b0eb2f391083a678e8cb1165c38715..44d8c965e537463d6cbf6e079c6a875fd2031468 100644 (file)
@@ -33,7 +33,7 @@ private:
        /// update
        virtual void update_contents();
        /// build the dialog
-       virtual void build();
+       virtual void build_dialog();
 };
 
 #endif // QINDEX_H
index 2d04c8fc86acd44a3a31e39ddae80dcf7c3a18eb..3c9deea407acdf19d6deb0e3d24c2b967100d0f7 100644 (file)
 
 #include <config.h>
 
+#include "support/lstrings.h"
 #include "QRefDialog.h"
-
-#include "QtLyXView.h"
-#include "BufferView.h"
-#include "Dialogs.h"
+#include "ControlRef.h"
 #include "QRef.h"
+#include "Qt2BC.h" 
 #include "gettext.h"
-#include "buffer.h"
-#include "lyxfunc.h"
-#include "debug.h"
+#include "insets/insetref.h"
 
-#include <qpushbutton.h>
 #include <qlineedit.h>
+#include <qcheckbox.h>
 #include <qlistbox.h>
 #include <qcombobox.h>
-#include <qcheckbox.h>
+#include <qpushbutton.h>
+#include <qtooltip.h>
 
 using std::endl;
 
-QRef::QRef(LyXView *v, Dialogs *d)
-       : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0),
-       sort(0), gotowhere(GOTOREF), type(REF), refs(0)
+typedef Qt2CB<ControlRef, Qt2DB<QRefDialog> > base_class;
+QRef::QRef(ControlRef & c)
+       : base_class(c, _("Cross Reference")),
+       sort_(false), at_ref_(false)
 {
-       // let the dialog be shown
-       // This is a permanent connection so we won't bother
-       // storing a copy because we won't be disconnecting.
-       d->showRef.connect(slot(this, &QRef::showRef));
-       d->createRef.connect(slot(this, &QRef::createRef));
 }
 
 
-QRef::~QRef()
+void QRef::build_dialog()
 {
-       delete dialog_;
+       dialog_.reset(new QRefDialog(this));
+
+       bc().setOK(dialog_->okPB); 
+       bc().setCancel(dialog_->closePB); 
+       bc().addReadOnly(dialog_->refsLB);
+       bc().addReadOnly(dialog_->sortCB);
+       bc().addReadOnly(dialog_->nameED);
+       bc().addReadOnly(dialog_->referenceED);
+       bc().addReadOnly(dialog_->typeCO);
 }
 
-
-void QRef::showRef(InsetCommand * const inset)
+void QRef::update_contents()
 {
-       // FIXME: when could inset be 0 here ?
-       if (inset==0)
-               return;
+       dialog_->referenceED->setText(controller().params().getContents().c_str());
+       dialog_->nameED->setText(controller().params().getOptions().c_str());
 
-       inset_ = inset;
-       readonly = lv_->buffer()->isReadonly();
-       //ih_ = inset_->hide.connect(slot(this,&QRef::hide));
-       params = inset->params();
-       
-       show();
+       dialog_->typeCO->setCurrentItem(InsetRef::getType(controller().params().getCmdName()));
+
+       dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
+
+       dialog_->typeCO->setEnabled(!typeAllowed() && !readOnly());
+       if (!typeAllowed())
+               dialog_->typeCO->setCurrentItem(0);
+
+       dialog_->sortCB->setChecked(sort_);
+
+       updateRefs();
 }
 
 
-void QRef::createRef(string const & arg)
+void QRef::apply()
 {
-       if (inset_)
-               close();
-
-       readonly = lv_->buffer()->isReadonly();
-       params.setFromString(arg);
-       show();
+       controller().params().setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
+       controller().params().setContents(dialog_->referenceED->text().latin1());
+       controller().params().setOptions(dialog_->nameED->text().latin1());
 }
 
 
-void QRef::select(const char *text)
+bool QRef::nameAllowed()
 {
-       highlight(text);
-       goto_ref();
+       return controller().docType() != ControlRef::LATEX &&
+               controller().docType() != ControlRef::LITERATE;
 }
 
  
-void QRef::highlight(const char *text)
+bool QRef::typeAllowed()
 {
-       if (gotowhere==GOTOBACK)
-               goto_ref();
-
-       dialog_->gotoPB->setEnabled(true);
-       if (!readonly) {
-               dialog_->typeCO->setEnabled(true);
-               dialog_->referenceED->setText(text);
-               dialog_->okPB->setEnabled(true);
-       }
+       return controller().docType() == ControlRef::LINUXDOC ||
+           controller().docType() == ControlRef::DOCBOOK;
 }
 
  
-void QRef::set_sort(bool on)
+void QRef::setGoBack()
 {
-       if (on!=sort) {
-               sort=on;
-               dialog_->refsLB->clear();
-               updateRefs();
-       }
+       dialog_->gotoPB->setText(_("&Go back"));
+       QToolTip::remove(dialog_->gotoPB);
+       QToolTip::add(dialog_->gotoPB, _("Go back"));
 }
 
  
-void QRef::goto_ref()
+void QRef::setGotoRef()
 {
-       switch (gotowhere) {
-               case GOTOREF:
-                       lv_->getLyXFunc()->dispatch(LFUN_REF_GOTO, dialog_->referenceED->text().latin1());
-                       gotowhere=GOTOBACK;
-                       dialog_->gotoPB->setText(_("&Go back"));
-                       break;
-               case GOTOBACK:
-                       //FIXME lv_->getLyXFunc()->dispatch(LFUN_REF_BACK);
-                       gotowhere=GOTOREF;
-                       dialog_->gotoPB->setText(_("&Goto reference"));
-                       break;
-               }
+       dialog_->gotoPB->setText(_("&Go to reference"));
+       QToolTip::remove(dialog_->gotoPB);
+       QToolTip::add(dialog_->gotoPB, _("Go to reference"));
 }
 
  
-void QRef::updateRefs()
+void QRef::gotoRef()
 {
-       // list will be re-done, should go back if necessary
-       if (gotowhere==GOTOBACK) {
-               //FIXME lv_->getLyXFunc()->dispatch(LFUN_REF_BACK);
-               gotowhere = GOTOREF;
-               dialog_->gotoPB->setText(_("&Goto reference"));
+       string ref(dialog_->referenceED->text());
+
+       if (at_ref_) {
+               // go back
+               setGotoRef();
+               controller().gotoBookmark();
+       } else {
+               // go to the ref
+               setGoBack();
+               controller().gotoRef(ref);
        }
+       at_ref_ = !at_ref_;
+}
 
+void QRef::redoRefs()
+{
        dialog_->refsLB->setAutoUpdate(false);
 
        // need this because Qt will send a highlight() here for
        // the first item inserted
        string tmp(dialog_->referenceED->text());
 
-       for (std::vector< string >::const_iterator iter = refs.begin();
-               iter != refs.end(); ++iter) {
-               if (sort)
+       for (std::vector<string>::const_iterator iter = refs_.begin();
+               iter != refs_.end(); ++iter) {
+               if (sort_)
                        dialog_->refsLB->inSort(iter->c_str());
                else
                        dialog_->refsLB->insertItem(iter->c_str());
@@ -145,7 +142,7 @@ void QRef::updateRefs()
        dialog_->referenceED->setText(tmp.c_str());
 
        for (unsigned int i = 0; i < dialog_->refsLB->count(); ++i) {
-               if (!strcmp(dialog_->referenceED->text(),dialog_->refsLB->text(i)))
+               if (!compare(tmp.c_str(), dialog_->refsLB->text(i).latin1()))
                        dialog_->refsLB->setCurrentItem(i);
        }
 
@@ -153,135 +150,15 @@ void QRef::updateRefs()
        dialog_->refsLB->update();
 }
 
-void QRef::do_ref_update()
-{
-       refs.clear();
-       dialog_->refsLB->clear();
-       refs = lv_->buffer()->getLabelList();
-       if (!refs.empty())
-               dialog_->sortCB->setEnabled(true);
-       updateRefs();
-}
-
-void QRef::update()
-{
-       // FIXME: needs updating
-       dialog_->referenceED->setText(params.getContents().c_str());
-       dialog_->nameED->setText(params.getOptions().c_str());
 
-       if (params.getCmdName()=="pageref") {
-               type = PAGEREF;
-               dialog_->typeCO->setCurrentItem(1);
-       } else if (params.getCmdName()=="vref") {
-               type = VREF;
-               dialog_->typeCO->setCurrentItem(2);
-       } else if (params.getCmdName()=="vpageref") {
-               type = VPAGEREF;
-               dialog_->typeCO->setCurrentItem(3);
-       } else if (params.getCmdName()=="prettyref") {
-               type = PRETTYREF;
-               dialog_->typeCO->setCurrentItem(4);
-       } else {
-               type = REF;
-               dialog_->typeCO->setCurrentItem(0);
-       }
-
-       dialog_->gotoPB->setText(_("&Goto reference"));
-
-       gotowhere = GOTOREF;
-
-       dialog_->sortCB->setChecked(sort);
-
-       do_ref_update();
-
-       dialog_->gotoPB->setEnabled(params.getContents()!="");
-       dialog_->okPB->setEnabled(params.getContents()!="");
-
-       dialog_->typeCO->setEnabled(!readonly);
-       dialog_->sortCB->setEnabled(!readonly);
-       dialog_->refsLB->setEnabled(!readonly);
-       dialog_->okPB->setEnabled(!readonly);
-       dialog_->updatePB->setEnabled(!readonly);
-       if (readonly)
-               dialog_->cancelPB->setText(_("&Close"));
-       else
-               dialog_->cancelPB->setText(_("&Cancel"));
-}
-
-void QRef::apply()
-{
-       if (readonly)
-               return;
-
-       if (!lv_->view()->available())
-               return;
-
-       switch (dialog_->typeCO->currentItem()) {
-               case 0:
-                       params.setCmdName("ref");
-                       break;
-               case 1:
-                       params.setCmdName("pageref");
-                       break;
-               case 2:
-                       params.setCmdName("vref");
-                       break;
-               case 3:
-                       params.setCmdName("vpageref");
-                       break;
-               case 4:
-                       params.setCmdName("prettyref");
-                       break;
-               default:
-                       lyxerr[Debug::GUI] << "Unknown Ref Type" << endl;
-       }
-
-       params.setContents(dialog_->referenceED->text().latin1());
-       params.setOptions(dialog_->nameED->text().latin1());
-
-       if (inset_ != 0) {
-               if (params != inset_->params()) {
-                       inset_->setParams(params);
-                       lv_->view()->updateInset(inset_, true);
-               }
-       } else
-               lv_->getLyXFunc()->dispatch(LFUN_REF_INSERT, params.getAsString().c_str());
-}
-
-void QRef::show()
-{
-       if (!dialog_)
-               dialog_ = new QRefDialog(this, 0, _("LyX: Cross Reference"), false);
-
-       if (!dialog_->isVisible()) {
-               h_ = d_->hideBufferDependent.connect(slot(this, &QRef::hide));
-               //u_ = d_->updateBufferDependent.connect(slot(this, &QRef::update));
-       }
-
-       dialog_->raise();
-       dialog_->setActiveWindow();
-
-       update();
-       dialog_->show();
-}
-
-void QRef::close()
-{
-       h_.disconnect();
-       u_.disconnect();
-       ih_.disconnect();
-       inset_ = 0;
-}
-
-void QRef::hide()
+void QRef::updateRefs()
 {
-       dialog_->hide();
-       close();
+       refs_.clear();
+       if (at_ref_)
+               gotoRef();
+       dialog_->refsLB->clear();
+       refs_ = controller().getLabelList();
+       dialog_->sortCB->setEnabled(!refs_.empty());
+       dialog_->refsLB->setEnabled(!refs_.empty()); 
+       redoRefs();
 }
index 60116d7c578477f247e221e68eecb18b6f9ff52a..59f35802ab74f400558b8b5a0fa397b8129f946f 100644 (file)
-// -*- C++ -*-
 /**
  * \file QRef.h
  * Copyright 2001 the LyX Team
  * Read the file COPYING
  *
- * \author John Levon <moz@compsoc.man.ac.uk>
- * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
+ * \author John Levon
  */
 
 #ifndef QREF_H
 #define QREF_H
 
-#include "DialogBase.h"
+#include <config.h>
+#include <vector>
 #include "LString.h"
-#include "boost/utility.hpp"
-#include "insets/insetcommand.h"
+#include "Qt2Base.h"
 
-class Dialogs;
-class LyXView;
+class ControlRef;
 class QRefDialog;
 
-class QRef : public DialogBase {
+class QRef :
+       public Qt2CB<ControlRef, Qt2DB<QRefDialog> >
+{
+       friend class QRefDialog;
 public: 
-       QRef(LyXView *, Dialogs *);
-       ~QRef();
+       QRef(ControlRef & c);
 
-       /// double-click a ref
-       void select(const char *);
-       /// highlight a ref
-       void highlight(const char *);
-       /// set sort
-       void set_sort(bool);
-       /// goto a ref (or back)
-       void goto_ref(); 
+private:
+       /// apply changes 
+       virtual void apply(); 
+       /// build dialog
+       virtual void build_dialog();
        /// update dialog
-       void update(); 
-       /// update just the refs
-       void do_ref_update();
-       /// Apply changes
-       void apply();
-       /// close the connections
-       void close();
-private: 
-       enum Type {
-               REF, PAGEREF, VREF, VPAGEREF, PRETTYREF
-       };
+       virtual void update_contents();
+
+       /// is name allowed for this ? 
+       bool nameAllowed();
 
-       enum GotoType {
-               GOTOREF, GOTOBACK
-       };
+       /// is type allowed for this ?
+       bool typeAllowed();
  
-       /// Create the dialog if necessary, update it and display it.
-       void show();
-       /// Hide the dialog.
-       void hide();
+       /// go to current reference
+       void gotoRef();
+
+       /// set go back button
+       void setGoBack();
  
-       /// create a Reference inset
-       void createRef(string const &);
-       /// edit a Reference inset
-       void showRef(InsetCommand * const);
+       /// set goto ref button
+       void setGotoRef();
  
-       /// update the keys list
-       void updateRefs(void);
+       /// re-enter references
+       void redoRefs();
  
-       /// Real GUI implementation.
-       QRefDialog * dialog_;
-
-       /// the LyXView we belong to
-       LyXView * lv_;
+       /// update references
+       void updateRefs();
  
-       /** Which Dialogs do we belong to?
-           Used so we can get at the signals we have to connect to.
-       */
-       Dialogs * d_;
-       /// pointer to the inset if any
-       InsetCommand * inset_;
-       /// insets params
-       InsetCommandParams params;
-       /// is the inset we are reading from a readonly buffer ?
-       bool readonly;
-       
-       /// Hide connection.
-       SigC::Connection h_;
-       /// Update connection.
-       SigC::Connection u_;
-       /// Inset hide connection.
-       SigC::Connection ih_;
+       /// sort or not persistent state
+       bool sort_; 
 
-       /// to sort or not to sort
-       bool sort;
-       /// where to go
-       GotoType gotowhere;
-       /// current type
-       Type type;
+       /// at a reference ? 
+       bool at_ref_;
  
-       /// available references
-       std::vector< string > refs;
+       /// the references
+       std::vector<string> refs_;
 };
 
 #endif // QREF_H
index 050c2b826b769794db1ed35202d9827cf7e002ad..4530a3ea0f55e5c8d217c628b302057248cd080f 100644 (file)
@@ -4,72 +4,83 @@
  * Read the file COPYING
  *
  * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
+ * \author John Levon <moz@compsoc.man.ac.uk>
  */
 
+#include <config.h>
+
+#include <qpushbutton.h>
+#include <qlineedit.h> 
+#include <qcombobox.h>
+#include <qlistbox.h> 
 #include "QRefDialog.h"
+#include "ControlRef.h" 
 #include "Dialogs.h"
 #include "QRef.h"
+#include "debug.h"
 
-QRefDialog::QRefDialog(QRef * form, QWidget * parent, const char * name, bool modal, WFlags fl)
-       : QRefDialogBase(parent, name, modal, fl),
+QRefDialog::QRefDialog(QRef * form)
+       : QRefDialogBase(0, 0, false, 0),
        form_(form)
 {
+       connect(okPB, SIGNAL(clicked()),
+               form_, SLOT(slotOK()));
+       connect(closePB, SIGNAL(clicked()),
+               form_, SLOT(slotClose()));
 }
 
 
-QRefDialog::~QRefDialog()
+void QRefDialog::changed_adaptor()
 {
-}
-
-void QRefDialog::apply_adaptor()
-{
-       form_->apply();
-       form_->close();
-       hide();
+       form_->changed();
 }
 
 
-void QRefDialog::goto_adaptor()
+void QRefDialog::gotoClicked()
 {
-       form_->goto_ref();
+       form_->gotoRef();
 }
 
 
-void QRefDialog::highlight_adaptor(const QString & sel)
+void QRefDialog::refHighlighted(const QString & sel)
 {
-       form_->highlight(sel); 
+       if (form_->readOnly())
+               return;
+
+       referenceED->setText(sel); 
+       if (form_->at_ref_)     
+               form_->gotoRef();
+       gotoPB->setEnabled(true);
+       if (form_->typeAllowed())
+               typeCO->setEnabled(true);
+       if (form_->nameAllowed())
+               nameED->setEnabled(true);
 }
 
-
-void QRefDialog::close_adaptor()
-{
-       form_->close();
-       hide();
-}
-
-
-void QRefDialog::select_adaptor(const QString & sel)
+void QRefDialog::refSelected(const QString & sel)
 {
-       form_->select(sel);
+       form_->gotoRef();
 }
 
 
-void QRefDialog::sort_adaptor(bool sort)
+void QRefDialog::sortToggled(bool on)
 {
-       form_->set_sort(sort);
+       form_->sort_ = on;
+       refsLB->clear();
+       form_->redoRefs();
 }
 
 
-void QRefDialog::update_adaptor()
+void QRefDialog::updateClicked()
 {
-       form_->do_ref_update();
+       form_->updateRefs();
 }
 
 
-
 void QRefDialog::closeEvent(QCloseEvent * e)
 {
-       form_->close();
+       form_->slotWMHide();
        e->accept();
 }
index cdd1eb8e2196d49a15d59ab236e96b40e01937e8..58135793934196007aa31add467129a33f4fb4ae 100644 (file)
@@ -4,6 +4,7 @@
  * Read the file COPYING
  *
  * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
+ * \author John Levon <moz@compsoc.man.ac.uk>
  */
 
 #ifndef QREFDIALOG_H
@@ -19,17 +20,15 @@ class QRefDialog : public QRefDialogBase
 { Q_OBJECT
 
 public:
-       QRefDialog(QRef * form, QWidget * parent = 0, const char * name = 0, bool modal = FALSE, WFlags fl = 0);
-       ~QRefDialog();
+       QRefDialog(QRef * form);
 
 public slots:
-       void apply_adaptor();
-       void goto_adaptor();
-       void highlight_adaptor(const QString &);
-       void close_adaptor();
-       void select_adaptor(const QString &);
-       void sort_adaptor(bool);
-       void update_adaptor();
+       void changed_adaptor();
+       void gotoClicked();
+       void refHighlighted(const QString &);
+       void refSelected(const QString &);
+       void sortToggled(bool);
+       void updateClicked();
 
 protected:
        void closeEvent(QCloseEvent * e);
index 45c8eb4d957c55d9daebc823bc8c75fda2bb2837..d633baad36026072bafea75db8c278e29ca0476e 100644 (file)
@@ -27,7 +27,7 @@ QURL::QURL(ControlUrl & c)
 }
 
 
-void QURL::build()
+void QURL::build_dialog()
 {
        dialog_.reset(new QURLDialog(this));
 
index af6ab0727eb3bc4cf3981aee0f395c567b21a164..70d3339dc6e5baea8ce3cbf2a1270ec005657f58 100644 (file)
@@ -28,7 +28,7 @@ private:
        /// apply dialog
        virtual void apply();
        /// build dialog
-       virtual void build();
+       virtual void build_dialog();
        /// update dialog
        virtual void update_contents();
 };
index 46b7b47524a9ff068d7f1de5acf988cb485cb2d0..437be4830851791b5b3a10f357a5f605f4b1d30f 100644 (file)
@@ -35,9 +35,6 @@ void Qt2BC::setButtonEnabled(QButton * obj, bool enabled)
 
 void Qt2BC::setWidgetEnabled(QWidget * obj, bool enabled)
 {
-       lyxerr << "Qt2BC: setting " 
-               << obj << " to " << enabled << std::endl;
        // yuck, rtti, but the user comes first
        if (obj->inherits("QLineEdit")) {
                QLineEdit * le(static_cast<QLineEdit*>(obj)); 
index 71bf92afd5ce44eaa6aa43e3d8fbbccc70240bef..5d23347d99ea57dccad19c01505ffcc4740df473 100644 (file)
@@ -65,8 +65,6 @@ bool Qt2Base::isValid()
  
 void Qt2Base::changed()
 {
-       lyxerr << "got changed() during updating:" << updating_ << std::endl;
        if (updating_)
                return;
  
index a6a660b4257e72ef6981eee1d05f34131d25287c..2bdc6ad7be22bba1c003fec21e1ba6249ebd83fe 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "ViewBase.h"
 #include "LString.h"
+#include "debug.h"
 #include "ButtonPolicies.h"
 #include "ControlButtons.h"
 
@@ -46,8 +47,8 @@ public:
        virtual ~Qt2Base() {}
 
 protected:
-       /// Build the dialog
-       virtual void build() = 0;
+       /// build the actual dialog
+       virtual void build_dialog() = 0;
        /// Hide the dialog.
        virtual void hide();
        /// Create the dialog if necessary, update it and display it.
@@ -99,8 +100,12 @@ protected:
        /// update the dialog 
        virtual void update();
  
+       /// Build the dialog
+       virtual void build();
        /// Pointer to the actual instantiation of the Qt dialog
        virtual QDialog * form() const;
        /// Real GUI implementation.
        boost::scoped_ptr<Dialog> dialog_;
 
@@ -125,11 +130,8 @@ void Qt2DB<Dialog>::update()
 {
        form()->setUpdatesEnabled(false);
  
-       // this is tricky. First we process pending events
-       // as a result of the bc() state change (if any).
-       // then we lock out any bc() changes as a result of
-       // "innocent" updates during update_contents()
-       // then we enable normal behaviour again.
+       // protect the BC from unwarranted state transitions
        qApp->processEvents();
        updating_ = true;
        update_contents();
@@ -141,9 +143,27 @@ void Qt2DB<Dialog>::update()
 }
 
  
+template <class Dialog>
+void Qt2DB<Dialog>::build()
+{
+       // protect the BC from unwarranted state transitions
+       qApp->processEvents();
+       updating_ = true;
+       build_dialog();
+       qApp->processEvents();
+       updating_ = false;
+}
+
 template <class Controller, class Base>
 class Qt2CB: public Base
 {
+public:
+       bool readOnly() const {
+               return controller().isReadonly();
+       }
+
 protected:
        ///
        Qt2CB(ControlButtons &, const QString&);
index c6e300a8edcdaa1b5e4a8100a6f8374d283ea23a..ff2905f15bf608627e09be3283400ab817cf0726 100644 (file)
@@ -19,7 +19,9 @@ of the current dialog's contents.
 OK/Apply/Restore/Close should be connected in the derived class's constructor
 to call form_->slotOK() etc. Refer to close/cancel as close in the source.
  
-Override update_contents() to update the dialog, not update()
+Override update_contents() to update the dialog, not update(), and build_dialog(),
+not build(). Only these functions may change dialog widgets that may emit changed()
+during initialisation, to prevent the button controller from changing its state.
 
 Never call buttoncontroller functions directly from dialogs. In general, you
 should use Qt2Base::changed() in all circumstances. However, if you must call
@@ -58,10 +60,10 @@ Document    Kalle           Waiting for MVC
 Index          Kalle           Done
 Paragraph      Edwin           Waiting for MVC
 Print          Edwin
-Ref            Kalle
+Ref            Kalle           Done
 Search         Edwin
 Splash         Edwin
 Tabular                                Waiting for MVC
 TabularCreate  Edwin
 Toc            Kalle
-Url            Kalle
+Url            Kalle           Done
index 353c17c6aff157c629d8905e7e0b7e33b0e6ead3..cb10bb4607c2cd7178e0835e70354e67f11e2552 100644 (file)
@@ -11,7 +11,7 @@
         <rect>
             <x>0</x>
             <y>0</y>
-            <width>417</width>
+            <width>401</width>
             <height>277</height>
         </rect>
     </property>
                         <name>name</name>
                         <cstring>refsLB</cstring>
                     </property>
+                    <property>
+                        <name>toolTip</name>
+                        <string>Available references</string>
+                    </property>
                 </widget>
                 <widget>
                     <class>QLayoutWidget</class>
                                 <name>text</name>
                                 <string>&amp;Update</string>
                             </property>
+                            <property>
+                                <name>toolTip</name>
+                                <string>Update the reference list</string>
+                            </property>
                         </widget>
                         <spacer>
                             <property>
                             </property>
                             <property>
                                 <name>toolTip</name>
-                                <string>Sort references in alphabetical order ?</string>
+                                <string>Sort references in alphabetical order</string>
                             </property>
                         </widget>
                         <spacer>
                         <name>text</name>
                         <string>&amp;Goto reference</string>
                     </property>
+                    <property>
+                        <name>toolTip</name>
+                        <string>Move the document cursor</string>
+                    </property>
                 </widget>
                 <spacer>
                     <property>
                             <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>
                     </hbox>
 </widget>
 <connections>
     <connection>
-        <sender>refsLB</sender>
-        <signal>highlighted(const QString&amp;)</signal>
+        <sender>typeCO</sender>
+        <signal>activated(int)</signal>
+        <receiver>QRefDialogBase</receiver>
+        <slot>changed_adaptor()</slot>
+    </connection>
+    <connection>
+        <sender>referenceED</sender>
+        <signal>textChanged(const QString&amp;)</signal>
         <receiver>QRefDialogBase</receiver>
-        <slot>highlight_adaptor(const QString&amp;)</slot>
+        <slot>changed_adaptor()</slot>
+    </connection>
+    <connection>
+        <sender>nameED</sender>
+        <signal>textChanged(const QString&amp;)</signal>
+        <receiver>QRefDialogBase</receiver>
+        <slot>changed_adaptor()</slot>
     </connection>
     <connection>
         <sender>refsLB</sender>
-        <signal>selected(const QString&amp;)</signal>
+        <signal>highlighted(const QString&amp;)</signal>
         <receiver>QRefDialogBase</receiver>
-        <slot>select_adaptor(const QString&amp;)</slot>
+        <slot>refHighlighted(const QString&amp;)</slot>
     </connection>
     <connection>
-        <sender>sortCB</sender>
-        <signal>toggled(bool)</signal>
+        <sender>refsLB</sender>
+        <signal>selected(const QString&amp;)</signal>
         <receiver>QRefDialogBase</receiver>
-        <slot>sort_adaptor(bool)</slot>
+        <slot>refSelected(const QString&amp;)</slot>
     </connection>
     <connection>
-        <sender>updatePB</sender>
-        <signal>clicked()</signal>
+        <sender>refsLB</sender>
+        <signal>highlighted(const QString&amp;)</signal>
         <receiver>QRefDialogBase</receiver>
-        <slot>update_adaptor()</slot>
+        <slot>changed_adaptor()</slot>
     </connection>
     <connection>
-        <sender>okPB</sender>
-        <signal>clicked()</signal>
+        <sender>sortCB</sender>
+        <signal>toggled(bool)</signal>
         <receiver>QRefDialogBase</receiver>
-        <slot>apply_adaptor()</slot>
+        <slot>sortToggled(bool)</slot>
     </connection>
     <connection>
-        <sender>cancelPB</sender>
+        <sender>gotoPB</sender>
         <signal>clicked()</signal>
         <receiver>QRefDialogBase</receiver>
-        <slot>close_adaptor()</slot>
+        <slot>gotoClicked()</slot>
     </connection>
     <connection>
-        <sender>gotoPB</sender>
+        <sender>updatePB</sender>
         <signal>clicked()</signal>
         <receiver>QRefDialogBase</receiver>
-        <slot>goto_adaptor()</slot>
+        <slot>updateClicked()</slot>
     </connection>
-    <slot access="public">apply_adaptor()</slot>
-    <slot access="public">goto_adaptor()</slot>
-    <slot access="public">highlight_adaptor(const QString&amp;)</slot>
-    <slot access="public">close_adaptor()</slot>
-    <slot access="public">select_adaptor(const QString&amp;)</slot>
-    <slot access="public">sort_adaptor(bool)</slot>
-    <slot access="public">update_adaptor()</slot>
+    <slot access="public">changed_adaptor()</slot>
+    <slot access="public">gotoClicked()</slot>
+    <slot access="public">refHighlighted(const QString&amp;)</slot>
+    <slot access="public">refSelected(const QString&amp;)</slot>
+    <slot access="public">sortToggled(bool)</slot>
+    <slot access="public">updateClicked()</slot>
 </connections>
 </UI>