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));
46 void FormToc::clearStore()
54 dialog_ = build_toc();
55 fl_addto_choice(dialog_->type,
56 _(" TOC | LOF | LOT | LOA "));
58 // Don't need to limit size of this dialog
62 FL_FORM * const FormToc::form() const
64 if ( dialog_ ) // no need to test for dialog_->form
71 void FormToc::update()
75 if( params.getCmdName() == "tableofcontents" )
76 type = Buffer::TOC_TOC;
78 else if( params.getCmdName() == "listofalgorithms" )
79 type = Buffer::TOC_LOA;
81 else if( params.getCmdName() == "listoffigures" )
82 type = Buffer::TOC_LOF;
85 type = Buffer::TOC_LOT;
87 fl_set_choice( dialog_->type, type+1 );
93 void FormToc::updateToc()
95 if (!lv_->view()->available()) {
97 fl_clear_browser( dialog_->browser );
98 fl_add_browser_line( dialog_->browser, _("*** No Document ***"));
102 vector<vector<Buffer::TocItem> > tmp =
103 lv_->view()->buffer()->getTocList();
104 int type = fl_get_choice( dialog_->type ) - 1;
106 // Check if all elements are the same.
107 if (toclist.size() == tmp[type].size()) {
109 for (; i < toclist.size(); ++i) {
110 if (toclist[i] != tmp[type][i])
113 if (i >= toclist.size()) return;
116 // List has changed. Update browser
119 static Buffer * buffer = 0;
122 if (buffer == lv_->view()->buffer()) {
123 topline = fl_get_browser_topline( dialog_->browser );
124 line = fl_get_browser( dialog_->browser );
126 buffer = lv_->view()->buffer();
128 fl_clear_browser( dialog_->browser );
130 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
131 it != toclist.end(); ++it)
132 fl_add_browser_line( dialog_->browser,
133 (string(4*(*it).depth,' ')+(*it).str).c_str());
135 fl_set_browser_topline( dialog_->browser, topline );
136 fl_select_browser_line( dialog_->browser, line );
140 void FormToc::apply()
142 if (!lv_->view()->available())
147 unsigned int choice = fl_get_browser( dialog_->browser );
148 if (0 < choice && choice - 1 < toclist.size()) {
149 lv_->view()->beforeChange();
150 lv_->view()->text->SetCursor( lv_->view(), toclist[choice-1].par, 0 );
151 lv_->view()->text->sel_cursor =
152 lv_->view()->text->cursor;
153 lv_->view()->update(BufferView::SELECT|BufferView::FITCUR);