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.
14 #include "ControlToc.h"
24 GToc::GToc(Dialog & parent)
25 : GViewCB<ControlToc, GViewGladeB>(parent, _("Table of Contents"), false)
31 string const gladeName = findGladeFile("toc");
32 xml_ = Gnome::Glade::Xml::create(gladeName);
35 xml_->get_widget("Close", button);
37 xml_->get_widget("Refresh", button);
38 button->signal_clicked().connect(
39 sigc::mem_fun(*this, >oc::updateContents));
41 changing_views_ = true;
43 // For both liststores
44 listCols_.add(listCol_);
45 listCols_.add(listColIndex_);
48 xml_->get_widget("Contents", tocview_);
49 tocstore_ = Gtk::ListStore::create(listCols_);
50 tocview_->set_model(tocstore_);
51 tocview_->append_column("Entry", listCol_);
53 listSel_ = tocview_->get_selection();
54 listSel_->signal_changed().connect(
55 sigc::mem_fun(*this, >oc::onTocViewSelected));
57 // Type Selection Combobox
58 xml_->get_widget("Type", typecombo_);
59 typestore_ = Gtk::ListStore::create(listCols_);
60 typecombo_->set_model(typestore_);
61 Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
62 typecombo_->pack_start(*cell, true);
63 typecombo_->add_attribute(*cell,"text",0);
64 typecombo_->set_size_request(130,-1);
66 typecombo_->signal_changed().connect(
67 sigc::mem_fun(*this, >oc::onTypeComboChanged));
69 changing_views_ = false;
80 void GToc::updateType()
82 changing_views_ = true;
83 string const targettype =
84 toc::getType(controller().params().getCmdName());
87 vector<string> types = controller().getTypes();
89 // Because tiny empty ComboBoxes just look silly
90 int const emptycombosize = 130;
91 typecombo_->set_size_request(types.empty() ? emptycombosize : -1, -1);
93 vector<string>::iterator it = types.begin();
94 vector<string>::iterator end = types.end();
95 for(;it != end; ++it) {
96 Gtk::TreeModel::iterator row = typestore_->append();
97 (*row)[listCol_] = *it;
98 if (*it == targettype)
99 typecombo_->set_active(row);
101 changing_views_ = false;
105 void GToc::updateContents()
107 if (typestore_->children().empty()) {
109 (*tocstore_->append())[listCol_] = _("*** No Lists ***");
110 tocview_->set_sensitive(false);
114 Gtk::TreeModel::iterator it = typecombo_->get_active();
115 Glib::ustring const type = (*it)[listCol_];
116 toc::Toc const contents = controller().getContents(type);
118 // Check if all elements are the same.
119 if (toc_ == contents) {
123 // List has changed, so let's update our view
126 if (contents.empty()) {
128 (*tocstore_->append())[listCol_] = _("*** No Items ***");
129 tocview_->set_sensitive(false);
133 // Okay, we're definitely going to put stuff in now
134 changing_views_ = true;
135 tocview_->set_sensitive(true);
138 toc::Toc::const_iterator cit = contents.begin();
139 toc::Toc::const_iterator end = contents.end();
141 for (int rowindex = 0; cit != end; ++cit, ++rowindex) {
142 Gtk::ListStore::iterator row = tocstore_->append();
143 (*row)[listCol_] = cit->asString();
144 (*row)[listColIndex_] = rowindex;
146 changing_views_ = false;
150 void GToc::onTocViewSelected()
152 // If we always do this, then an item is jumped to without
153 // the user clicking on one when he changes type from TOC->figures or so
154 if (!changing_views_) {
155 unsigned int choice = (*listSel_->get_selected())[listColIndex_];
156 if (choice < toc_.size()) {
157 controller().goTo(toc_[choice]);
163 void GToc::onTypeComboChanged()
169 } // namespace frontend