]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlToc.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlToc.C
index 7af987fad6a710079c5803d66405e6ea436e283e..f64cb4ad62c98e864f5a62651207f0f1d66f3dec 100644 (file)
@@ -1,47 +1,51 @@
-/* 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
  *
- * \file ControlToc.C
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "ControlToc.h"
-#include "toc.h"
-#include "Dialogs.h"
-#include "BufferView.h"
-
-#include "support/lstrings.h" // tostr
+#include "gettext.h"
 
 using std::vector;
+using std::string;
+
 
 class Buffer;
 
-ControlToc::ControlToc(LyXView & lv, Dialogs & d)
-       : ControlCommand(lv, d, LFUN_TOC_INSERT)
+namespace lyx {
+namespace frontend {
+
+
+ControlToc::ControlToc(Dialog & d)
+       : ControlCommand(d, "toc")
 {}
 
 
-void ControlToc::goTo(toc::TocItem const & item) const
+void ControlToc::goTo(toc::TocItem const & item)
 {
-       item.goTo(lv_);
+       item.goTo(kernel().lyxview());
 }
 
 
 vector<string> const ControlToc::getTypes() const
 {
-       return toc::getTypes(lv_.view()->buffer());
+       return toc::getTypes(kernel().buffer());
+}
+
+
+string const ControlToc::getGuiName(string const & type) const
+{
+       if (type == "TOC")
+               return _("Table of Contents");
+       else
+               return _(toc::getGuiName(type, kernel().buffer()));
 }
 
 
@@ -50,11 +54,11 @@ toc::Toc const ControlToc::getContents(string const & type) const
        toc::Toc empty_list;
 
        // This shouldn't be possible...
-       if (!lv_.view()->available()) {
+       if (!kernel().isBufferAvailable()) {
                return empty_list;
        }
 
-       toc::TocList tmp = toc::getTocList(lv_.view()->buffer());
+       toc::TocList tmp = toc::getTocList(kernel().buffer());
        toc::TocList::iterator it = tmp.find(type);
        if (it == tmp.end()) {
                return empty_list;
@@ -62,3 +66,6 @@ toc::Toc const ControlToc::getContents(string const & type) const
 
        return it->second;
 }
+
+} // namespace frontend
+} // namespace lyx