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
29 FormToc::FormToc(LyXView * lv, Dialogs * d)
30 : FormCommand(lv, d, _("Table of Contents")), dialog_(0)
32 // let the dialog be shown
33 // These are permanent connections so we won't bother
34 // storing a copy because we won't be disconnecting.
35 d->showTOC.connect(slot(this, &FormToc::showInset));
36 d->createTOC.connect(slot(this, &FormToc::createInset));
47 void FormToc::clearStore()
55 dialog_ = build_toc();
56 fl_addto_choice(dialog_->type,
57 _(" TOC | LOF | LOT | LOA "));
59 // Don't need to limit size of this dialog
63 FL_FORM * const FormToc::form() const
65 if( dialog_ ) // no need to test for dialog_->form_toc
66 return dialog_->form_toc;
72 void FormToc::update()
76 if( params.getCmdName() == "tableofcontents" )
77 type = Buffer::TOC_TOC;
79 else if( params.getCmdName() == "listofalgorithms" )
80 type = Buffer::TOC_LOA;
82 else if( params.getCmdName() == "listoffigures" )
83 type = Buffer::TOC_LOF;
86 type = Buffer::TOC_LOT;
88 fl_set_choice( dialog_->type, type+1 );
94 void FormToc::updateToc()
96 if (!lv_->view()->available()) {
98 fl_clear_browser( dialog_->browser );
99 fl_add_browser_line( dialog_->browser, _("*** No Document ***"));
103 vector<vector<Buffer::TocItem> > tmp =
104 lv_->view()->buffer()->getTocList();
105 int type = fl_get_choice( dialog_->type ) - 1;
107 // Check if all elements are the same.
108 if (toclist.size() == tmp[type].size()) {
110 for (; i < toclist.size(); ++i) {
111 if (toclist[i] != tmp[type][i])
114 if (i >= toclist.size()) return;
117 // List has changed. Update browser
120 static Buffer * buffer = 0;
123 if (buffer == lv_->view()->buffer()) {
124 topline = fl_get_browser_topline( dialog_->browser );
125 line = fl_get_browser( dialog_->browser );
127 buffer = lv_->view()->buffer();
129 fl_clear_browser( dialog_->browser );
131 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
132 it != toclist.end(); ++it)
133 fl_add_browser_line( dialog_->browser,
134 (string(4*(*it).depth,' ')+(*it).str).c_str());
136 fl_set_browser_topline( dialog_->browser, topline );
137 fl_select_browser_line( dialog_->browser, line );
141 void FormToc::apply()
143 if (!lv_->view()->available())
148 unsigned int choice = fl_get_browser( dialog_->browser );
149 if (0 < choice && choice - 1 < toclist.size()) {
150 lv_->view()->beforeChange();
151 lv_->view()->text->SetCursor( lv_->view(), toclist[choice-1].par, 0 );
152 lv_->view()->text->sel_cursor =
153 lv_->view()->text->cursor;
154 lv_->view()->update(BufferView::SELECT|BufferView::FITCUR);