]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlToc.C
fix toc bug
[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 empty_list;
68
69         // This shouldn't be possible...
70         if (!lv_.view()->available()) {
71                 return empty_list;
72         }
73
74         Buffer::Lists tmp = lv_.view()->buffer()->getLists();
75
76         Buffer::Lists::iterator it = tmp.find(type);
77
78         if (it == tmp.end()) {
79                 return empty_list;
80         }
81
82         return it->second;
83 }
84
85
86 namespace toc 
87 {
88
89 string const getType(string const & cmdName)
90 {
91         string type;
92
93         // It would be nice to have a map to extract this info.
94         // Does one already exist, Lars?
95         if (cmdName == "tableofcontents" )
96                 type = "TOC";
97
98         return cmdName;
99 }
100  
101 } // namespace toc