]> git.lyx.org Git - lyx.git/blob - src/insets/insettoc.C
2001-12-28 Lars Gullik Bj�nnes <larsbj@birdstep.com>
[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 using std::vector;
16
17 string const InsetTOC::getScreenLabel(Buffer const *) const 
18 {
19         string const cmdname(getCmdName());
20         
21         if (cmdname == "tableofcontents")
22                 return _("Table of Contents");
23         return _("Unknown toc list");
24 }
25
26
27 Inset::Code InsetTOC::lyxCode() const
28 {
29         string const cmdname(getCmdName());
30         if (cmdname == "tableofcontents")
31                 return Inset::TOC_CODE;
32         return Inset::NO_CODE;
33 }
34
35
36 void InsetTOC::edit(BufferView * bv, int, int, unsigned int)
37 {
38         bv->owner()->getDialogs()->showTOC(this);
39 }
40
41
42 void InsetTOC::edit(BufferView * bv, bool)
43 {
44         edit(bv, 0, 0, 0);
45 }
46
47
48 int InsetTOC::ascii(Buffer const * buffer, std::ostream & os, int) const
49 {
50         os << getScreenLabel(buffer) << "\n\n";
51
52         string type;
53         string const cmdname = getCmdName();
54         if (cmdname == "tableofcontents")
55                 type = "TOC";
56         Buffer::Lists const toc_list = buffer->getLists();
57         Buffer::Lists::const_iterator cit =
58                 toc_list.find(type);
59         if (cit != toc_list.end()) {
60                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
61                 Buffer::SingleList::const_iterator end = cit->second.end();
62                 for (; ccit != end; ++ccit)
63                         os << string(4 * ccit->depth, ' ')
64                            << ccit->str << "\n";
65         }
66
67         os << "\n";
68         return 0;
69 }
70
71
72 int InsetTOC::linuxdoc(Buffer const *, std::ostream & os) const
73 {
74         if (getCmdName() == "tableofcontents")
75                 os << "<toc>";
76         return 0;
77 }
78
79
80 int InsetTOC::docbook(Buffer const *, std::ostream & os) const
81 {
82         if (getCmdName() == "tableofcontents")
83                 os << "<toc></toc>";
84         return 0;
85 }