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"
32 // The current code uses the apply() for handling the Update button and the
33 // type-of-table selection and cancel() for the close button. This is a little
34 // confusing to the button controller so I've made an IgnorantPolicy to cover
35 // this situation since the dialog doesn't care about buttons. ARRae 20001013
36 FormToc::FormToc(LyXView * lv, Dialogs * d)
37 : FormCommand(lv, d, _("Table of Contents")),
40 // let the dialog be shown
41 // These are permanent connections so we won't bother
42 // storing a copy because we won't be disconnecting.
43 d->showTOC.connect(slot(this, &FormToc::showInset));
44 d->createTOC.connect(slot(this, &FormToc::createInset));
48 FL_FORM * FormToc::form() const
56 void FormToc::disconnect()
59 FormCommand::disconnect();
65 dialog_.reset(build_toc());
68 fl_addto_choice(dialog_->choice_toc_type,
69 _(" TOC | LOF | LOT | LOA "));
71 Buffer::Lists const tmp = lv_->view()->buffer()->getLists();
72 Buffer::Lists::const_iterator cit = tmp.begin();
73 Buffer::Lists::const_iterator end = tmp.end();
74 for (; cit != end; ++cit) {
75 fl_addto_choice(dialog_->choice_toc_type, cit->first.c_str());
78 // Don't need to limit size of this dialog
79 // (but fixing min size is a GOOD thing).
80 // Workaround dumb xforms sizing bug
84 // Manage the cancel/close button
85 bc().setCancel(dialog_->button_cancel);
90 void FormToc::update()
95 if (params.getCmdName() == "tableofcontents" )
96 type = Buffer::TOC_TOC;
98 else if (params.getCmdName() == "listofalgorithms" )
99 type = Buffer::TOC_LOA;
101 else if (params.getCmdName() == "listoffigures" )
102 type = Buffer::TOC_LOF;
105 type = Buffer::TOC_LOT;
107 fl_set_choice( dialog_->choice_toc_type, type+1 );
109 #warning Reimplement (Lgb)
115 void FormToc::updateToc()
118 if (!lv_->view()->available()) {
120 fl_clear_browser( dialog_->browser_toc );
121 fl_add_browser_line( dialog_->browser_toc,
122 _("*** No Document ***"));
126 vector<vector<Buffer::TocItem> > tmp =
127 lv_->view()->buffer()->getTocList();
128 int type = fl_get_choice( dialog_->choice_toc_type ) - 1;
130 // Check if all elements are the same.
131 if (toclist.size() == tmp[type].size()) {
133 for (; i < toclist.size(); ++i) {
134 if (toclist[i] != tmp[type][i])
137 if (i >= toclist.size()) return;
140 // List has changed. Update browser
143 static Buffer * buffer = 0;
146 if (buffer == lv_->view()->buffer()) {
147 topline = fl_get_browser_topline( dialog_->browser_toc );
148 line = fl_get_browser( dialog_->browser_toc );
150 buffer = lv_->view()->buffer();
152 fl_clear_browser( dialog_->browser_toc );
154 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
155 it != toclist.end(); ++it)
156 fl_add_browser_line( dialog_->browser_toc,
157 (string(4 * (*it).depth, ' ')
158 + (*it).str).c_str());
160 fl_set_browser_topline( dialog_->browser_toc, topline );
161 fl_select_browser_line( dialog_->browser_toc, line );
163 #warning Fix Me! (Lgb)
164 if (!lv_->view()->available()) {
166 fl_clear_browser( dialog_->browser_toc );
167 fl_add_browser_line( dialog_->browser_toc,
168 _("*** No Document ***"));
172 Buffer::Lists tmp = lv_->view()->buffer()->getLists();
174 fl_get_choice_item_text(dialog_->choice_toc_type,
175 fl_get_choice(dialog_->choice_toc_type));
177 Buffer::Lists::iterator it = tmp.find(type);
179 if (it != tmp.end()) {
180 // Check if all elements are the same.
181 if (toclist == it->second) {
184 } else if (it == tmp.end()) {
186 fl_clear_browser(dialog_->browser_toc);
187 fl_add_browser_line(dialog_->browser_toc,
188 _("*** No Lists ***"));
192 // List has changed. Update browser
193 toclist = it->second;
195 static Buffer * buffer = 0;
198 if (buffer == lv_->view()->buffer()) {
199 topline = fl_get_browser_topline(dialog_->browser_toc);
200 line = fl_get_browser( dialog_->browser_toc );
202 buffer = lv_->view()->buffer();
204 fl_clear_browser(dialog_->browser_toc);
206 Buffer::SingleList::const_iterator cit = toclist.begin();
207 Buffer::SingleList::const_iterator end = toclist.end();
209 for (; cit != end; ++cit) {
210 string const line = string(4 * cit->depth, ' ') + cit->str;
211 fl_add_browser_line(dialog_->browser_toc, line.c_str());
214 fl_set_browser_topline(dialog_->browser_toc, topline);
215 fl_select_browser_line(dialog_->browser_toc, line);
220 bool FormToc::input(FL_OBJECT *, long)
224 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
225 if (0 < choice && choice - 1 < toclist.size()) {
226 string const tmp = tostr(toclist[choice-1].par->id());
227 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);