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