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 #include "support/lstrings.h"
31 FormToc::FormToc(LyXView * lv, Dialogs * d)
32 : FormCommand(lv, d, _("Table of Contents")), dialog_(0)
34 // let the dialog be shown
35 // These are permanent connections so we won't bother
36 // storing a copy because we won't be disconnecting.
37 d->showTOC.connect(slot(this, &FormToc::showInset));
38 d->createTOC.connect(slot(this, &FormToc::createInset));
48 void FormToc::clearStore()
56 dialog_ = build_toc();
57 fl_addto_choice(dialog_->type,
58 _(" TOC | LOF | LOT | LOA "));
60 // Don't need to limit size of this dialog
64 FL_FORM * const FormToc::form() const
66 if ( dialog_ ) // no need to test for dialog_->form
73 void FormToc::update()
77 if( params.getCmdName() == "tableofcontents" )
78 type = Buffer::TOC_TOC;
80 else if( params.getCmdName() == "listofalgorithms" )
81 type = Buffer::TOC_LOA;
83 else if( params.getCmdName() == "listoffigures" )
84 type = Buffer::TOC_LOF;
87 type = Buffer::TOC_LOT;
89 fl_set_choice( dialog_->type, type+1 );
95 void FormToc::updateToc()
97 if (!lv_->view()->available()) {
99 fl_clear_browser( dialog_->browser );
100 fl_add_browser_line( dialog_->browser, _("*** No Document ***"));
104 vector<vector<Buffer::TocItem> > tmp =
105 lv_->view()->buffer()->getTocList();
106 int type = fl_get_choice( dialog_->type ) - 1;
108 // Check if all elements are the same.
109 if (toclist.size() == tmp[type].size()) {
111 for (; i < toclist.size(); ++i) {
112 if (toclist[i] != tmp[type][i])
115 if (i >= toclist.size()) return;
118 // List has changed. Update browser
121 static Buffer * buffer = 0;
124 if (buffer == lv_->view()->buffer()) {
125 topline = fl_get_browser_topline( dialog_->browser );
126 line = fl_get_browser( dialog_->browser );
128 buffer = lv_->view()->buffer();
130 fl_clear_browser( dialog_->browser );
132 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
133 it != toclist.end(); ++it)
134 fl_add_browser_line( dialog_->browser,
135 (string(4*(*it).depth,' ')+(*it).str).c_str());
137 fl_set_browser_topline( dialog_->browser, topline );
138 fl_select_browser_line( dialog_->browser, line );
142 void FormToc::apply()
144 if (!lv_->view()->available())
149 unsigned int choice = fl_get_browser( dialog_->browser );
150 if (0 < choice && choice - 1 < toclist.size()) {
151 string tmp = tostr(toclist[choice-1].par->id());
152 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp.c_str());