]> git.lyx.org Git - lyx.git/blob - src/insets/insettoc.C
c93c62e26acb11e63787d4aa6b65eab0022a139d
[lyx.git] / src / insets / insettoc.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "gettext.h"
8 #include "insettoc.h"
9 #include "BufferView.h"
10 #include "LyXView.h"
11 #include "frontends/Dialogs.h"
12 #include "debug.h"
13 #include "buffer.h"
14
15
16 using std::vector;
17 using std::ostream;
18
19
20 string const InsetTOC::getScreenLabel(Buffer const *) const 
21 {
22         string const cmdname(getCmdName());
23         
24         if (cmdname == "tableofcontents")
25                 return _("Table of Contents");
26         return _("Unknown toc list");
27 }
28
29
30 Inset::Code InsetTOC::lyxCode() const
31 {
32         string const cmdname(getCmdName());
33         if (cmdname == "tableofcontents")
34                 return Inset::TOC_CODE;
35         return Inset::NO_CODE;
36 }
37
38
39 void InsetTOC::edit(BufferView * bv, int, int, unsigned int)
40 {
41         bv->owner()->getDialogs()->showTOC(this);
42 }
43
44
45 void InsetTOC::edit(BufferView * bv, bool)
46 {
47         edit(bv, 0, 0, 0);
48 }
49
50
51 int InsetTOC::ascii(Buffer const * buffer, ostream & os, int) const
52 {
53         os << getScreenLabel(buffer) << "\n\n";
54
55         string type;
56         string const cmdname = getCmdName();
57         if (cmdname == "tableofcontents")
58                 type = "TOC";
59         Buffer::Lists const toc_list = buffer->getLists();
60         Buffer::Lists::const_iterator cit =
61                 toc_list.find(type);
62         if (cit != toc_list.end()) {
63                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
64                 Buffer::SingleList::const_iterator end = cit->second.end();
65                 for (; ccit != end; ++ccit)
66                         os << string(4 * ccit->depth, ' ')
67                            << ccit->str << "\n";
68         }
69
70         os << "\n";
71         return 0;
72 }
73
74
75 int InsetTOC::linuxdoc(Buffer const *, ostream & os) const
76 {
77         if (getCmdName() == "tableofcontents")
78                 os << "<toc>";
79         return 0;
80 }
81
82
83 int InsetTOC::docbook(Buffer const *, ostream & os) const
84 {
85         if (getCmdName() == "tableofcontents")
86                 os << "<toc></toc>";
87         return 0;
88 }