]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlToc.C
Cleanup of the Toc model and controller: The objective is to let the View (TocWidget...
[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  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <sstream>
13
14 #include <config.h>
15
16 #include "ControlToc.h"
17
18 #include "buffer.h"
19 #include "BufferView.h"
20 #include "bufferparams.h"
21 #include "debug.h"
22 #include "FloatList.h"
23 #include "funcrequest.h"
24 #include "gettext.h"
25
26 #include "frontends/LyXView.h"
27
28 #include "support/convert.h"
29
30 using std::vector;
31 using std::string;
32
33
34 class Buffer;
35
36 namespace lyx {
37 namespace frontend {
38
39
40 ControlToc::ControlToc(Dialog & d)
41         : ControlCommand(d, "tableofcontents", "toc")
42 {
43 }
44
45
46 TocList const & ControlToc::tocs() const
47 {
48         return kernel().buffer().tocBackend().tocs();
49 }
50
51
52 bool ControlToc::initialiseParams(string const & data)
53 {
54         if (!ControlCommand::initialiseParams(data))
55                 return false;
56
57         types_.clear();
58         type_names_.clear();
59         TocList const & tocs = kernel().buffer().tocBackend().tocs();
60         TocList::const_iterator it = tocs.begin();
61         TocList::const_iterator end = tocs.end();
62         for (; it != end; ++it) {
63                 types_.push_back(it->first);
64                 type_names_.push_back(getGuiName(it->first));
65         }
66
67         string selected_type ;
68         if(params()["type"].empty()) //Then plain toc...
69                 selected_type = params().getCmdName();
70         else
71                 selected_type = to_ascii(params()["type"]);
72         selected_type_ = -1;
73         for (size_t i = 0;  i != types_.size(); ++i) {
74                 if (selected_type == types_[i]) {
75                         selected_type_ = i;
76                         break;
77                 }
78         }
79
80         update();
81         return true;
82 }
83
84 void ControlToc::goTo(TocItem const & item)
85 {
86         string const tmp = convert<string>(item.id());
87         kernel().lyxview().dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
88 }
89
90
91 bool ControlToc::canOutline(size_t type) const
92 {
93         BOOST_ASSERT(type >= 0 && type < int(types_.size()));
94         return types_[type] == "tableofcontents";
95 }
96
97
98 void ControlToc::outlineUp()
99 {
100         kernel().dispatch(FuncRequest(LFUN_OUTLINE_UP));
101 }
102
103
104 void ControlToc::outlineDown()
105 {
106         kernel().dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
107 }
108
109
110 void ControlToc::outlineIn()
111 {
112         kernel().dispatch(FuncRequest(LFUN_OUTLINE_IN));
113 }
114
115
116 void ControlToc::outlineOut()
117 {
118         kernel().dispatch(FuncRequest(LFUN_OUTLINE_OUT));
119 }
120
121
122 void ControlToc::updateBackend()
123 {
124         kernel().buffer().tocBackend().update();
125 }
126
127
128 TocIterator const ControlToc::getCurrentTocItem(size_t type) const
129 {
130         BOOST_ASSERT(kernel().bufferview());
131         ParConstIterator it(kernel().bufferview()->cursor());
132         return kernel().buffer().tocBackend().item(types_[type], it);
133 }
134
135
136 docstring const ControlToc::getGuiName(string const & type) const
137 {
138         if (type == "tableofcontents")
139                 return _("Table of Contents");
140
141         FloatList const & floats =
142                 kernel().buffer().params().getLyXTextClass().floats();
143         if (floats.typeExist(type))
144                 return from_utf8(floats.getType(type).name());
145         else
146                 return _(type);
147 }
148
149 } // namespace frontend
150 } // namespace lyx