]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlToc.C
*duck*
[lyx.git] / src / frontends / controllers / ControlToc.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 2001 The LyX Team.
7  *
8  * ======================================================
9  *
10  * \file ControlToc.C
11  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "ControlToc.h"
21 #include "buffer.h"
22 #include "Dialogs.h"
23 #include "lyxfunc.h"
24 #include "gettext.h"
25 #include "BufferView.h"
26
27 #include "support/lstrings.h" // tostr
28
29 using std::vector;
30
31
32 ControlToc::ControlToc(LyXView & lv, Dialogs & d)
33         : ControlCommand(lv, d, LFUN_TOC_INSERT)
34 {}
35
36
37 void ControlToc::Goto(int const & id) const
38 {
39         string const tmp = tostr(id);
40         lv_.getLyXFunc()->dispatch(LFUN_GOTO_PARAGRAPH, tmp);
41 }
42
43
44 vector<string> const ControlToc::getTypes() const
45 {
46         vector<string> types;
47
48         Buffer::Lists const tmp = lv_.view()->buffer()->getLists();
49
50         Buffer::Lists::const_iterator cit = tmp.begin();
51         Buffer::Lists::const_iterator end = tmp.end();
52
53         for (; cit != end; ++cit) {
54                 types.push_back(cit->first);
55         }
56
57         return types;
58 }
59
60
61 Buffer::SingleList const ControlToc::getContents(string const & type) const
62 {
63         Buffer::SingleList empty_list;
64
65         // This shouldn't be possible...
66         if (!lv_.view()->available()) {
67                 return empty_list;
68         }
69
70         Buffer::Lists tmp = lv_.view()->buffer()->getLists();
71
72         Buffer::Lists::iterator it = tmp.find(type);
73
74         if (it == tmp.end()) {
75                 return empty_list;
76         }
77
78         return it->second;
79 }
80
81
82 namespace toc
83 {
84
85 string const getType(string const & cmdName)
86 {
87         string type = cmdName;
88
89         // special case
90         if (cmdName == "tableofcontents")
91                 type = "TOC";
92
93         return type;
94 }
95
96 } // namespace toc