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