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());
79 // Don't need to limit size of this dialog
80 // (but fixing min size is a GOOD thing).
81 // Workaround dumb xforms sizing bug
85 // Manage the cancel/close button
86 bc().setCancel(dialog_->button_cancel);
91 void FormToc::update()
96 if (params.getCmdName() == "tableofcontents" )
97 type = Buffer::TOC_TOC;
99 else if (params.getCmdName() == "listofalgorithms" )
100 type = Buffer::TOC_LOA;
102 else if (params.getCmdName() == "listoffigures" )
103 type = Buffer::TOC_LOF;
106 type = Buffer::TOC_LOT;
108 fl_set_choice( dialog_->choice_toc_type, type+1 );
110 #warning Reimplement (Lgb)
116 void FormToc::updateToc()
119 if (!lv_->view()->available()) {
121 fl_clear_browser( dialog_->browser_toc );
122 fl_add_browser_line( dialog_->browser_toc,
123 _("*** No Document ***"));
127 vector<vector<Buffer::TocItem> > tmp =
128 lv_->view()->buffer()->getTocList();
129 int type = fl_get_choice( dialog_->choice_toc_type ) - 1;
131 // Check if all elements are the same.
132 if (toclist.size() == tmp[type].size()) {
134 for (; i < toclist.size(); ++i) {
135 if (toclist[i] != tmp[type][i])
138 if (i >= toclist.size()) return;
141 // List has changed. Update browser
144 static Buffer * buffer = 0;
147 if (buffer == lv_->view()->buffer()) {
148 topline = fl_get_browser_topline( dialog_->browser_toc );
149 line = fl_get_browser( dialog_->browser_toc );
151 buffer = lv_->view()->buffer();
153 fl_clear_browser( dialog_->browser_toc );
155 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
156 it != toclist.end(); ++it)
157 fl_add_browser_line( dialog_->browser_toc,
158 (string(4 * (*it).depth, ' ')
159 + (*it).str).c_str());
161 fl_set_browser_topline( dialog_->browser_toc, topline );
162 fl_select_browser_line( dialog_->browser_toc, line );
164 #warning Fix Me! (Lgb)
165 if (!lv_->view()->available()) {
167 fl_clear_browser( dialog_->browser_toc );
168 fl_add_browser_line( dialog_->browser_toc,
169 _("*** No Document ***"));
173 Buffer::Lists tmp = lv_->view()->buffer()->getLists();
175 fl_get_choice_item_text(dialog_->choice_toc_type,
176 fl_get_choice(dialog_->choice_toc_type));
178 Buffer::Lists::iterator it = tmp.find(type);
180 if (it != tmp.end()) {
181 // Check if all elements are the same.
182 if (toclist == it->second) {
185 } else if (it == tmp.end()) {
187 fl_clear_browser(dialog_->browser_toc);
188 fl_add_browser_line(dialog_->browser_toc,
189 _("*** No Lists ***"));
193 // List has changed. Update browser
194 toclist = it->second;
196 static Buffer * buffer = 0;
199 if (buffer == lv_->view()->buffer()) {
200 topline = fl_get_browser_topline(dialog_->browser_toc);
201 line = fl_get_browser( dialog_->browser_toc );
203 buffer = lv_->view()->buffer();
205 fl_clear_browser(dialog_->browser_toc);
207 Buffer::SingleList::const_iterator cit = toclist.begin();
208 Buffer::SingleList::const_iterator end = toclist.end();
210 for (; cit != end; ++cit) {
211 string const line = string(4 * cit->depth, ' ') + cit->str;
212 fl_add_browser_line(dialog_->browser_toc, line.c_str());
215 fl_set_browser_topline(dialog_->browser_toc, topline);
216 fl_select_browser_line(dialog_->browser_toc, line);
221 bool FormToc::input(FL_OBJECT *, long)
225 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
226 if (0 < choice && choice - 1 < toclist.size()) {
227 string const tmp = tostr(toclist[choice-1].par->id());
228 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);