]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlToc.C
more unicode filenames
[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 <sstream>
12
13 #include <config.h>
14
15 #include "ControlToc.h"
16 #include "buffer.h"
17 #include "BufferView.h"
18 #include "bufferparams.h"
19 #include "debug.h"
20 #include "FloatList.h"
21 #include "funcrequest.h"
22 #include "gettext.h"
23
24 #include "frontends/LyXView.h"
25
26 #include "support/convert.h"
27
28 using std::vector;
29 using std::string;
30
31
32 class Buffer;
33
34 namespace lyx {
35 namespace frontend {
36
37
38 ControlToc::ControlToc(Dialog & d)
39         : ControlCommand(d, "tableofcontents", "toc")
40 {}
41
42
43 void ControlToc::goTo(TocItem const & item)
44 {
45         string const tmp = convert<string>(item.id());
46         kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
47 }
48
49
50 bool ControlToc::canOutline(string const & type)
51 {
52         return type == "tableofcontents";
53 }
54
55
56 void ControlToc::outlineUp()
57 {
58         kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
59 }
60
61
62 void ControlToc::outlineDown()
63 {
64         kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
65 }
66
67
68 void ControlToc::outlineIn()
69 {
70         kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
71 }
72
73
74 void ControlToc::outlineOut()
75 {
76         kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
77 }
78
79
80 vector<string> const & ControlToc::getTypes() const
81 {
82         return kernel().buffer().tocBackend().types();
83 }
84
85
86 TocIterator const ControlToc::getCurrentTocItem(
87         string const & type) const
88 {
89         BOOST_ASSERT(kernel().bufferview());
90
91         ParConstIterator it(kernel().bufferview()->cursor());
92         return kernel().buffer().tocBackend().item(type, it);
93 }
94
95
96 string const ControlToc::getGuiName(string const & type) const
97 {
98         if (type == "tableofcontents")
99                 return lyx::to_utf8(_("Table of Contents"));
100
101         FloatList const & floats =
102                 kernel().buffer().params().getLyXTextClass().floats();
103         if (floats.typeExist(type))
104                 return floats.getType(type).name();
105         else
106                 return lyx::to_utf8(_(type));
107 }
108
109
110 Toc const empty_list;
111
112 Toc const & ControlToc::getContents(string const & type) const
113 {
114         // This shouldn't be possible...
115         if (!kernel().isBufferAvailable()) {
116                 return empty_list;
117         }
118
119         return kernel().buffer().tocBackend().toc(type);
120 }
121
122 } // namespace frontend
123 } // namespace lyx