3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
22 #include "ControlToc.h"
32 GToc::GToc(Dialog & parent)
33 : GViewCB<ControlToc, GViewGladeB>(parent, lyx::to_utf8(_("Table of Contents")), false)
39 string const gladeName = findGladeFile("toc");
40 xml_ = Gnome::Glade::Xml::create(gladeName);
43 xml_->get_widget("Close", button);
45 xml_->get_widget("Refresh", button);
46 button->signal_clicked().connect(
47 sigc::mem_fun(*this, >oc::updateContents));
49 changing_views_ = true;
51 // For both liststores
52 listCols_.add(listCol_);
53 listCols_.add(listColIndex_);
56 xml_->get_widget("Contents", tocview_);
57 tocstore_ = Gtk::ListStore::create(listCols_);
58 tocview_->set_model(tocstore_);
59 tocview_->append_column("Entry", listCol_);
61 listSel_ = tocview_->get_selection();
62 listSel_->signal_changed().connect(
63 sigc::mem_fun(*this, >oc::onTocViewSelected));
65 // Type Selection Combobox
66 xml_->get_widget("Type", typecombo_);
67 typestore_ = Gtk::ListStore::create(listCols_);
68 typecombo_->set_model(typestore_);
69 Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
70 typecombo_->pack_start(*cell, true);
71 typecombo_->add_attribute(*cell,"text",0);
72 typecombo_->set_size_request(130,-1);
74 typecombo_->signal_changed().connect(
75 sigc::mem_fun(*this, >oc::onTypeComboChanged));
77 changing_views_ = false;
88 void GToc::updateType()
90 changing_views_ = true;
91 string const targettype =
92 toc::getType(controller().params().getCmdName());
95 vector<string> types = controller().getTypes();
97 // Because tiny empty ComboBoxes just look silly
98 int const emptycombosize = 130;
99 typecombo_->set_size_request(types.empty() ? emptycombosize : -1, -1);
101 vector<string>::iterator it = types.begin();
102 vector<string>::iterator end = types.end();
104 for(;it != end; ++it) {
105 string const & guiname = controller().getGuiName(*it);
106 Gtk::TreeModel::iterator row = typestore_->append();
107 (*row)[listCol_] = guiname;
108 (*row)[listColIndex_] = index;
111 if (*it == targettype)
112 typecombo_->set_active(row);
114 changing_views_ = false;
118 void GToc::updateContents()
120 if (typestore_->children().empty()) {
122 (*tocstore_->append())[listCol_] = lyx::to_utf8(_("*** No Lists ***"));
123 tocview_->set_sensitive(false);
127 Gtk::TreeModel::iterator it = typecombo_->get_active();
128 vector<string> const & choice = controller().getTypes();
132 type = choice[(*it)[listColIndex_]];
133 toc::Toc const contents = controller().getContents(type);
135 // Check if all elements are the same.
136 if (toc_ == contents) {
140 // List has changed, so let's update our view
143 if (contents.empty()) {
145 (*tocstore_->append())[listCol_] = lyx::to_utf8(_("*** No Items ***"));
146 tocview_->set_sensitive(false);
150 // Okay, we're definitely going to put stuff in now
151 changing_views_ = true;
152 tocview_->set_sensitive(true);
155 toc::Toc::const_iterator cit = contents.begin();
156 toc::Toc::const_iterator end = contents.end();
158 for (int rowindex = 0; cit != end; ++cit, ++rowindex) {
159 Gtk::ListStore::iterator row = tocstore_->append();
160 (*row)[listCol_] = cit->asString();
161 (*row)[listColIndex_] = rowindex;
163 changing_views_ = false;
167 void GToc::onTocViewSelected()
169 // If we always do this, then an item is jumped to without
170 // the user clicking on one when he changes type from TOC->figures or so
171 if (!changing_views_) {
172 unsigned int choice = (*listSel_->get_selected())[listColIndex_];
173 if (choice < toc_.size()) {
174 controller().goTo(toc_[choice]);
180 void GToc::onTypeComboChanged()
187 } // namespace frontend