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 IgnorantPolicy),
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();
70 fl_addto_choice(dialog_->type,
71 _(" TOC | LOF | LOT | LOA "));
73 // Don't need to limit size of this dialog
74 // (but fixing min size is a GOOD thing).
75 // Workaround dumb xforms sizing bug
81 void FormToc::update()
85 if ( params.getCmdName() == "tableofcontents" )
86 type = Buffer::TOC_TOC;
88 else if ( params.getCmdName() == "listofalgorithms" )
89 type = Buffer::TOC_LOA;
91 else if ( params.getCmdName() == "listoffigures" )
92 type = Buffer::TOC_LOF;
95 type = Buffer::TOC_LOT;
97 fl_set_choice( dialog_->type, type+1 );
103 void FormToc::updateToc()
105 if (!lv_->view()->available()) {
107 fl_clear_browser( dialog_->browser );
108 fl_add_browser_line( dialog_->browser,
109 _("*** No Document ***"));
113 vector<vector<Buffer::TocItem> > tmp =
114 lv_->view()->buffer()->getTocList();
115 int type = fl_get_choice( dialog_->type ) - 1;
117 // Check if all elements are the same.
118 if (toclist.size() == tmp[type].size()) {
120 for (; i < toclist.size(); ++i) {
121 if (toclist[i] != tmp[type][i])
124 if (i >= toclist.size()) return;
127 // List has changed. Update browser
130 static Buffer * buffer = 0;
133 if (buffer == lv_->view()->buffer()) {
134 topline = fl_get_browser_topline( dialog_->browser );
135 line = fl_get_browser( dialog_->browser );
137 buffer = lv_->view()->buffer();
139 fl_clear_browser( dialog_->browser );
141 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
142 it != toclist.end(); ++it)
143 fl_add_browser_line( dialog_->browser,
144 (string(4 * (*it).depth, ' ')
145 + (*it).str).c_str());
147 fl_set_browser_topline( dialog_->browser, topline );
148 fl_select_browser_line( dialog_->browser, line );
152 void FormToc::apply()
154 if (!lv_->view()->available())
159 unsigned int const choice = fl_get_browser( dialog_->browser );
160 if (0 < choice && choice - 1 < toclist.size()) {
161 string const tmp = tostr(toclist[choice-1].par->id());
162 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);