* 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 "funcrequest.h"
-#include "gettext.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::vector;
using std::string;
ControlToc::ControlToc(Dialog & d)
: ControlCommand(d, "tableofcontents", "toc")
-{}
+{
+}
+
+
+TocList const & ControlToc::tocs() const
+{
+ return kernel().buffer().tocBackend().tocs();
+}
+
+
+bool ControlToc::initialiseParams(string const & data)
+{
+ 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));
+ }
+
+ 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;
+ }
+ }
+ update();
+ return true;
+}
-void ControlToc::goTo(toc::TocItem const & item)
+void ControlToc::goTo(TocItem const & item)
{
- item.goTo(kernel().lyxview());
+ string const tmp = convert<string>(item.id());
+ kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
}
-bool ControlToc::canOutline(string const & type)
+bool ControlToc::canOutline(size_t type) const
{
- return type == "TOC";
+ BOOST_ASSERT(type >= 0 && type < int(types_.size()));
+ return types_[type] == "tableofcontents";
}
}
-vector<string> const & ControlToc::getTypes() const
+void ControlToc::updateBackend()
{
- return toc::getTypes(kernel().buffer());
+ kernel().buffer().tocBackend().update();
}
-toc::TocIterator const ControlToc::getCurrentTocItem(
- string const & type) const
+TocIterator const ControlToc::getCurrentTocItem(size_t type) const
{
BOOST_ASSERT(kernel().bufferview());
-
- return toc::getCurrentTocItem(kernel().buffer(),
- kernel().bufferview()->cursor(), type);
+ ParConstIterator it(kernel().bufferview()->cursor());
+ return kernel().buffer().tocBackend().item(types_[type], it);
}
-string const ControlToc::getGuiName(string const & type) const
+docstring const ControlToc::getGuiName(string const & type) const
{
- if (type == "TOC")
- return lyx::to_utf8(_("Table of Contents"));
- else
- return lyx::to_utf8(_(toc::getGuiName(type, kernel().buffer())));
-}
-
+ if (type == "tableofcontents")
+ return _("Table of Contents");
-toc::Toc const empty_list;
-
-toc::Toc const & ControlToc::getContents(string const & type) const
-{
- // This shouldn't be possible...
- if (!kernel().isBufferAvailable()) {
- return empty_list;
- }
-
- return toc::getToc(kernel().buffer(), type);
+ FloatList const & floats =
+ kernel().buffer().params().getLyXTextClass().floats();
+ if (floats.typeExist(type))
+ return from_utf8(floats.getType(type).name());
+ else
+ return _(type);
}
} // namespace frontend