-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 2001 The LyX Team.
+/**
+ * \file ControlToc.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ======================================================
+ * \author Angus Leeming
+ * \author Abdelrazak Younes
*
- * \file ControlToc.C
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * Full author contact details are available in file CREDITS.
*/
-#include <config.h>
+#include <sstream>
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include <config.h>
-#include "ViewBase.h"
-#include "ButtonControllerBase.h"
#include "ControlToc.h"
+
#include "buffer.h"
-#include "Dialogs.h"
-#include "LyXView.h"
-#include "lyxfunc.h"
-#include "support/lstrings.h" // tostr
+#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::vector;
-using SigC::slot;
+using std::string;
+
-ControlToc::ControlToc(LyXView & lv, Dialogs & d)
- : ControlCommand(lv, d, LFUN_TOC_INSERT)
+class Buffer;
+
+namespace lyx {
+namespace frontend {
+
+
+ControlToc::ControlToc(Dialog & d)
+ : ControlCommand(d, "tableofcontents", "toc")
{
- d_.showTOC.connect(slot(this, &ControlToc::showInset));
- d_.createTOC.connect(slot(this, &ControlToc::createInset));
}
-void ControlToc::Goto(int const & id) const
+TocList const & ControlToc::tocs() const
{
- string const tmp = tostr(id);
- lv_.getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);
+ return kernel().buffer().tocBackend().tocs();
}
-vector<string> const ControlToc::getTypes() const
+bool ControlToc::initialiseParams(string const & data)
{
- vector<string> types;
+ if (!ControlCommand::initialiseParams(data))
+ return false;
+
+ types_.clear();
+ type_names_.clear();
+ TocList const & tocs = kernel().buffer().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));
+ }
- Buffer::Lists const tmp = lv_.view()->buffer()->getLists();
+ 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;
+ }
+ }
- Buffer::Lists::const_iterator cit = tmp.begin();
- Buffer::Lists::const_iterator end = tmp.end();
+ update();
+ return true;
+}
+
+void ControlToc::goTo(TocItem const & item)
+{
+ string const tmp = convert<string>(item.id());
+ kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
+}
- for (; cit != end; ++cit) {
- types.push_back(cit->first);
- }
- return types;
+bool ControlToc::canOutline(size_t type) const
+{
+ BOOST_ASSERT(type >= 0 && type < int(types_.size()));
+ return types_[type] == "tableofcontents";
}
-Buffer::SingleList const ControlToc::getContents(string const & type) const
+void ControlToc::outlineUp()
{
- Buffer::SingleList contents;
-
- Buffer::TocItem noContent(0, 0, string());
-
- // This shouldn't be possible...
- if (!lv_.view()->available()) {
- noContent.str = _("*** No Document ***");
- contents.push_back(noContent);
- return contents;
- }
+ kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
+}
- Buffer::Lists tmp = lv_.view()->buffer()->getLists();
- Buffer::Lists::iterator it = tmp.find(type);
+void ControlToc::outlineDown()
+{
+ kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
+}
- if (it == tmp.end()) {
- noContent.str = _("*** No Lists ***");
- contents.push_back(noContent);
- return contents;
- }
- return it->second;
+void ControlToc::outlineIn()
+{
+ kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
}
-namespace toc
+void ControlToc::outlineOut()
{
+ kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
+}
+
-string getType(string const & cmdName)
+void ControlToc::updateBackend()
{
- string type;
+ kernel().buffer().tocBackend().update();
+}
- // It would be nice to have a map to extract this info.
- // Does one already exist, Lars?
- if (cmdName == "tableofcontents" )
- type = "TOC";
- else if (cmdName == "listofalgorithms" )
- type = "algorithm";
+TocIterator const ControlToc::getCurrentTocItem(size_t type) const
+{
+ BOOST_ASSERT(kernel().bufferview());
+ ParConstIterator it(kernel().bufferview()->cursor());
+ return kernel().buffer().tocBackend().item(types_[type], it);
+}
- else if (cmdName == "listoffigures" )
- type = "figure";
- else
- type = "table";
+docstring const ControlToc::getGuiName(string const & type) const
+{
+ if (type == "tableofcontents")
+ return _("Table of Contents");
- return type;
+ FloatList const & floats =
+ kernel().buffer().params().getLyXTextClass().floats();
+ if (floats.typeExist(type))
+ return from_utf8(floats.getType(type).name());
+ else
+ return _(type);
}
-
-} // namespace toc
+
+} // namespace frontend
+} // namespace lyx