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 _GLIBCPP_CONCEPT_CHECKS
15 #undef _GLIBCPP_CONCEPT_CHECKS
19 #include "ControlToc.h"
29 GToc::GToc(Dialog & parent)
30 : GViewCB<ControlToc, GViewGladeB>(parent, _("Table of Contents"), false)
36 string const gladeName = findGladeFile("toc");
37 xml_ = Gnome::Glade::Xml::create(gladeName);
40 xml_->get_widget("Close", button);
42 xml_->get_widget("Refresh", button);
43 button->signal_clicked().connect(
44 sigc::mem_fun(*this, >oc::updateContents));
46 changing_views_ = true;
48 // For both liststores
49 listCols_.add(listCol_);
50 listCols_.add(listColIndex_);
53 xml_->get_widget("Contents", tocview_);
54 tocstore_ = Gtk::ListStore::create(listCols_);
55 tocview_->set_model(tocstore_);
56 tocview_->append_column("Entry", listCol_);
58 listSel_ = tocview_->get_selection();
59 listSel_->signal_changed().connect(
60 sigc::mem_fun(*this, >oc::onTocViewSelected));
62 // Type Selection Combobox
63 xml_->get_widget("Type", typecombo_);
64 typestore_ = Gtk::ListStore::create(listCols_);
65 typecombo_->set_model(typestore_);
66 Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
67 typecombo_->pack_start(*cell, true);
68 typecombo_->add_attribute(*cell,"text",0);
69 typecombo_->set_size_request(130,-1);
71 typecombo_->signal_changed().connect(
72 sigc::mem_fun(*this, >oc::onTypeComboChanged));
74 changing_views_ = false;
85 void GToc::updateType()
87 changing_views_ = true;
88 string const targettype =
89 toc::getType(controller().params().getCmdName());
92 vector<string> types = controller().getTypes();
94 // Because tiny empty ComboBoxes just look silly
95 int const emptycombosize = 130;
96 typecombo_->set_size_request(types.empty() ? emptycombosize : -1, -1);
98 vector<string>::iterator it = types.begin();
99 vector<string>::iterator end = types.end();
100 for(;it != end; ++it) {
101 Gtk::TreeModel::iterator row = typestore_->append();
102 (*row)[listCol_] = *it;
103 if (*it == targettype)
104 typecombo_->set_active(row);
106 changing_views_ = false;
110 void GToc::updateContents()
112 if (typestore_->children().empty()) {
114 (*tocstore_->append())[listCol_] = _("*** No Lists ***");
115 tocview_->set_sensitive(false);
119 Gtk::TreeModel::iterator it = typecombo_->get_active();
120 Glib::ustring const type = (*it)[listCol_];
121 toc::Toc const contents = controller().getContents(type);
123 // Check if all elements are the same.
124 if (toc_ == contents) {
128 // List has changed, so let's update our view
131 if (contents.empty()) {
133 (*tocstore_->append())[listCol_] = _("*** No Items ***");
134 tocview_->set_sensitive(false);
138 // Okay, we're definitely going to put stuff in now
139 changing_views_ = true;
140 tocview_->set_sensitive(true);
143 toc::Toc::const_iterator cit = contents.begin();
144 toc::Toc::const_iterator end = contents.end();
146 for (int rowindex = 0; cit != end; ++cit, ++rowindex) {
147 Gtk::ListStore::iterator row = tocstore_->append();
148 (*row)[listCol_] = cit->asString();
149 (*row)[listColIndex_] = rowindex;
151 changing_views_ = false;
155 void GToc::onTocViewSelected()
157 // If we always do this, then an item is jumped to without
158 // the user clicking on one when he changes type from TOC->figures or so
159 if (!changing_views_) {
160 unsigned int choice = (*listSel_->get_selected())[listColIndex_];
161 if (choice < toc_.size()) {
162 controller().goTo(toc_[choice]);
168 void GToc::onTypeComboChanged()
175 } // namespace frontend