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
28 #include "support/lstrings.h"
30 FormToc::FormToc(LyXView * lv, Dialogs * d)
31 : FormCommand(lv, d, _("Table of Contents")), dialog_(0)
33 // let the dialog be shown
34 // These are permanent connections so we won't bother
35 // storing a copy because we won't be disconnecting.
36 d->showTOC.connect(slot(this, &FormToc::showInset));
37 d->createTOC.connect(slot(this, &FormToc::createInset));
47 FL_FORM * FormToc::form() const
49 if ( dialog_ ) return dialog_->form;
54 void FormToc::clearStore()
62 dialog_ = build_toc();
63 fl_addto_choice(dialog_->type,
64 _(" TOC | LOF | LOT | LOA "));
66 // Don't need to limit size of this dialog
70 void FormToc::update()
74 if ( params.getCmdName() == "tableofcontents" )
75 type = Buffer::TOC_TOC;
77 else if ( params.getCmdName() == "listofalgorithms" )
78 type = Buffer::TOC_LOA;
80 else if ( params.getCmdName() == "listoffigures" )
81 type = Buffer::TOC_LOF;
84 type = Buffer::TOC_LOT;
86 fl_set_choice( dialog_->type, type+1 );
92 void FormToc::updateToc()
94 if (!lv_->view()->available()) {
96 fl_clear_browser( dialog_->browser );
97 fl_add_browser_line( dialog_->browser, _("*** No Document ***"));
101 vector<vector<Buffer::TocItem> > tmp =
102 lv_->view()->buffer()->getTocList();
103 int type = fl_get_choice( dialog_->type ) - 1;
105 // Check if all elements are the same.
106 if (toclist.size() == tmp[type].size()) {
108 for (; i < toclist.size(); ++i) {
109 if (toclist[i] != tmp[type][i])
112 if (i >= toclist.size()) return;
115 // List has changed. Update browser
118 static Buffer * buffer = 0;
121 if (buffer == lv_->view()->buffer()) {
122 topline = fl_get_browser_topline( dialog_->browser );
123 line = fl_get_browser( dialog_->browser );
125 buffer = lv_->view()->buffer();
127 fl_clear_browser( dialog_->browser );
129 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
130 it != toclist.end(); ++it)
131 fl_add_browser_line( dialog_->browser,
132 (string(4*(*it).depth,' ')+(*it).str).c_str());
134 fl_set_browser_topline( dialog_->browser, topline );
135 fl_select_browser_line( dialog_->browser, line );
139 void FormToc::apply()
141 if (!lv_->view()->available())
146 unsigned int const choice = fl_get_browser( dialog_->browser );
147 if (0 < choice && choice - 1 < toclist.size()) {
148 string const tmp = tostr(toclist[choice-1].par->id());
149 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tmp);