+++ /dev/null
-/**
- * \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
+++ /dev/null
-// -*- 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
ControlPrefs.cpp \
ControlPrint.cpp \
ControlSearch.cpp \
- ControlToc.cpp \
frontend_helpers.cpp
HEADERFILES = \
ControlPrefs.h \
ControlPrint.h \
ControlSearch.h \
- ControlToc.h \
frontend_helpers.h
if MONOLITHIC_CONTROLLERS
#include "GuiPrint.h"
#include "GuiSearch.h"
#include "GuiShowFile.h"
-#include "GuiToc.h"
#include "GuiView.h"
#include "TocWidget.h"
#include "GuiURL.h"
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);
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")
*
* \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);
}
}
-QModelIndex const GuiToc::getCurrentIndex(int type) const
+QModelIndex GuiToc::currentIndex(int type) const
{
if (type < 0)
return QModelIndex();
if(!canOutline(type))
return QModelIndex();
- return toc_models_[type]->modelIndex(getCurrentTocItem(type));
+ return toc_models_[type]->modelIndex(currentTocItem(type));
}
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
}
*
* \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
///
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);
///
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
void TocWidget::updateView()
{
LYXERR(Debug::GUI) << "In TocWidget::updateView()" << endl;
- select(form_.getCurrentIndex(typeCO->currentIndex()));
+ select(form_.currentIndex(typeCO->currentIndex()));
}
LYXERR(Debug::GUI) << "In TocWidget::updateGui()" << endl;
- select(form_.getCurrentIndex(typeCO->currentIndex()));
+ select(form_.currentIndex(typeCO->currentIndex()));
if (toc_model) {
LYXERR(Debug::GUI)