]> git.lyx.org Git - lyx.git/blob - src/insets/insettoc.C
d166b443193d626529f3085c2e8f70d365a2d34e
[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::endl;
17
18 string const InsetTOC::getScreenLabel() const 
19 {
20         string cmdname( getCmdName() );
21         if (cmdname == "tableofcontents" )
22                 return _("Table of Contents");
23         else if (cmdname == "listofalgorithms" )
24                 return _("List of Algorithms");
25         else if (cmdname == "listoffigures" )
26                 return _("List of Figures");
27         else
28                 return _("List of Tables");
29 }
30
31
32 Inset::Code InsetTOC::LyxCode() const
33 {
34         string cmdname( getCmdName() );
35         if (cmdname == "tableofcontents" )
36                 return Inset::TOC_CODE;
37         else if (cmdname == "listofalgorithms" )
38                 return Inset::LOA_CODE;
39         else if (cmdname == "listoffigures" )
40                 return Inset::LOF_CODE; 
41         else
42                 return Inset::LOT_CODE;
43 }
44
45
46 void InsetTOC::Edit(BufferView * bv, int, int, unsigned int)
47 {
48         bv->owner()->getDialogs()->showTOC( this );
49 }
50
51 int InsetTOC::Ascii(Buffer const * buffer, ostream & os, int) const
52 {
53         os << getScreenLabel() << endl << endl;
54
55         Buffer::TocType type;
56         string cmdname = getCmdName();
57         if (cmdname == "tableofcontents" )
58                 type = Buffer::TOC_TOC;
59         else if (cmdname == "listofalgorithms" )
60                 type = Buffer::TOC_LOA;
61         else if (cmdname == "listoffigures" )
62                 type = Buffer::TOC_LOF; 
63         else
64                 type = Buffer::TOC_LOT;
65
66         vector<vector<Buffer::TocItem> > const toc_list =
67                 buffer->getTocList();
68         vector<Buffer::TocItem> const & toc = toc_list[type];
69         for (vector<Buffer::TocItem>::const_iterator it = toc.begin();
70              it != toc.end(); ++it)
71                 os << string(4 * it->depth, ' ') << it->str << endl;
72
73         os << endl;
74         return 0;
75 }
76
77
78 int InsetTOC::Linuxdoc(Buffer const *, ostream & os) const
79 {
80         if (getCmdName() == "tableofcontents" )
81                 os << "<toc>";
82         return 0;
83 }
84
85
86 int InsetTOC::DocBook(Buffer const *, ostream & os) const
87 {
88         if (getCmdName() == "tableofcontents" )
89                 os << "<toc></toc>";
90         return 0;
91 }