+/**
+ * \file insettoc.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
#include "gettext.h"
#include "insettoc.h"
+#include "funcrequest.h"
#include "BufferView.h"
-#include "LyXView.h"
+#include "frontends/LyXView.h"
#include "frontends/Dialogs.h"
#include "debug.h"
-#include "buffer.h"
+#include "toc.h"
+using std::vector;
using std::ostream;
-using std::endl;
-string const InsetTOC::getScreenLabel() const
+
+InsetTOC::InsetTOC(InsetCommandParams const & p)
+ : InsetCommand(p)
+{}
+
+
+InsetTOC::~InsetTOC()
{
- string cmdname( getCmdName() );
- if (cmdname == "tableofcontents" )
+ InsetCommandMailer mailer("toc", *this);
+ mailer.hideDialog();
+}
+
+
+string const InsetTOC::getScreenLabel(Buffer const &) const
+{
+ string const cmdname(getCmdName());
+
+ if (cmdname == "tableofcontents")
return _("Table of Contents");
- else if (cmdname == "listofalgorithms" )
- return _("List of Algorithms");
- else if (cmdname == "listoffigures" )
- return _("List of Figures");
- else
- return _("List of Tables");
+ return _("Unknown toc list");
+}
+
+
+InsetOld::Code InsetTOC::lyxCode() const
+{
+ string const cmdname(getCmdName());
+ if (cmdname == "tableofcontents")
+ return InsetOld::TOC_CODE;
+ return InsetOld::NO_CODE;
}
-Inset::Code InsetTOC::LyxCode() const
+void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
{
- string cmdname( getCmdName() );
- if (cmdname == "tableofcontents" )
- return Inset::TOC_CODE;
- else if (cmdname == "listofalgorithms" )
- return Inset::LOA_CODE;
- else if (cmdname == "listoffigures" )
- return Inset::LOF_CODE;
- else
- return Inset::LOT_CODE;
+ InsetCommand::metrics(mi, dim);
+ center_indent_ = (mi.base.textwidth - dim.wid) / 2;
+ dim.wid = mi.base.textwidth;
+ dim_ = dim;
}
-void InsetTOC::Edit(BufferView * bv, int, int, unsigned int)
+void InsetTOC::draw(PainterInfo & pi, int x, int y) const
{
- bv->owner()->getDialogs()->showTOC( this );
+ InsetCommand::draw(pi, x + center_indent_, y);
}
-int InsetTOC::Ascii(Buffer const * buffer, ostream & os, int) const
+dispatch_result InsetTOC::localDispatch(FuncRequest const & cmd)
{
- os << getScreenLabel() << endl << endl;
-
-#if 0
- Buffer::TocType type;
- string cmdname = getCmdName();
- if (cmdname == "tableofcontents" )
- type = Buffer::TOC_TOC;
- else if (cmdname == "listofalgorithms" )
- type = Buffer::TOC_LOA;
- else if (cmdname == "listoffigures" )
- type = Buffer::TOC_LOF;
- else
- type = Buffer::TOC_LOT;
-
- vector<vector<Buffer::TocItem> > const toc_list =
- buffer->getTocList();
- vector<Buffer::TocItem> const & toc = toc_list[type];
- for (vector<Buffer::TocItem>::const_iterator it = toc.begin();
- it != toc.end(); ++it)
- os << string(4 * it->depth, ' ') << it->str << endl;
-#else
-#warning Fix Me! (Lgb)
- string type;
- string cmdname = getCmdName();
- if (cmdname == "tableofcontents" )
- type = "TOC";
- else if (cmdname == "listofalgorithms" )
- type = "LOA";
- else if (cmdname == "listoffigures" )
- type = "LOF";
- else
- type = "LOT";
-
- map<string, vector<Buffer::TocItem> > const toc_list =
- buffer->getTocList();
- map<string, vector<Buffer::TocItem> >::const_iterator cit =
- toc_list.find(type);
- if (cit != toc_list.end()) {
- vector<Buffer::TocItem>::const_iterator ccit =
- cit->second.begin();
- vector<Buffer::TocItem>::const_iterator end =
- cit->second.end();
- for (; ccit != end; ++ccit)
- os << string(4 * ccit->depth, ' ')
- << ccit->str << endl;
+ switch (cmd.action) {
+ case LFUN_INSET_EDIT:
+ InsetCommandMailer("toc", *this).showDialog(cmd.view());
+ return DISPATCHED;
+ default:
+ return InsetCommand::localDispatch(cmd);
}
-#endif
- os << endl;
+}
+
+
+int InsetTOC::ascii(Buffer const & buffer, ostream & os, int) const
+{
+ os << getScreenLabel(buffer) << "\n\n";
+
+ lyx::toc::asciiTocList(lyx::toc::getType(getCmdName()), buffer, os);
+
+ os << "\n";
return 0;
}
-int InsetTOC::Linuxdoc(Buffer const *, ostream & os) const
+int InsetTOC::linuxdoc(Buffer const &, ostream & os) const
{
- if (getCmdName() == "tableofcontents" )
+ if (getCmdName() == "tableofcontents")
os << "<toc>";
return 0;
}
-int InsetTOC::DocBook(Buffer const *, ostream & os) const
+int InsetTOC::docbook(Buffer const &, ostream & os, bool) const
{
- if (getCmdName() == "tableofcontents" )
+ if (getCmdName() == "tableofcontents")
os << "<toc></toc>";
return 0;
}