]> git.lyx.org Git - lyx.git/blob - src/insets/insettoc.C
make cursor_visible private
[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 #warning Fix Me! (Lgb)
75         string type;
76         string const cmdname = getCmdName();
77         if (cmdname == "tableofcontents" )
78                 type = "TOC";
79         else if (cmdname == "listofalgorithms" )
80                 type = "LOA";
81         else if (cmdname == "listoffigures" )
82                 type = "LOF";
83         else 
84                 type = "LOT";
85
86         Buffer::Lists const toc_list = buffer->getLists();
87         Buffer::Lists::const_iterator cit =
88                 toc_list.find(type);
89         if (cit != toc_list.end()) {
90                 Buffer::SingleList::const_iterator ccit = cit->second.begin();
91                 Buffer::SingleList::const_iterator end = cit->second.end();
92                 for (; ccit != end; ++ccit)
93                         os << string(4 * ccit->depth, ' ')
94                            << ccit->str << "\n";
95         }
96 #endif
97         os << "\n";
98         return 0;
99 }
100
101
102 int InsetTOC::Linuxdoc(Buffer const *, std::ostream & os) const
103 {
104         if (getCmdName() == "tableofcontents" )
105                 os << "<toc>";
106         return 0;
107 }
108
109
110 int InsetTOC::DocBook(Buffer const *, std::ostream & os) const
111 {
112         if (getCmdName() == "tableofcontents" )
113                 os << "<toc></toc>";
114         return 0;
115 }