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, _("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();
103 for(;it != end; ++it) {
104 Gtk::TreeModel::iterator row = typestore_->append();
105 (*row)[listCol_] = *it;
106 if (*it == targettype)
107 typecombo_->set_active(row);
109 changing_views_ = false;
113 void GToc::updateContents()
115 if (typestore_->children().empty()) {
117 (*tocstore_->append())[listCol_] = _("*** No Lists ***");
118 tocview_->set_sensitive(false);
122 Gtk::TreeModel::iterator it = typecombo_->get_active();
123 Glib::ustring const type = (*it)[listCol_];
124 toc::Toc const contents = controller().getContents(type);
126 // Check if all elements are the same.
127 if (toc_ == contents) {
131 // List has changed, so let's update our view
134 if (contents.empty()) {
136 (*tocstore_->append())[listCol_] = _("*** No Items ***");
137 tocview_->set_sensitive(false);
141 // Okay, we're definitely going to put stuff in now
142 changing_views_ = true;
143 tocview_->set_sensitive(true);
146 toc::Toc::const_iterator cit = contents.begin();
147 toc::Toc::const_iterator end = contents.end();
149 for (int rowindex = 0; cit != end; ++cit, ++rowindex) {
150 Gtk::ListStore::iterator row = tocstore_->append();
151 (*row)[listCol_] = cit->asString();
152 (*row)[listColIndex_] = rowindex;
154 changing_views_ = false;
158 void GToc::onTocViewSelected()
160 // If we always do this, then an item is jumped to without
161 // the user clicking on one when he changes type from TOC->figures or so
162 if (!changing_views_) {
163 unsigned int choice = (*listSel_->get_selected())[listColIndex_];
164 if (choice < toc_.size()) {
165 controller().goTo(toc_[choice]);
171 void GToc::onTypeComboChanged()
178 } // namespace frontend