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
30 static vector<Buffer::TocItem> toclist;
32 FormToc::FormToc(LyXView * lv, Dialogs * d)
33 : FormCommand(lv, d, _("Table of Contents")), dialog_(0)
35 // let the dialog be shown
36 // These are permanent connections so we won't bother
37 // storing a copy because we won't be disconnecting.
38 d->showTOC.connect(slot(this, &FormToc::showInset));
39 d->createTOC.connect(slot(this, &FormToc::createInset));
49 void FormToc::clearStore()
57 dialog_ = build_toc();
58 fl_addto_choice(dialog_->type,
59 _(" TOC | LOF | LOT | LOA "));
63 FL_FORM * const FormToc::form() const
65 if( dialog_ && dialog_->form_toc )
66 return dialog_->form_toc;
72 void FormToc::update()
74 static int ow = -1, oh;
80 fl_set_form_minsize(form(), ow, oh);
81 fl_set_form_maxsize(form(), 2*ow, oh);
86 if( params.getCmdName() == "tableofcontents" )
87 type = Buffer::TOC_TOC;
89 else if( params.getCmdName() == "listofalgorithms" )
90 type = Buffer::TOC_LOA;
92 else if( params.getCmdName() == "listoffigures" )
93 type = Buffer::TOC_LOF;
96 type = Buffer::TOC_LOT;
98 fl_set_choice( dialog_->type, type+1 );
104 void FormToc::updateToc()
106 if (!lv_->view()->available()) {
108 fl_clear_browser( dialog_->browser );
109 fl_add_browser_line( dialog_->browser, _("*** 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,' ')+(*it).str).c_str());
146 fl_set_browser_topline( dialog_->browser, topline );
147 fl_select_browser_line( dialog_->browser, line );
151 void FormToc::apply()
153 if (!lv_->view()->available())
158 unsigned int choice = fl_get_browser( dialog_->browser );
159 if (0 < choice && choice - 1 < toclist.size()) {
160 lv_->view()->beforeChange();
161 lv_->view()->text->SetCursor( lv_->view(), toclist[choice-1].par, 0 );
162 lv_->view()->text->sel_cursor =
163 lv_->view()->text->cursor;
164 lv_->view()->update(BufferView::SELECT|BufferView::FITCUR);