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"
30 // The current code uses the apply() for handling the Update button and the
31 // type-of-table selection and cancel() for the close button. This is a little
32 // confusing to the button controller so I've made an IgnorantPolicy to cover
33 // this situation since the dialog doesn't care about buttons. ARRae 20001013
34 FormToc::FormToc(LyXView * lv, Dialogs * d)
35 : FormCommand(lv, d, _("Table of Contents"), new OkCancelPolicy),
38 // let the dialog be shown
39 // These are permanent connections so we won't bother
40 // storing a copy because we won't be disconnecting.
41 d->showTOC.connect(slot(this, &FormToc::showInset));
42 d->createTOC.connect(slot(this, &FormToc::createInset));
52 FL_FORM * FormToc::form() const
54 if (dialog_ ) return dialog_->form;
59 void FormToc::disconnect()
62 FormCommand::disconnect();
68 dialog_ = build_toc();
71 fl_addto_choice(dialog_->choice_toc_type,
72 _(" TOC | LOF | LOT | LOA "));
74 Buffer::Lists const tmp = lv_->view()->buffer()->getLists();
75 Buffer::Lists::const_iterator cit = tmp.begin();
76 Buffer::Lists::const_iterator end = tmp.end();
77 for (; cit != end; ++cit) {
78 fl_addto_choice(dialog_->choice_toc_type, cit->first.c_str());
81 // Don't need to limit size of this dialog
82 // (but fixing min size is a GOOD thing).
83 // Workaround dumb xforms sizing bug
87 // Manage the cancel/close button
88 bc_.setCancel(dialog_->button_cancel);
93 void FormToc::update()
98 if (params.getCmdName() == "tableofcontents" )
99 type = Buffer::TOC_TOC;
101 else if (params.getCmdName() == "listofalgorithms" )
102 type = Buffer::TOC_LOA;
104 else if (params.getCmdName() == "listoffigures" )
105 type = Buffer::TOC_LOF;
108 type = Buffer::TOC_LOT;
110 fl_set_choice( dialog_->choice_toc_type, type+1 );
112 #warning Reimplement (Lgb)
118 void FormToc::updateToc()
121 if (!lv_->view()->available()) {
123 fl_clear_browser( dialog_->browser_toc );
124 fl_add_browser_line( dialog_->browser_toc,
125 _("*** No Document ***"));
129 vector<vector<Buffer::TocItem> > tmp =
130 lv_->view()->buffer()->getTocList();
131 int type = fl_get_choice( dialog_->choice_toc_type ) - 1;
133 // Check if all elements are the same.
134 if (toclist.size() == tmp[type].size()) {
136 for (; i < toclist.size(); ++i) {
137 if (toclist[i] != tmp[type][i])
140 if (i >= toclist.size()) return;
143 // List has changed. Update browser
146 static Buffer * buffer = 0;
149 if (buffer == lv_->view()->buffer()) {
150 topline = fl_get_browser_topline( dialog_->browser_toc );
151 line = fl_get_browser( dialog_->browser_toc );
153 buffer = lv_->view()->buffer();
155 fl_clear_browser( dialog_->browser_toc );
157 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
158 it != toclist.end(); ++it)
159 fl_add_browser_line( dialog_->browser_toc,
160 (string(4 * (*it).depth, ' ')
161 + (*it).str).c_str());
163 fl_set_browser_topline( dialog_->browser_toc, topline );
164 fl_select_browser_line( dialog_->browser_toc, line );
166 #warning Fix Me! (Lgb)
167 if (!lv_->view()->available()) {
169 fl_clear_browser( dialog_->browser_toc );
170 fl_add_browser_line( dialog_->browser_toc,
171 _("*** No Document ***"));
175 Buffer::Lists tmp = lv_->view()->buffer()->getLists();
177 fl_get_choice_item_text(dialog_->choice_toc_type,
178 fl_get_choice(dialog_->choice_toc_type));
180 Buffer::Lists::iterator it = tmp.find(type);
182 if (it != tmp.end()) {
183 // Check if all elements are the same.
184 if (toclist == it->second) {
187 } else if (it == tmp.end()) {
189 fl_clear_browser(dialog_->browser_toc);
190 fl_add_browser_line(dialog_->browser_toc,
191 _("*** No Lists ***"));
195 // List has changed. Update browser
196 toclist = it->second;
198 static Buffer * buffer = 0;
201 if (buffer == lv_->view()->buffer()) {
202 topline = fl_get_browser_topline(dialog_->browser_toc);
203 line = fl_get_browser( dialog_->browser_toc );
205 buffer = lv_->view()->buffer();
207 fl_clear_browser(dialog_->browser_toc);
209 Buffer::SingleList::const_iterator cit = toclist.begin();
210 Buffer::SingleList::const_iterator end = toclist.end();
212 for (; cit != end; ++cit) {
213 string const line = string(4 * cit->depth, ' ') + cit->str;
214 fl_add_browser_line(dialog_->browser_toc, line.c_str());
217 fl_set_browser_topline(dialog_->browser_toc, topline);
218 fl_select_browser_line(dialog_->browser_toc, line);
223 bool FormToc::input(FL_OBJECT *, long)
227 unsigned int const choice = fl_get_browser( dialog_->browser_toc );
228 if (0 < choice && choice - 1 < toclist.size()) {
229 string const tmp = tostr(toclist[choice-1].par->id());
230 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);