]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlToc.C
Switch from SigC signals to boost::signals
[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 "ViewBase.h"
22 #include "ButtonControllerBase.h"
23 #include "buffer.h"
24 #include "Dialogs.h"
25 #include "lyxfunc.h"
26 #include "gettext.h"
27 #include "BufferView.h"
28
29 #include "frontends/LyXView.h"
30
31 #include "support/lstrings.h" // tostr
32
33 #include <boost/bind.hpp>
34
35 using std::vector;
36
37 ControlToc::ControlToc(LyXView & lv, Dialogs & d)
38         : ControlCommand(lv, d, LFUN_TOC_INSERT)
39 {
40         d_.showTOC = boost::bind(&ControlToc::showInset, this, _1);
41         d_.createTOC = boost::bind(&ControlToc::createInset, this, _1);
42 }
43
44
45 void ControlToc::Goto(int const & id) const
46 {
47         string const tmp = tostr(id);
48         lv_.getLyXFunc()->dispatch(LFUN_GOTO_PARAGRAPH, tmp);
49 }
50
51
52 vector<string> const ControlToc::getTypes() const
53 {
54         vector<string> types;
55
56         Buffer::Lists const tmp = lv_.view()->buffer()->getLists();
57
58         Buffer::Lists::const_iterator cit = tmp.begin();
59         Buffer::Lists::const_iterator end = tmp.end();
60
61         for (; cit != end; ++cit) {
62                 types.push_back(cit->first);
63         }
64
65         return types;
66 }
67
68
69 Buffer::SingleList const ControlToc::getContents(string const & type) const
70 {
71         Buffer::SingleList empty_list;
72
73         // This shouldn't be possible...
74         if (!lv_.view()->available()) {
75                 return empty_list;
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                 return empty_list;
84         }
85
86         return it->second;
87 }
88
89
90 namespace toc
91 {
92
93 string const getType(string const & cmdName)
94 {
95         string type = cmdName;
96
97         // special case
98         if (cmdName == "tableofcontents")
99                 type = "TOC";
100
101         return type;
102 }
103
104 } // namespace toc