]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlToc.C
implement getLabelList
[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 "LyXView.h"
24 #include "lyxfunc.h"
25 #include "support/lstrings.h" // tostr
26
27 using std::vector;
28 using SigC::slot;
29
30 ControlToc::ControlToc(LyXView & lv, Dialogs & d)
31         : ControlCommand(lv, d, LFUN_TOC_INSERT)
32 {
33         d_.showTOC.connect(slot(this, &ControlToc::showInset));
34         d_.createTOC.connect(slot(this, &ControlToc::createInset));
35 }
36
37
38 void ControlToc::Goto(int const & id) const
39 {
40         string const tmp = tostr(id);
41         lv_.getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);
42 }
43
44
45 vector<string> const ControlToc::getTypes() const
46 {
47         vector<string> types;
48
49         Buffer::Lists const tmp = lv_.view()->buffer()->getLists();
50
51         Buffer::Lists::const_iterator cit = tmp.begin();
52         Buffer::Lists::const_iterator end = tmp.end();
53
54         for (; cit != end; ++cit) {
55                 types.push_back(cit->first);
56         }
57
58         return types;
59 }
60
61
62 Buffer::SingleList const ControlToc::getContents(string const & type) const
63 {
64         Buffer::SingleList contents;
65         
66         Buffer::TocItem noContent(0, 0, string());
67
68         // This shouldn't be possible...
69         if (!lv_.view()->available()) {
70                 noContent.str = _("*** No Document ***");
71                 contents.push_back(noContent);
72                 return contents;
73         }
74
75         Buffer::Lists tmp = lv_.view()->buffer()->getLists();
76
77         Buffer::Lists::iterator it = tmp.find(type);
78
79         if (it == tmp.end()) {
80                 noContent.str = _("*** No Lists ***");
81                 contents.push_back(noContent);
82                 return contents;
83         }
84
85         return it->second;
86 }
87
88
89 namespace toc 
90 {
91
92 string getType(string const & cmdName)
93 {
94         string type;
95
96         // It would be nice to have a map to extract this info.
97         // Does one already exist, Lars?
98         if (cmdName == "tableofcontents" )
99                 type = "TOC";
100
101         else if (cmdName == "listofalgorithms" )
102                 type = "algorithm";
103
104         else if (cmdName == "listoffigures" )
105                 type = "figure";
106
107         else
108                 type = "table";
109
110         return type;
111 }
112  
113 } // namespace toc