]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlToc.C
The reference dialog now disconnects from the inset on Apply. Its behaviour
[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 #include "BufferView.h"
30
31 using std::vector;
32 using SigC::slot;
33
34 ControlToc::ControlToc(LyXView & lv, Dialogs & d)
35         : ControlCommand(lv, d, LFUN_TOC_INSERT)
36 {
37         d_.showTOC.connect(slot(this, &ControlToc::showInset));
38         d_.createTOC.connect(slot(this, &ControlToc::createInset));
39 }
40
41
42 void ControlToc::Goto(int const & id) const
43 {
44         string const tmp = tostr(id);
45         lv_.getLyXFunc()->dispatch(LFUN_GOTO_PARAGRAPH, tmp);
46 }
47
48
49 vector<string> const ControlToc::getTypes() const
50 {
51         vector<string> types;
52
53         Buffer::Lists const tmp = lv_.view()->buffer()->getLists();
54
55         Buffer::Lists::const_iterator cit = tmp.begin();
56         Buffer::Lists::const_iterator end = tmp.end();
57
58         for (; cit != end; ++cit) {
59                 types.push_back(cit->first);
60         }
61
62         return types;
63 }
64
65
66 Buffer::SingleList const ControlToc::getContents(string const & type) const
67 {
68         Buffer::SingleList empty_list;
69
70         // This shouldn't be possible...
71         if (!lv_.view()->available()) {
72                 return empty_list;
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                 return empty_list;
81         }
82
83         return it->second;
84 }
85
86
87 namespace toc 
88 {
89
90 string const getType(string const & cmdName)
91 {
92         string type;
93
94         // It would be nice to have a map to extract this info.
95         // Does one already exist, Lars?
96         if (cmdName == "tableofcontents" )
97                 type = "TOC";
98
99         return cmdName;
100 }
101  
102 } // namespace toc