2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ======================================================
15 #include FORMS_H_LOCATION
18 #pragma implementation
28 #include "support/lstrings.h"
33 // The current code uses the apply() for handling the Update button and the
34 // type-of-table selection and cancel() for the close button. This is a little
35 // confusing to the button controller so I've made an IgnorantPolicy to cover
36 // this situation since the dialog doesn't care about buttons. ARRae 20001013
37 FormToc::FormToc(LyXView * lv, Dialogs * d)
38 : FormCommand(lv, d, _("Table of Contents")),
41 // let the dialog be shown
42 // These are permanent connections so we won't bother
43 // storing a copy because we won't be disconnecting.
44 d->showTOC.connect(slot(this, &FormToc::showInset));
45 d->createTOC.connect(slot(this, &FormToc::createInset));
49 FL_FORM * FormToc::form() const
57 void FormToc::disconnect()
60 FormCommand::disconnect();
66 dialog_.reset(build_toc());
69 fl_addto_choice(dialog_->choice_toc_type,
70 _(" TOC | LOF | LOT | LOA "));
72 Buffer::Lists const tmp = lv_->view()->buffer()->getLists();
73 Buffer::Lists::const_iterator cit = tmp.begin();
74 Buffer::Lists::const_iterator end = tmp.end();
75 for (; cit != end; ++cit) {
76 fl_addto_choice(dialog_->choice_toc_type, cit->first.c_str());
80 // Manage the cancel/close button
81 bc().setCancel(dialog_->button_cancel);
86 void FormToc::update()
91 if (params.getCmdName() == "tableofcontents" )
92 type = Buffer::TOC_TOC;
94 else if (params.getCmdName() == "listofalgorithms" )
95 type = Buffer::TOC_LOA;
97 else if (params.getCmdName() == "listoffigures" )
98 type = Buffer::TOC_LOF;
101 type = Buffer::TOC_LOT;
103 fl_set_choice( dialog_->choice_toc_type, type+1 );
105 #warning Reimplement (Lgb)
111 void FormToc::updateToc()
114 if (!lv_->view()->available()) {
116 fl_clear_browser( dialog_->browser_toc );
117 fl_add_browser_line( dialog_->browser_toc,
118 _("*** No Document ***"));
122 vector<vector<Buffer::TocItem> > tmp =
123 lv_->view()->buffer()->getTocList();
124 int type = fl_get_choice( dialog_->choice_toc_type ) - 1;
126 // Check if all elements are the same.
127 if (toclist.size() == tmp[type].size()) {
129 for (; i < toclist.size(); ++i) {
130 if (toclist[i] != tmp[type][i])
133 if (i >= toclist.size()) return;
136 // List has changed. Update browser
139 static Buffer * buffer = 0;
142 if (buffer == lv_->view()->buffer()) {
143 topline = fl_get_browser_topline( dialog_->browser_toc );
144 line = fl_get_browser( dialog_->browser_toc );
146 buffer = lv_->view()->buffer();
148 fl_clear_browser( dialog_->browser_toc );
150 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
151 it != toclist.end(); ++it)
152 fl_add_browser_line( dialog_->browser_toc,
153 (string(4 * (*it).depth, ' ')
154 + (*it).str).c_str());
156 fl_set_browser_topline( dialog_->browser_toc, topline );
157 fl_select_browser_line( dialog_->browser_toc, line );
159 #warning Fix Me! (Lgb)
160 if (!lv_->view()->available()) {
162 fl_clear_browser( dialog_->browser_toc );
163 fl_add_browser_line( dialog_->browser_toc,
164 _("*** No Document ***"));
168 Buffer::Lists tmp = lv_->view()->buffer()->getLists();
170 fl_get_choice_item_text(dialog_->choice_toc_type,
171 fl_get_choice(dialog_->choice_toc_type));
173 Buffer::Lists::iterator it = tmp.find(type);
175 if (it != tmp.end()) {
176 // Check if all elements are the same.
177 if (toclist == it->second) {
180 } else if (it == tmp.end()) {
182 fl_clear_browser(dialog_->browser_toc);
183 fl_add_browser_line(dialog_->browser_toc,
184 _("*** No Lists ***"));
188 // List has changed. Update browser
189 toclist = it->second;
191 static Buffer * buffer = 0;
194 if (buffer == lv_->view()->buffer()) {
195 topline = fl_get_browser_topline(dialog_->browser_toc);
196 line = fl_get_browser( dialog_->browser_toc );
198 buffer = lv_->view()->buffer();
200 fl_clear_browser(dialog_->browser_toc);
202 Buffer::SingleList::const_iterator cit = toclist.begin();
203 Buffer::SingleList::const_iterator end = toclist.end();
205 for (; cit != end; ++cit) {
206 string const line = string(4 * cit->depth, ' ') + cit->str;
207 fl_add_browser_line(dialog_->browser_toc, line.c_str());
210 fl_set_browser_topline(dialog_->browser_toc, topline);
211 fl_select_browser_line(dialog_->browser_toc, line);
216 bool FormToc::input(FL_OBJECT *, long)
220 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
221 if (0 < choice && choice - 1 < toclist.size()) {
222 string const tmp = tostr(toclist[choice-1].par->id());
223 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);