]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlToc.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlToc.C
1 /**
2  * \file ControlToc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlToc.h"
14 #include "gettext.h"
15
16 using std::vector;
17 using std::string;
18
19
20 class Buffer;
21
22 namespace lyx {
23 namespace frontend {
24
25
26 ControlToc::ControlToc(Dialog & d)
27         : ControlCommand(d, "toc")
28 {}
29
30
31 void ControlToc::goTo(toc::TocItem const & item)
32 {
33         item.goTo(kernel().lyxview());
34 }
35
36
37 vector<string> const ControlToc::getTypes() const
38 {
39         return toc::getTypes(kernel().buffer());
40 }
41
42
43 string const ControlToc::getGuiName(string const & type) const
44 {
45         if (type == "TOC")
46                 return _("Table of Contents");
47         else
48                 return _(toc::getGuiName(type, kernel().buffer()));
49 }
50
51
52 toc::Toc const ControlToc::getContents(string const & type) const
53 {
54         toc::Toc empty_list;
55
56         // This shouldn't be possible...
57         if (!kernel().isBufferAvailable()) {
58                 return empty_list;
59         }
60
61         toc::TocList tmp = toc::getTocList(kernel().buffer());
62         toc::TocList::iterator it = tmp.find(type);
63         if (it == tmp.end()) {
64                 return empty_list;
65         }
66
67         return it->second;
68 }
69
70 } // namespace frontend
71 } // namespace lyx