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