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));
52 dialog_ = build_toc();
53 fl_addto_choice(dialog_->type,
54 _(" TOC | LOF | LOT | LOA "));
58 FL_FORM * const FormToc::form() const
60 if( dialog_ && dialog_->form_toc )
61 return dialog_->form_toc;
67 void FormToc::update()
69 static int ow = -1, oh;
75 fl_set_form_minsize(form(), ow, oh);
76 fl_set_form_maxsize(form(), 2*ow, oh);
81 if( params.getCmdName() == "tableofcontents" )
82 type = Buffer::TOC_TOC;
84 else if( params.getCmdName() == "listofalgorithms" )
85 type = Buffer::TOC_LOA;
87 else if( params.getCmdName() == "listoffigures" )
88 type = Buffer::TOC_LOF;
91 type = Buffer::TOC_LOT;
93 fl_set_choice( dialog_->type, type+1 );
99 void FormToc::updateToc()
101 if (!lv_->view()->available()) {
103 fl_clear_browser( dialog_->browser );
104 fl_add_browser_line( dialog_->browser, _("*** No Document ***"));
108 vector<vector<Buffer::TocItem> > tmp =
109 lv_->view()->buffer()->getTocList();
110 int type = fl_get_choice( dialog_->type ) - 1;
112 // Check if all elements are the same.
113 if (toclist.size() == tmp[type].size()) {
115 for (; i < toclist.size(); ++i) {
116 if (toclist[i] != tmp[type][i])
119 if (i >= toclist.size()) return;
122 // List has changed. Update browser
125 static Buffer * buffer = 0;
128 if (buffer == lv_->view()->buffer()) {
129 topline = fl_get_browser_topline( dialog_->browser );
130 line = fl_get_browser( dialog_->browser );
132 buffer = lv_->view()->buffer();
134 fl_clear_browser( dialog_->browser );
136 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
137 it != toclist.end(); ++it)
138 fl_add_browser_line( dialog_->browser,
139 (string(4*(*it).depth,' ')+(*it).str).c_str());
141 fl_set_browser_topline( dialog_->browser, topline );
142 fl_select_browser_line( dialog_->browser, line );
146 void FormToc::apply()
148 if (!lv_->view()->available())
153 unsigned int choice = fl_get_browser( dialog_->browser );
154 if (0 < choice && choice - 1 < toclist.size()) {
155 lv_->view()->beforeChange();
156 lv_->view()->text->SetCursor( lv_->view(), toclist[choice-1].par, 0 );
157 lv_->view()->text->sel_cursor =
158 lv_->view()->text->cursor;
159 lv_->view()->update(BufferView::SELECT|BufferView::FITCUR);