4 * John Levon, moz@compsoc.man.ac.uk
7 /***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 ***************************************************************************/
18 #include "formtocdialog.h"
24 #include "support/lstrings.h"
25 #include "QtLyXView.h"
32 FormToc::FormToc(LyXView *v, Dialogs *d)
33 : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0),
34 toclist(0), type(Buffer::TOC_TOC)
36 // let the dialog be shown
37 // This is a permanent connection so we won't bother
38 // storing a copy because we won't be disconnecting.
39 d->showTOC.connect(slot(this, &FormToc::showTOC));
40 d->createTOC.connect(slot(this, &FormToc::createTOC));
48 void FormToc::showTOC(InsetCommand * const inset)
50 // FIXME: when could inset be 0 here ?
55 ih_ = inset_->hide.connect(slot(this,&FormToc::hide));
56 params = inset->params();
61 void FormToc::createTOC(string const & arg)
66 params.setFromString(arg);
70 void FormToc::updateToc()
72 if (!lv_->view()->available()) {
74 dialog_->tree->clear();
78 vector< vector<Buffer::TocItem> > tmp =
79 lv_->view()->buffer()->getTocList();
81 // Check if all elements are the same.
82 if (toclist.size() == tmp[type].size()) {
84 for (; i < toclist.size(); ++i) {
85 if (toclist[i] != tmp[type][i])
88 if (i >= toclist.size())
94 dialog_->tree->clear();
97 // FIXME: should do hierarchically. at each point we need to know
98 // id of item we've just inserted, id of most recent sibling, and
101 dialog_->tree->setAutoUpdate(false);
102 for (vector< Buffer::TocItem >::const_iterator iter = toclist.begin();
103 iter != toclist.end(); ++iter) {
104 dialog_->tree->insertItem((string(4*(*iter).depth,' ')+(*iter).str).c_str(), 0, -1, false);
106 dialog_->tree->setAutoUpdate(true);
107 dialog_->tree->update();
110 void FormToc::setType(Buffer::TocType toctype)
114 case Buffer::TOC_TOC:
115 dialog_->setCaption(_("Table of Contents"));
117 case Buffer::TOC_LOF:
118 dialog_->setCaption(_("List of Figures"));
120 case Buffer::TOC_LOT:
121 dialog_->setCaption(_("List of Tables"));
123 case Buffer::TOC_LOA:
124 dialog_->setCaption(_("List of Algorithms"));
129 void FormToc::update()
131 if (params.getCmdName()=="tableofcontents") {
132 setType(Buffer::TOC_TOC);
133 dialog_->menu->setCurrentItem(0);
134 } else if (params.getCmdName()=="listoffigures") {
135 setType(Buffer::TOC_LOF);
136 dialog_->menu->setCurrentItem(1);
137 } else if (params.getCmdName()=="listoftables") {
138 setType(Buffer::TOC_LOT);
139 dialog_->menu->setCurrentItem(2);
141 setType(Buffer::TOC_LOA);
142 dialog_->menu->setCurrentItem(3);
148 void FormToc::highlight(int index)
150 if (!lv_->view()->available())
153 // FIXME: frontStrip can go once it's hierarchical
154 string tmp(frontStrip(dialog_->tree->itemAt(index)->getText(),' '));
156 vector <Buffer::TocItem>::const_iterator iter = toclist.begin();
157 for (; iter != toclist.end(); ++iter) {
162 if (iter==toclist.end()) {
163 lyxerr[Debug::GUI] << "Couldn't find highlighted TOC entry : " << tmp << endl;
167 lv_->getLyXFunc()->Dispatch(LFUN_GOTO_PARAGRAPH, tostr(iter->par->id()).c_str());
170 void FormToc::set_type(Buffer::TocType toctype)
182 dialog_ = new FormTocDialog(this, 0, _("LyX: Table of Contents"), false);
184 if (!dialog_->isVisible()) {
185 h_ = d_->hideBufferDependent.connect(slot(this, &FormToc::hide));
186 u_ = d_->updateBufferDependent.connect(slot(this, &FormToc::update));
190 dialog_->setActiveWindow();
196 void FormToc::close()