]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetIndex.cpp
This should be the last of the commits refactoring the InsetLayout code.
[lyx.git] / src / insets / InsetIndex.cpp
index b43e1831160a643801f22042c2cc4be41ee83b29..e46e6cea8016168a921ddad2c26523f53ba7f0a1 100644 (file)
 
 #include "InsetIndex.h"
 
+#include "Buffer.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
-#include "gettext.h"
+#include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "MetricsInfo.h"
 #include "sgml.h"
+#include "TocBackend.h"
 
-#include "support/std_ostream.h"
+#include "support/gettext.h"
 
+#include <ostream>
 
-namespace lyx {
+using namespace std;
 
-using std::string;
-using std::ostream;
+namespace lyx {
 
 
-InsetIndex::InsetIndex(InsetCommandParams const & p)
-       : InsetCommand(p, "index")
+InsetIndex::InsetIndex(BufferParams const & bp)
+       : InsetCollapsable(bp)
 {}
 
 
-// InsetIndex::InsetIndex(InsetCommandParams const & p, bool)
-//     : InsetCommand(p, false)
-// {}
+InsetIndex::InsetIndex(InsetIndex const & in)
+       : InsetCollapsable(in)
+{}
 
 
-docstring const InsetIndex::getScreenLabel(Buffer const &) const
+int InsetIndex::docbook(Buffer const & buf, odocstream & os,
+                       OutputParams const & runparams) const
 {
-       return _("Idx");
+       os << "<indexterm><primary>";
+       int const i = InsetText::docbook(buf, os, runparams);
+       os << "</primary></indexterm>";
+       return i;
 }
 
 
-int InsetIndex::docbook(Buffer const &, odocstream & os,
-                       OutputParams const &) const
+Inset * InsetIndex::clone() const
 {
-       os << "<indexterm><primary>"
-           << sgml::escapeString(getParam("name"))
-          << "</primary></indexterm>";
-       return 0;
+       return new InsetIndex(*this);
 }
 
 
-InsetBase::Code InsetIndex::lyxCode() const
+void InsetIndex::write(Buffer const & buf, ostream & os) const
 {
-       return InsetBase::INDEX_CODE;
+       os << to_utf8(name()) << "\n";
+       InsetCollapsable::write(buf, os);
 }
 
 
+void InsetIndex::addToToc(Buffer const & buf,
+       ParConstIterator const & cpit) const
+{
+       ParConstIterator pit = cpit;
+       pit.push_back(*this);
+
+       Toc & toc = buf.tocBackend().toc("index");
+       docstring str;
+       str = getNewLabel(str);
+       toc.push_back(TocItem(pit, 0, str));
+}
+
 
 InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p)
        : InsetCommand(p, string())
 {}
 
 
-// InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p, bool)
-//     : InsetCommand(p, false)
-// {}
+CommandInfo const * InsetPrintIndex::findInfo(string const & /* cmdName */)
+{
+       static const char * const paramnames[] = {"name", ""};
+       static const bool isoptional[] = {false};
+       static const CommandInfo info = {1, paramnames, isoptional};
+       return &info;
+}
 
 
 docstring const InsetPrintIndex::getScreenLabel(Buffer const &) const
@@ -82,10 +101,9 @@ void InsetPrintIndex::validate(LaTeXFeatures & features) const
 }
 
 
-InsetBase::Code InsetPrintIndex::lyxCode() const
+InsetCode InsetPrintIndex::lyxCode() const
 {
-       return InsetBase::INDEX_PRINT_CODE;
+       return INDEX_PRINT_CODE;
 }
 
-
 } // namespace lyx