]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlToc.C
* ControlToc.[Ch]
[features.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 <sstream>
12
13 #include <config.h>
14
15 #include "ControlToc.h"
16 #include "funcrequest.h"
17 #include "gettext.h"
18
19 using std::vector;
20 using std::string;
21
22
23 class Buffer;
24
25 namespace lyx {
26 namespace frontend {
27
28
29 ControlToc::ControlToc(Dialog & d)
30         : ControlCommand(d, "toc")
31 {}
32
33
34 void ControlToc::goTo(toc::TocItem const & item)
35 {
36         item.goTo(kernel().lyxview());
37 }
38
39
40 bool ControlToc::canOutline(string const & type)
41 {
42         return type == "TOC";
43 }
44
45
46 void ControlToc::outline(toc::OutlineOp op)
47 {
48         std::ostringstream o;
49         o << op << std::flush;
50         kernel().dispatch(FuncRequest(LFUN_OUTLINE, o.str()));
51 }
52
53
54 vector<string> const ControlToc::getTypes() const
55 {
56         return toc::getTypes(kernel().buffer());
57 }
58
59
60 string const ControlToc::getGuiName(string const & type) const
61 {
62         if (type == "TOC")
63                 return _("Table of Contents");
64         else
65                 return _(toc::getGuiName(type, kernel().buffer()));
66 }
67
68
69 toc::Toc const ControlToc::getContents(string const & type) const
70 {
71         toc::Toc empty_list;
72
73         // This shouldn't be possible...
74         if (!kernel().isBufferAvailable()) {
75                 return empty_list;
76         }
77
78         toc::TocList tmp = toc::getTocList(kernel().buffer());
79         toc::TocList::iterator it = tmp.find(type);
80         if (it == tmp.end()) {
81                 return empty_list;
82         }
83
84         return it->second;
85 }
86
87 } // namespace frontend
88 } // namespace lyx