From e117f67786032e6951ba08bb8a1e69cc2f89bfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 6 Oct 2007 20:35:44 +0000 Subject: [PATCH] next one git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20800 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ControlToc.cpp | 145 --------------------- src/frontends/controllers/ControlToc.h | 78 ----------- src/frontends/controllers/Makefile.am | 2 - src/frontends/qt4/Dialogs.cpp | 13 +- src/frontends/qt4/GuiToc.cpp | 158 +++++++++++++++++++---- src/frontends/qt4/GuiToc.h | 49 ++++++- src/frontends/qt4/TocWidget.cpp | 4 +- 7 files changed, 183 insertions(+), 266 deletions(-) delete mode 100644 src/frontends/controllers/ControlToc.cpp delete mode 100644 src/frontends/controllers/ControlToc.h diff --git a/src/frontends/controllers/ControlToc.cpp b/src/frontends/controllers/ControlToc.cpp deleted file mode 100644 index a04386578f..0000000000 --- a/src/frontends/controllers/ControlToc.cpp +++ /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 - -#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(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 index 36d306179f..0000000000 --- a/src/frontends/controllers/ControlToc.h +++ /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 - -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 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 types_; - std::vector 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 diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 4772778136..700d379976 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -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 diff --git a/src/frontends/qt4/Dialogs.cpp b/src/frontends/qt4/Dialogs.cpp index ed41742460..477ebed208 100644 --- a/src/frontends/qt4/Dialogs.cpp +++ b/src/frontends/qt4/Dialogs.cpp @@ -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(guiview, name, - Qt::RightDockWidgetArea, Qt::Drawer); -#else - return new DockView(guiview, name); -#endif - } + if (name == "toc") + return createGuiToc(lyxview_); if (name == "url") return new GuiURLDialog(lyxview_); if (name == "vspace") diff --git a/src/frontends/qt4/GuiToc.cpp b/src/frontends/qt4/GuiToc.cpp index 5fd6ef47f5..cf1d54362a 100644 --- a/src/frontends/qt4/GuiToc.cpp +++ b/src/frontends/qt4/GuiToc.cpp @@ -5,6 +5,7 @@ * * \author John Levon * \author Abdelrazak Younes + * \author Angus Leeming * * Full author contact details are available in file CREDITS. */ @@ -12,34 +13,40 @@ #include #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 using std::endl; +using std::string; + namespace lyx { namespace frontend { - GuiToc::GuiToc(Dialog & dialog) - : ControlToc(dialog) + : ControlCommand(dialog, "toc") { } -bool GuiToc::canOutline(int type) const -{ - if (type < 0) - return false; - return ControlToc::canOutline(type); -} - - int GuiToc::getTocDepth(int type) { if (type < 0) @@ -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,17 +106,8 @@ void GuiToc::goTo(int type, QModelIndex const & index) LYXERR(Debug::GUI) << "GuiToc::goTo " << to_utf8(it->str()) << endl; - ControlToc::goTo(*it); -} - - -bool GuiToc::initialiseParams(std::string const & data) -{ - if (!ControlToc::initialiseParams(data)) - return false; - updateView(); - modelReset(); - return true; + string const tmp = convert(it->id()); + lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp)); } @@ -123,6 +121,120 @@ void GuiToc::updateView() } +TocList const & GuiToc::tocs() const +{ + return buffer().getMasterBuffer()->tocBackend().tocs(); +} + + +bool GuiToc::initialiseParams(string const & 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; +} + + +bool GuiToc::canOutline(int type) const +{ + 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(lv); +#ifdef Q_WS_MACX + // On Mac show as a drawer at the right + return new DockView(guiview, "toc", + Qt::RightDockWidgetArea, Qt::Drawer); +#else + return new DockView(guiview, "toc"); +#endif +} + + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiToc.h b/src/frontends/qt4/GuiToc.h index ac40c2fdae..81a9a65b53 100644 --- a/src/frontends/qt4/GuiToc.h +++ b/src/frontends/qt4/GuiToc.h @@ -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. @@ -14,18 +15,21 @@ #ifndef GUITOC_H #define GUITOC_H -#include "ControlToc.h" +#include "ControlCommand.h" +#include "TocBackend.h" #include #include #include +#include + 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); + /// + 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 toc_models_; + + /// + TocList const & tocs() const; + + /// Return the list of types available + std::vector 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 types_; + std::vector 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 diff --git a/src/frontends/qt4/TocWidget.cpp b/src/frontends/qt4/TocWidget.cpp index 63c6fe4d08..faa8b035bd 100644 --- a/src/frontends/qt4/TocWidget.cpp +++ b/src/frontends/qt4/TocWidget.cpp @@ -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)