]> git.lyx.org Git - lyx.git/blob - src/insets/insettoc.C
74be043cf647efa845caddcc25a3bae69ad83366
[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() const 
18 {
19         string const cmdname( getCmdName() );
20         if (cmdname == "tableofcontents" )
21                 return _("Table of Contents");
22         else if (cmdname == "listofalgorithms" )
23                 return _("List of Algorithms");
24         else if (cmdname == "listoffigures" )
25                 return _("List of Figures");
26         else
27                 return _("List of Tables");
28 }
29
30
31 Inset::Code InsetTOC::LyxCode() const
32 {
33         string const cmdname(getCmdName());
34         if (cmdname == "tableofcontents")
35                 return Inset::TOC_CODE;
36         else if (cmdname == "listofalgorithms")
37                 return Inset::LOA_CODE;
38         else if (cmdname == "listoffigures")
39                 return Inset::LOF_CODE; 
40         else
41                 return Inset::LOT_CODE;
42 }
43
44
45 void InsetTOC::Edit(BufferView * bv, int, int, unsigned int)
46 {
47         bv->owner()->getDialogs()->showTOC( this );
48 }
49
50
51 int InsetTOC::Ascii(Buffer const * buffer, std::ostream & os, int) const
52 {
53         os << getScreenLabel() << "\n\n";
54
55 #if 0
56         Buffer::TocType type;
57         string cmdname = getCmdName();
58         if (cmdname == "tableofcontents" )
59                 type = Buffer::TOC_TOC;
60         else if (cmdname == "listofalgorithms" )
61                 type = Buffer::TOC_LOA;
62         else if (cmdname == "listoffigures" )
63                 type = Buffer::TOC_LOF; 
64         else
65                 type = Buffer::TOC_LOT;
66
67         vector<vector<Buffer::TocItem> > const toc_list =
68                 buffer->getTocList();
69         vector<Buffer::TocItem> const & toc = toc_list[type];
70         for (vector<Buffer::TocItem>::const_iterator it = toc.begin();
71              it != toc.end(); ++it)
72                 os << string(4 * it->depth, ' ') << it->str << endl;
73 #else
74 #ifdef WITH_WARNINGS
75 #warning Fix Me! (Lgb)
76 #endif
77         string type;
78         string const cmdname = getCmdName();
79         if (cmdname == "tableofcontents" )
80                 type = "TOC";
81         else if (cmdname == "listofalgorithms" )
82                 type = "LOA";
83         else if (cmdname == "listoffigures" )
84                 type = "LOF";
85         else 
86                 type = "LOT";
87
88         Buffer::Lists const toc_list = buffer->getLists();
89         Buffer::Lists::const_iterator cit =
90                 toc_list.find(type);
91         if (cit != toc_list.end()) {
92                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
93                 Buffer::SingleList::const_iterator end = cit->second.end();
94                 for (; ccit != end; ++ccit)
95                         os << string(4 * ccit->depth, ' ')
96                            << ccit->str << "\n";
97         }
98 #endif
99         os << "\n";
100         return 0;
101 }
102
103
104 int InsetTOC::Linuxdoc(Buffer const *, std::ostream & os) const
105 {
106         if (getCmdName() == "tableofcontents" )
107                 os << "<toc>";
108         return 0;
109 }
110
111
112 int InsetTOC::DocBook(Buffer const *, std::ostream & os) const
113 {
114         if (getCmdName() == "tableofcontents" )
115                 os << "<toc></toc>";
116         return 0;
117 }