]> git.lyx.org Git - features.git/commitdiff
start dissolving frontends/controllers. 40 steps to go.
authorAndré Pönitz <poenitz@gmx.net>
Fri, 5 Oct 2007 19:04:38 +0000 (19:04 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 5 Oct 2007 19:04:38 +0000 (19:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20757 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ControlRef.cpp [deleted file]
src/frontends/controllers/ControlRef.h [deleted file]
src/frontends/controllers/Makefile.am
src/frontends/qt4/Dialogs.cpp
src/frontends/qt4/GuiDialog.cpp
src/frontends/qt4/GuiDialog.h
src/frontends/qt4/GuiRef.cpp
src/frontends/qt4/GuiRef.h

diff --git a/src/frontends/controllers/ControlRef.cpp b/src/frontends/controllers/ControlRef.cpp
deleted file mode 100644 (file)
index 54b4fb7..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/**
- * \file ControlRef.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "ControlRef.h"
-
-#include "Buffer.h"
-#include "BufferList.h"
-#include "FuncRequest.h"
-
-#include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
-
-#include <boost/filesystem/operations.hpp>
-
-using lyx::docstring;
-
-using std::find;
-using std::vector;
-using std::string;
-
-namespace lyx {
-
-using support::makeAbsPath;
-using support::makeDisplayPath;
-
-namespace frontend {
-
-ControlRef::ControlRef(Dialog & d)
-       : ControlCommand(d, "ref")
-{}
-
-
-vector<docstring> const ControlRef::getLabelList(string const & name) const
-{
-       Buffer const & buf = *theBufferList().getBuffer(makeAbsPath(name).absFilename());
-       vector<docstring> list;
-       buf.getLabelList(list);
-       return list;
-}
-
-
-void ControlRef::gotoRef(string const & ref)
-{
-       dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
-       dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
-}
-
-
-void ControlRef::gotoBookmark()
-{
-       dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
-}
-
-
-vector<string> const ControlRef::getBufferList() const
-{
-       vector<string> buffers = theBufferList().getFileNames();
-       for (vector<string>::iterator it = buffers.begin();
-            it != buffers.end(); ++it) {
-               *it = lyx::to_utf8(makeDisplayPath(*it));
-       }
-
-       return buffers;
-}
-
-
-int ControlRef::getBufferNum() const
-{
-       vector<string> buffers = theBufferList().getFileNames();
-       string const name = buffer().fileName();
-       vector<string>::const_iterator cit =
-               find(buffers.begin(), buffers.end(), name);
-       if (cit == buffers.end())
-               return 0;
-       return int(cit - buffers.begin());
-}
-
-string const ControlRef::getBufferName(int num) const
-{
-       return theBufferList().getFileNames()[num];
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/controllers/ControlRef.h b/src/frontends/controllers/ControlRef.h
deleted file mode 100644 (file)
index 5829a0b..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-// -*- C++ -*-
-/**
- * \file ControlRef.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef CONTROLREF_H
-#define CONTROLREF_H
-
-
-#include "ControlCommand.h"
-#include <vector>
-
-namespace lyx {
-namespace frontend {
-
-/** A controller for the Ref Dialog.
- */
-class ControlRef : public ControlCommand {
-public:
-       ///
-       ControlRef(Dialog &);
-       ///
-       std::vector<docstring> const getLabelList(std::string const &) const;
-       ///
-       void gotoRef(std::string const &);
-       ///
-       void gotoBookmark();
-       ///
-       std::vector<std::string> const getBufferList() const;
-       ///
-       int getBufferNum() const;
-       ///
-       std::string const getBufferName(int num) const;
-private:
-       /** disconnect from the inset when the Apply button is pressed.
-        Allows easy insertion of multiple references. */
-       virtual bool disconnectOnApply() const { return true; }
-};
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // CONTROLREF_H
index 284b3f1f0c0edc4029ca43aafc8431766bf89ee0..b74066cc0bb88d8fadffc821f15787612b533618 100644 (file)
@@ -33,7 +33,6 @@ SOURCEFILES = \
        ControlParagraph.cpp \
        ControlPrefs.cpp \
        ControlPrint.cpp \
-       ControlRef.cpp \
        ControlSearch.cpp \
        ControlSendto.cpp \
        ControlShowFile.cpp \
@@ -73,7 +72,6 @@ HEADERFILES = \
        ControlParagraph.h \
        ControlPrefs.h \
        ControlPrint.h \
-       ControlRef.h \
        ControlSearch.h \
        ControlSendto.h \
        ControlShowFile.h \
index 18bef47df8dd8e8869a7c2de84c5de7a5d7422a2..8b7fd753add3016fb156f8a7ffb580d03f71ef68 100644 (file)
@@ -42,7 +42,6 @@
 #include "GuiParagraph.h"
 #include "GuiPrefs.h"
 #include "GuiPrint.h"
-#include "GuiRef.h"
 #include "GuiSearch.h"
 #include "GuiSendto.h"
 #include "GuiShowFile.h"
@@ -111,6 +110,9 @@ private:
 } // namespace anon
 
 
+Dialog * createGuiRef(LyXView & lv);
+
+
 bool Dialogs::isValidName(string const & name) const
 {
        return std::find_if(dialognames, end_dialognames,
@@ -194,7 +196,7 @@ Dialog * Dialogs::build(string const & name)
        } else if (name == "print") {
                dialog = new GuiPrintDialog(lyxview_);
        } else if (name == "ref") {
-               dialog = new GuiRefDialog(lyxview_);
+               dialog = createGuiRef(lyxview_);
        } else if (name == "sendto") {
                dialog = new GuiSendtoDialog(lyxview_);
        } else if (name == "spellchecker") {
index 950fedf40b0cd26b29b9ead02851e1e49f8c7a05..d93482538f884b2502df9105283f7b3fb6fe6673 100644 (file)
@@ -25,7 +25,7 @@ namespace lyx {
 namespace frontend {
 
 GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
-       : is_closing_(false), name_(name), controller_(0)
+       : is_closing_(false), name_(name), controller_(0), destroy_controller_(false)
 {
        lyxview_ = &lv;
 }
@@ -33,7 +33,8 @@ GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
 
 GuiDialog::~GuiDialog()
 {
-       delete controller_;
+       if (destroy_controller_)
+               delete controller_;
 }
 
 
@@ -232,10 +233,11 @@ void GuiDialog::apply()
 }
 
 
-void GuiDialog::setController(Controller * controller)
+void GuiDialog::setController(Controller * controller, bool destroy)
 {
        BOOST_ASSERT(controller);
        BOOST_ASSERT(!controller_);
+       destroy_controller_ = destroy;
        controller_ = controller;
        controller_->setLyXView(*lyxview_);
 }
index 9185a8770e3f4603471dcdf44f9ede0bc7e665ae..768b50a815f2d0c2972bf777043c63c7f85c47ad 100644 (file)
@@ -123,7 +123,7 @@ public:
         */
        //@{
        /// \param ptr is stored and destroyed by \c Dialog.
-       void setController(Controller * ptr);
+       void setController(Controller * ptr, bool destroy = true);
        //@}
 
        /** \name Dialog Components
@@ -160,6 +160,7 @@ private:
         */
        std::string name_;
        Controller * controller_;
+       bool destroy_controller_;
        LyXView * lyxview_; // FIXME: replace by moving to constructor
 };
 
index 5748cee39b46728e016b7a71075ac5d20b2e412b..d091d48343e341ca54d327bb1f642bb4be510342 100644 (file)
 
 #include "GuiRef.h"
 
-#include "ControlRef.h"
+#include "Buffer.h"
+#include "BufferList.h"
+#include "FuncRequest.h"
+
 #include "qt_helpers.h"
 
 #include "insets/InsetRef.h"
 
+#include "support/filetools.h" // MakeAbsPath, MakeDisplayPath
+
+#include <boost/filesystem/operations.hpp>
+
 #include <QLineEdit>
 #include <QCheckBox>
 #include <QListWidget>
 #include <QToolTip>
 #include <QCloseEvent>
 
+#include <algorithm>
 
+using std::find;
 using std::vector;
 using std::string;
 
-
 namespace lyx {
 namespace frontend {
 
-GuiRefDialog::GuiRefDialog(LyXView & lv)
-       : GuiDialog(lv, "ref")
+using support::makeAbsPath;
+using support::makeDisplayPath;
+
+//FIXME It should be possible to eliminate lfun_name_
+//now and recover that information from params().insetType().
+//But let's not do that quite yet.
+/// Flags what action is taken by Kernel::dispatch()
+static std::string const lfun_name_ = "ref";
+
+GuiRef::GuiRef(LyXView & lv)
+       : GuiDialog(lv, "ref"), Controller(*static_cast<Dialog*>(this)),
+               params_("ref")
 {
        setupUi(this);
-       setController(new ControlRef(*this));
+       setController(this, false);
        setViewTitle(_("Cross-reference"));
 
        sort_ = false;
@@ -88,26 +106,20 @@ GuiRefDialog::GuiRefDialog(LyXView & lv)
 }
 
 
-ControlRef & GuiRefDialog::controller()
-{
-       return static_cast<ControlRef &>(GuiDialog::controller());
-}
-
-
-void GuiRefDialog::changed_adaptor()
+void GuiRef::changed_adaptor()
 {
        changed();
 }
 
 
-void GuiRefDialog::gotoClicked()
+void GuiRef::gotoClicked()
 {
        gotoRef();
 }
 
-void GuiRefDialog::selectionChanged()
+void GuiRef::selectionChanged()
 {
-       if (controller().isBufferReadonly())
+       if (isBufferReadonly())
                return;
 
        QList<QListWidgetItem *> selections = refsLW->selectedItems();
@@ -119,7 +131,7 @@ void GuiRefDialog::selectionChanged()
 }
 
 
-void GuiRefDialog::refHighlighted(QListWidgetItem * sel)
+void GuiRef::refHighlighted(QListWidgetItem * sel)
 {
        if (controller().isBufferReadonly())
                return;
@@ -142,9 +154,9 @@ void GuiRefDialog::refHighlighted(QListWidgetItem * sel)
 }
 
 
-void GuiRefDialog::refSelected(QListWidgetItem * sel)
+void GuiRef::refSelected(QListWidgetItem * sel)
 {
-       if (controller().isBufferReadonly())
+       if (isBufferReadonly())
                return;
 
 /*     int const cur_item = refsLW->currentRow();
@@ -159,27 +171,27 @@ void GuiRefDialog::refSelected(QListWidgetItem * sel)
 }
 
 
-void GuiRefDialog::sortToggled(bool on)
+void GuiRef::sortToggled(bool on)
 {
        sort_ = on;
        redoRefs();
 }
 
 
-void GuiRefDialog::updateClicked()
+void GuiRef::updateClicked()
 {
        updateRefs();
 }
 
 
-void GuiRefDialog::reset_dialog()
+void GuiRef::reset_dialog()
 {
        at_ref_ = false;
        setGotoRef();
 }
 
 
-void GuiRefDialog::closeEvent(QCloseEvent * e)
+void GuiRef::closeEvent(QCloseEvent * e)
 {
        slotClose();
        reset_dialog();
@@ -187,23 +199,21 @@ void GuiRefDialog::closeEvent(QCloseEvent * e)
 }
 
 
-void GuiRefDialog::updateContents()
+void GuiRef::updateContents()
 {
-       InsetCommandParams const & params = controller().params();
-
        int orig_type = typeCO->currentIndex();
 
-       referenceED->setText(toqstr(params["reference"]));
+       referenceED->setText(toqstr(params_["reference"]));
 
-       nameED->setText(toqstr(params["name"]));
-       nameED->setReadOnly(!nameAllowed() && !controller().isBufferReadonly());
+       nameED->setText(toqstr(params_["name"]));
+       nameED->setReadOnly(!nameAllowed() && !isBufferReadonly());
 
        // restore type settings for new insets
-       if (params["reference"].empty())
+       if (params_["reference"].empty())
                typeCO->setCurrentIndex(orig_type);
        else
-               typeCO->setCurrentIndex(InsetRef::getType(params.getCmdName()));
-       typeCO->setEnabled(typeAllowed() && !controller().isBufferReadonly());
+               typeCO->setCurrentIndex(InsetRef::getType(params_.getCmdName()));
+       typeCO->setEnabled(typeAllowed() && !isBufferReadonly());
        if (!typeAllowed())
                typeCO->setCurrentIndex(0);
 
@@ -211,51 +221,50 @@ void GuiRefDialog::updateContents()
 
        // insert buffer list
        bufferCO->clear();
-       vector<string> const buffers = controller().getBufferList();
-       for (vector<string>::const_iterator it = buffers.begin();
-               it != buffers.end(); ++it) {
-               bufferCO->addItem(toqstr(*it));
+       vector<string> buffers = theBufferList().getFileNames();
+       for (vector<string>::iterator it = buffers.begin();
+            it != buffers.end(); ++it) {
+               bufferCO->addItem(toqstr(lyx::to_utf8(makeDisplayPath(*it))));
        }
+
        // restore the buffer combo setting for new insets
-       if (params["reference"].empty() && restored_buffer_ != -1
+       if (params_["reference"].empty() && restored_buffer_ != -1
        && restored_buffer_ < bufferCO->count())
                bufferCO->setCurrentIndex(restored_buffer_);
        else
-               bufferCO->setCurrentIndex(controller().getBufferNum());
+               bufferCO->setCurrentIndex(bufferNum());
 
        updateRefs();
        bc().setValid(false);
 }
 
 
-void GuiRefDialog::applyView()
+void GuiRef::applyView()
 {
-       InsetCommandParams & params = controller().params();
-
        last_reference_ = referenceED->text();
 
-       params.setCmdName(InsetRef::getName(typeCO->currentIndex()));
-       params["reference"] = qstring_to_ucs4(last_reference_);
-       params["name"] = qstring_to_ucs4(nameED->text());
+       params_.setCmdName(InsetRef::getName(typeCO->currentIndex()));
+       params_["reference"] = qstring_to_ucs4(last_reference_);
+       params_["name"] = qstring_to_ucs4(nameED->text());
 
        restored_buffer_ = bufferCO->currentIndex();
 }
 
 
-bool GuiRefDialog::nameAllowed()
+bool GuiRef::nameAllowed()
 {
-       KernelDocType const doc_type = controller().docType();
+       KernelDocType const doc_type = docType();
        return doc_type != LATEX && doc_type != LITERATE;
 }
 
 
-bool GuiRefDialog::typeAllowed()
+bool GuiRef::typeAllowed()
 {
-       return controller().docType() != DOCBOOK;
+       return docType() != DOCBOOK;
 }
 
 
-void GuiRefDialog::setGoBack()
+void GuiRef::setGoBack()
 {
        gotoPB->setText(qt_("&Go Back"));
        gotoPB->setToolTip("");
@@ -263,7 +272,7 @@ void GuiRefDialog::setGoBack()
 }
 
 
-void GuiRefDialog::setGotoRef()
+void GuiRef::setGotoRef()
 {
        gotoPB->setText(qt_("&Go to Label"));
        gotoPB->setToolTip("");
@@ -271,24 +280,24 @@ void GuiRefDialog::setGotoRef()
 }
 
 
-void GuiRefDialog::gotoRef()
+void GuiRef::gotoRef()
 {
        string ref = fromqstr(referenceED->text());
 
        if (at_ref_) {
                // go back
                setGotoRef();
-               controller().gotoBookmark();
+               gotoBookmark();
        } else {
                // go to the ref
                setGoBack();
-               controller().gotoRef(ref);
+               gotoRef(ref);
        }
        at_ref_ = !at_ref_;
 }
 
 
-void GuiRefDialog::redoRefs()
+void GuiRef::redoRefs()
 {
        // Prevent these widgets from emitting any signals whilst
        // we modify their state.
@@ -341,11 +350,12 @@ void GuiRefDialog::redoRefs()
 }
 
 
-void GuiRefDialog::updateRefs()
+void GuiRef::updateRefs()
 {
        refs_.clear();
-       string const name = controller().getBufferName(bufferCO->currentIndex());
-       refs_ = controller().getLabelList(name);
+       string const name = theBufferList().getFileNames()[bufferCO->currentIndex()];
+       Buffer const * buf = theBufferList().getBuffer(makeAbsPath(name).absFilename());
+       buf->getLabelList(refs_);
        sortCB->setEnabled(!refs_.empty());
        refsLW->setEnabled(!refs_.empty());
        gotoPB->setEnabled(!refs_.empty());
@@ -353,11 +363,62 @@ void GuiRefDialog::updateRefs()
 }
 
 
-bool GuiRefDialog::isValid()
+bool GuiRef::isValid()
 {
        return !referenceED->text().isEmpty();
 }
 
+
+void GuiRef::gotoRef(string const & ref)
+{
+       dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
+       dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
+}
+
+
+void GuiRef::gotoBookmark()
+{
+       dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
+}
+
+
+int GuiRef::bufferNum() const
+{
+       vector<string> buffers = theBufferList().getFileNames();
+       string const name = buffer().fileName();
+       vector<string>::const_iterator cit =
+               std::find(buffers.begin(), buffers.end(), name);
+       if (cit == buffers.end())
+               return 0;
+       return int(cit - buffers.begin());
+}
+
+
+bool GuiRef::initialiseParams(string const & data)
+{
+       // The name passed with LFUN_INSET_APPLY is also the name
+       // used to identify the mailer.
+       InsetCommandMailer::string2params(lfun_name_, data, params_);
+       return true;
+}
+
+
+void GuiRef::clearParams()
+{
+       params_.clear();
+}
+
+
+void GuiRef::dispatchParams()
+{
+       string const lfun = InsetCommandMailer::params2string(lfun_name_, params_);
+       dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+Dialog * createGuiRef(LyXView & lv) { return new GuiRef(lv); }
+
+
 } // namespace frontend
 } // namespace lyx
 
index 6c0faae500494effa2ca7df7186812e1cbceb4f8..3578985f7ba11b310460bd61bbac700cbc6aa836 100644 (file)
@@ -13,8 +13,9 @@
 #define GUIREF_H
 
 #include "GuiDialog.h"
-#include "ControlRef.h"
+#include "Dialog.h"
 #include "ui_RefUi.h"
+#include "insets/InsetCommandParams.h"
 
 #include <vector>
 
@@ -23,12 +24,12 @@ class QListWidgetItem;
 namespace lyx {
 namespace frontend {
 
-class GuiRefDialog : public GuiDialog, public Ui::RefUi
+class GuiRef : public GuiDialog, public Ui::RefUi, public Controller
 {
        Q_OBJECT
 
 public:
-       GuiRefDialog(LyXView & lv);
+       GuiRef(LyXView & lv);
 
 private Q_SLOTS:
        void changed_adaptor();
@@ -41,10 +42,29 @@ private Q_SLOTS:
        void reset_dialog();
 
 private:
+       ///
+       bool initialiseParams(std::string const & data);
+       /// clean-up on hide.
+       void clearParams();
+       /// clean-up on hide.
+       void dispatchParams();
+       ///
+       bool isBufferDependent() const { return true; }
+
+       /** disconnect from the inset when the Apply button is pressed.
+        Allows easy insertion of multiple references. */
+       bool disconnectOnApply() const { return true; }
+       ///
+       void gotoRef(std::string const &);
+       ///
+       void gotoBookmark();
+       ///
+       int bufferNum() const;
+
        ///
        void closeEvent(QCloseEvent * e);
        /// parent controller
-       ControlRef & controller();
+       Controller & controller() { return *static_cast<Controller*>(this); }
        ///
        bool isValid();
        /// apply changes
@@ -77,6 +97,9 @@ private:
        int restored_buffer_;
        /// the references
        std::vector<docstring> refs_;
+
+       ///
+       InsetCommandParams params_;
 };
 
 } // namespace frontend