]> git.lyx.org Git - features.git/commitdiff
next one
authorAndré Pönitz <poenitz@gmx.net>
Sat, 6 Oct 2007 20:35:44 +0000 (20:35 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sat, 6 Oct 2007 20:35:44 +0000 (20:35 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20800 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ControlToc.cpp [deleted file]
src/frontends/controllers/ControlToc.h [deleted file]
src/frontends/controllers/Makefile.am
src/frontends/qt4/Dialogs.cpp
src/frontends/qt4/GuiToc.cpp
src/frontends/qt4/GuiToc.h
src/frontends/qt4/TocWidget.cpp

diff --git a/src/frontends/controllers/ControlToc.cpp b/src/frontends/controllers/ControlToc.cpp
deleted file mode 100644 (file)
index a043865..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * \file ControlToc.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "ControlToc.h"
-
-#include "Buffer.h"
-#include "BufferView.h"
-#include "BufferParams.h"
-#include "debug.h"
-#include "FloatList.h"
-#include "FuncRequest.h"
-#include "gettext.h"
-
-#include "frontends/LyXView.h"
-
-#include "support/convert.h"
-
-using std::string;
-
-
-namespace lyx {
-namespace frontend {
-
-ControlToc::ControlToc(Dialog & d)
-       : ControlCommand(d, "toc")
-{
-}
-
-
-TocList const & ControlToc::tocs() const
-{
-       return buffer().getMasterBuffer()->tocBackend().tocs();
-}
-
-
-bool ControlToc::initialiseParams(string const & data)
-{
-       if (!ControlCommand::initialiseParams(data))
-               return false;
-
-       types_.clear();
-       type_names_.clear();
-       TocList const & tocs = buffer().getMasterBuffer()->
-               tocBackend().tocs();
-       TocList::const_iterator it = tocs.begin();
-       TocList::const_iterator end = tocs.end();
-       for (; it != end; ++it) {
-               types_.push_back(it->first);
-               type_names_.push_back(getGuiName(it->first));
-       }
-
-       string selected_type ;
-       if(params()["type"].empty()) //Then plain toc...
-               selected_type = params().getCmdName();
-       else
-               selected_type = to_ascii(params()["type"]);
-       selected_type_ = -1;
-       for (size_t i = 0;  i != types_.size(); ++i) {
-               if (selected_type == types_[i]) {
-                       selected_type_ = i;
-                       break;
-               }
-       }
-
-       return true;
-}
-
-
-void ControlToc::goTo(TocItem const & item)
-{
-       string const tmp = convert<string>(item.id());
-       lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
-}
-
-
-bool ControlToc::canOutline(size_t type) const
-{
-       return types_[type] == "tableofcontents";
-}
-
-
-void ControlToc::outlineUp()
-{
-       dispatch(FuncRequest(LFUN_OUTLINE_UP));
-}
-
-
-void ControlToc::outlineDown()
-{
-       dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
-}
-
-
-void ControlToc::outlineIn()
-{
-       dispatch(FuncRequest(LFUN_OUTLINE_IN));
-}
-
-
-void ControlToc::outlineOut()
-{
-       dispatch(FuncRequest(LFUN_OUTLINE_OUT));
-}
-
-
-void ControlToc::updateBackend()
-{
-       buffer().getMasterBuffer()->tocBackend().update();
-       buffer().structureChanged();
-}
-
-
-TocIterator const ControlToc::getCurrentTocItem(size_t type) const
-{
-       BOOST_ASSERT(bufferview());
-       ParConstIterator it(bufferview()->cursor());
-       Buffer const * master = buffer().getMasterBuffer();
-       return master->tocBackend().item(types_[type], it);
-}
-
-
-docstring const ControlToc::getGuiName(string const & type) const
-{
-       if (type == "tableofcontents")
-               return _("Table of Contents");
-
-       FloatList const & floats = buffer().params().getTextClass().floats();
-       if (floats.typeExist(type))
-               return _(floats.getType(type).listName());
-       else
-               return _(type);
-}
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/controllers/ControlToc.h b/src/frontends/controllers/ControlToc.h
deleted file mode 100644 (file)
index 36d3061..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-// -*- C++ -*-
-/**
- * \file ControlToc.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- * \author Abdelrazak Younes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef CONTROLTOC_H
-#define CONTROLTOC_H
-
-
-#include "ControlCommand.h"
-#include "TocBackend.h"
-
-#include <vector>
-
-namespace lyx {
-namespace frontend {
-
-/** A controller for TOC dialogs.
- */
-class ControlToc : public ControlCommand {
-public:
-       ///
-       ControlToc(Dialog &);
-       ///
-       virtual ~ControlToc() {}
-
-       /// \c ControlCommand inherited method.
-       virtual bool initialiseParams(std::string const & data);
-
-       ///
-       TocList const & tocs() const;
-
-       /// Goto this paragraph id
-       void goTo(TocItem const &);
-
-       /// Return the list of types available
-       std::vector<docstring> const & typeNames() const
-       { return type_names_; }
-
-       ///
-       int selectedType() { return selected_type_; }
-
-       /// Return the first TocItem before the cursor
-       TocIterator const getCurrentTocItem(size_t type) const;
-
-       /// Apply the selected outlining operation
-       void outlineUp();
-       ///
-       void outlineDown();
-       ///
-       void outlineIn();
-       ///
-       void outlineOut();
-       /// Test if outlining operation is possible
-       bool canOutline(size_t type) const;
-       ///
-       void updateBackend();
-
-private:
-       std::vector<std::string> types_;
-       std::vector<docstring> type_names_;
-       int selected_type_;
-
-       /// Return the guiname from a given cmdName of the TOC param
-       docstring const getGuiName(std::string const & type) const;
-};
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // CONTROLTOC_H
index 4772778136e3295426e9d497f9f142025a4bee24..700d379976fd68bbfc47e90fe20048c8ac56669d 100644 (file)
@@ -19,7 +19,6 @@ SOURCEFILES = \
        ControlPrefs.cpp \
        ControlPrint.cpp \
        ControlSearch.cpp \
-       ControlToc.cpp \
        frontend_helpers.cpp 
 
 HEADERFILES = \
@@ -34,7 +33,6 @@ HEADERFILES = \
        ControlPrefs.h \
        ControlPrint.h \
        ControlSearch.h \
-       ControlToc.h \
        frontend_helpers.h
 
 if MONOLITHIC_CONTROLLERS
index ed417424603af7655073125f7dc261a7d1e22dcc..477ebed208754683069639be72b53b7e1c9d1fb8 100644 (file)
@@ -29,7 +29,6 @@
 #include "GuiPrint.h"
 #include "GuiSearch.h"
 #include "GuiShowFile.h"
-#include "GuiToc.h"
 #include "GuiView.h"
 #include "TocWidget.h"
 #include "GuiURL.h"
@@ -116,6 +115,7 @@ Dialog * createGuiSpellchecker(LyXView & lv);
 Dialog * createGuiTabularCreate(LyXView & lv);
 Dialog * createGuiTabular(LyXView & lv);
 Dialog * createGuiTexInfo(LyXView & lv);
+Dialog * createGuiToc(LyXView & lv);
 Dialog * createGuiThesaurus(LyXView & lv);
 Dialog * createGuiURL(LyXView & lv);
 Dialog * createGuiVSpace(LyXView & lv);
@@ -216,15 +216,8 @@ Dialog * Dialogs::build(string const & name)
        if (name == "thesaurus")
                return createGuiThesaurus(lyxview_);
 #endif
-       if (name == "toc") {
-#ifdef Q_WS_MACX
-               // On Mac show as a drawer at the right
-               return new DockView<GuiToc, TocWidget>(guiview, name,
-                       Qt::RightDockWidgetArea, Qt::Drawer);
-#else
-               return new DockView<GuiToc, TocWidget>(guiview, name);
-#endif
-       }
+       if (name == "toc")
+               return createGuiToc(lyxview_);
        if (name == "url")
                return new GuiURLDialog(lyxview_);
        if (name == "vspace")
index 5fd6ef47f5c0d8b8a8e70414a12cc92c4e6e48ac..cf1d54362ab4e83aea8dd2b6ad3647e449a81d14 100644 (file)
@@ -5,6 +5,7 @@
  *
  * \author John Levon
  * \author Abdelrazak Younes
+ * \author Angus Leeming
  *
  * Full author contact details are available in file CREDITS.
  */
 #include <config.h>
 
 #include "GuiToc.h"
+#include "GuiView.h"
+#include "DockView.h"
+#include "TocWidget.h"
 
 #include "TocModel.h"
 #include "qt_helpers.h"
 
+#include "Buffer.h"
+#include "BufferView.h"
+#include "BufferParams.h"
 #include "debug.h"
+#include "FloatList.h"
+#include "FuncRequest.h"
+#include "gettext.h"
+
+#include "frontends/LyXView.h"
+
+#include "support/convert.h"
 
 #include <algorithm>
 
 using std::endl;
+using std::string;
+
 
 namespace lyx {
 namespace frontend {
 
-
 GuiToc::GuiToc(Dialog & dialog)
-       : ControlToc(dialog)
-{
-}
-
-
-bool GuiToc::canOutline(int type) const
+       : ControlCommand(dialog, "toc")
 {
-       if (type < 0)
-               return false;
-       return ControlToc::canOutline(type);
 }
 
 
@@ -68,7 +75,7 @@ QStandardItemModel * GuiToc::tocModel(int type)
 }
 
 
-QModelIndex const GuiToc::getCurrentIndex(int type) const
+QModelIndex GuiToc::currentIndex(int type) const
 {
        if (type < 0)
                return QModelIndex();
@@ -79,7 +86,7 @@ QModelIndex const GuiToc::getCurrentIndex(int type) const
        if(!canOutline(type))
                return QModelIndex();
 
-       return toc_models_[type]->modelIndex(getCurrentTocItem(type));
+       return toc_models_[type]->modelIndex(currentTocItem(type));
 }
 
 
@@ -99,27 +106,132 @@ void GuiToc::goTo(int type, QModelIndex const & index)
 
        LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl;
 
-       ControlToc::goTo(*it);
+       string const tmp = convert<string>(it->id());
+       lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
+}
+
+
+void GuiToc::updateView()
+{
+       toc_models_.clear();
+       TocList::const_iterator it = tocs().begin();
+       TocList::const_iterator end = tocs().end();
+       for (; it != end; ++it)
+               toc_models_.push_back(new TocModel(it->second));
+}
+
+
+TocList const & GuiToc::tocs() const
+{
+       return buffer().getMasterBuffer()->tocBackend().tocs();
 }
 
 
-bool GuiToc::initialiseParams(std::string const & data)
+bool GuiToc::initialiseParams(string const & data)
 {
-       if (!ControlToc::initialiseParams(data))
+       if (!ControlCommand::initialiseParams(data))
                return false;
+
        updateView();
        modelReset();
+
+       types_.clear();
+       type_names_.clear();
+       TocList const & tocs = buffer().getMasterBuffer()->
+               tocBackend().tocs();
+       TocList::const_iterator it = tocs.begin();
+       TocList::const_iterator end = tocs.end();
+       for (; it != end; ++it) {
+               types_.push_back(it->first);
+               type_names_.push_back(guiName(it->first));
+       }
+
+       string selected_type ;
+       if(params()["type"].empty()) //Then plain toc...
+               selected_type = params().getCmdName();
+       else
+               selected_type = to_ascii(params()["type"]);
+       selected_type_ = -1;
+       for (size_t i = 0;  i != types_.size(); ++i) {
+               if (selected_type == types_[i]) {
+                       selected_type_ = i;
+                       break;
+               }
+       }
+
        return true;
 }
 
 
-void GuiToc::updateView()
+bool GuiToc::canOutline(int type) const
 {
-       toc_models_.clear();
-       TocList::const_iterator it = tocs().begin();
-       TocList::const_iterator end = tocs().end();
-       for (; it != end; ++it)
-               toc_models_.push_back(new TocModel(it->second));
+       return types_[type] == "tableofcontents";
+}
+
+
+void GuiToc::outlineUp()
+{
+       dispatch(FuncRequest(LFUN_OUTLINE_UP));
+}
+
+
+void GuiToc::outlineDown()
+{
+       dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
+}
+
+
+void GuiToc::outlineIn()
+{
+       dispatch(FuncRequest(LFUN_OUTLINE_IN));
+}
+
+
+void GuiToc::outlineOut()
+{
+       dispatch(FuncRequest(LFUN_OUTLINE_OUT));
+}
+
+
+void GuiToc::updateBackend()
+{
+       buffer().getMasterBuffer()->tocBackend().update();
+       buffer().structureChanged();
+}
+
+
+TocIterator GuiToc::currentTocItem(int type) const
+{
+       BOOST_ASSERT(bufferview());
+       ParConstIterator it(bufferview()->cursor());
+       Buffer const * master = buffer().getMasterBuffer();
+       return master->tocBackend().item(types_[type], it);
+}
+
+
+docstring GuiToc::guiName(string const & type) const
+{
+       if (type == "tableofcontents")
+               return _("Table of Contents");
+
+       FloatList const & floats = buffer().params().getTextClass().floats();
+       if (floats.typeExist(type))
+               return _(floats.getType(type).listName());
+
+       return _(type);
+}
+
+
+Dialog * createGuiToc(LyXView & lv)
+{
+       GuiViewBase & guiview = static_cast<GuiViewBase &>(lv);
+#ifdef Q_WS_MACX
+       // On Mac show as a drawer at the right
+       return new DockView<GuiToc, TocWidget>(guiview, "toc",
+               Qt::RightDockWidgetArea, Qt::Drawer);
+#else
+       return new DockView<GuiToc, TocWidget>(guiview, "toc");
+#endif
 }
 
 
index ac40c2fdae8c3c3ba755ca426dc8e292d1b0718f..81a9a65b539b99e0c69ec822ad53d3175690590e 100644 (file)
@@ -6,6 +6,7 @@
  *
  * \author John Levon
  * \author Kalle Dalheimer
+ * \author Angus Leeming
  * \author Abdelrazak Younes
  *
  * Full author contact details are available in file CREDITS.
 #ifndef GUITOC_H
 #define GUITOC_H
 
-#include "ControlToc.h"
+#include "ControlCommand.h"
+#include "TocBackend.h"
 
 #include <QObject>
 #include <QStandardItemModel>
 #include <QStringListModel>
 
+#include <vector>
+
 namespace lyx {
 namespace frontend {
 
 class TocModel;
 
-class GuiToc : public QObject, public ControlToc
+class GuiToc : public QObject, public ControlCommand
 {
        Q_OBJECT
 
@@ -33,16 +37,16 @@ public:
        ///
        GuiToc(Dialog &);
 
-       /// \c ControlToc inherited method.
-       virtual bool initialiseParams(std::string const & data);
        ///
-       void updateView();
+       bool initialiseParams(std::string const & data);
        ///
+       void updateView();
+       /// Test if outlining operation is possible
        bool canOutline(int type) const;
 
        QStandardItemModel * tocModel(int type);
        ///
-       QModelIndex const getCurrentIndex(int type) const;
+       QModelIndex currentIndex(int type) const;
        ///
        void goTo(int type, QModelIndex const & index);
        ///
@@ -55,8 +59,41 @@ Q_SIGNALS:
        void modelReset();
 
 private:
+       friend class TocWidget;
        ///
        std::vector<TocModel *> toc_models_;
+
+       ///
+       TocList const & tocs() const;
+
+       /// Return the list of types available
+       std::vector<docstring> const & typeNames() const
+       { return type_names_; }
+
+       ///
+       int selectedType() { return selected_type_; }
+
+       /// Return the first TocItem before the cursor
+       TocIterator currentTocItem(int type) const;
+
+       /// Apply the selected outlining operation
+       void outlineUp();
+       ///
+       void outlineDown();
+       ///
+       void outlineIn();
+       ///
+       void outlineOut();
+       ///
+       void updateBackend();
+
+private:
+       std::vector<std::string> types_;
+       std::vector<docstring> type_names_;
+       int selected_type_;
+
+       /// Return the guiname from a given cmdName of the TOC param
+       docstring guiName(std::string const & type) const;
 };
 
 } // namespace frontend
index 63c6fe4d08b9adfeb77003cbf5f61d03c40c9f68..faa8b035bd867433ec3bb5adcd43bd890f016a50 100644 (file)
@@ -232,7 +232,7 @@ void TocWidget::enableControls(bool enable)
 void TocWidget::updateView()
 {
        LYXERR(Debug::GUI) << "In TocWidget::updateView()" << endl;
-       select(form_.getCurrentIndex(typeCO->currentIndex()));
+       select(form_.currentIndex(typeCO->currentIndex()));
 }
 
 
@@ -289,7 +289,7 @@ void TocWidget::setTocModel(size_t type)
 
        LYXERR(Debug::GUI) << "In TocWidget::updateGui()" << endl;
 
-       select(form_.getCurrentIndex(typeCO->currentIndex()));
+       select(form_.currentIndex(typeCO->currentIndex()));
 
        if (toc_model) {
                LYXERR(Debug::GUI)