Hi, Attached: GTK+ Table of Contents dialog. Let the code critique begin! :-)
John
Index: Makefile.am =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/Makefile.am,v retrieving revision 1.20 diff -u -3 -p -r1.20 Makefile.am --- Makefile.am 2004/10/01 18:59:36 1.20 +++ Makefile.am 2004/10/02 13:27:43 @@ -52,6 +52,8 @@ libgtk_la_SOURCES = \ GText.h \ GTimeout.C \ GTimeout.h \ + GToc.C \ + GToc.h \ GToolbar.C \ GToolbar.h \ GUrl.C \ @@ -122,7 +124,6 @@ xforms_objects = \ ../xforms/FormTexinfo.lo \ ../xforms/FormText.lo \ ../xforms/FormThesaurus.lo \ - ../xforms/FormToc.lo \ ../xforms/FormVSpace.lo \ ../xforms/FormWrap.lo \ ../xforms/freebrowser.lo \ Index: Dialogs.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/Dialogs.C,v retrieving revision 1.22 diff -u -3 -p -r1.22 Dialogs.C --- Dialogs.C 2004/10/01 18:59:36 1.22 +++ Dialogs.C 2004/10/02 13:27:44 @@ -85,7 +85,7 @@ #include "FormShowFile.h" #include "FormSpellchecker.h" #include "GTableCreate.h" -#include "FormToc.h" +#include "GToc.h" #include "GUrl.h" #include "FormVSpace.h" #include "FormWrap.h" @@ -501,8 +501,9 @@ Dialogs::DialogPtr Dialogs::build(string dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); #endif } else if (name == "toc") { + dialog->bc().view(new GBC(dialog->bc())); dialog->setController(new ControlToc(*dialog)); - dialog->setView(new FormToc(*dialog)); + dialog->setView(new GToc(*dialog)); dialog->bc().bp(new OkCancelPolicy); } else if (name == "url") { dialog->bc().view(new GBC(dialog->bc())); Index: ChangeLog =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/ChangeLog,v retrieving revision 1.64 diff -u -3 -p -r1.64 ChangeLog --- ChangeLog 2004/10/01 18:59:36 1.64 +++ ChangeLog 2004/10/02 13:27:44 @@ -1,3 +1,8 @@ +2004-10-02 John Spray <[EMAIL PROTECTED]> + + * The Table of Contents dialog + * Dialogs.C, GToc.C, GToc.h, Makefile.am + 2004-09-29 John Spray <[EMAIL PROTECTED]> * The Paragraph dialog
/** * \file GToc.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author John Spray * * Full author contact details are available in file CREDITS. */ #include <config.h> #include "GToc.h" #include "ControlToc.h" #include "ghelpers.h" using std::vector; using std::string; namespace lyx { namespace frontend { GToc::GToc(Dialog & parent) : GViewCB<ControlToc, GViewGladeB>(parent, _("Table of Contents"), false) {} void GToc::doBuild() { string const gladeName = findGladeFile("toc"); xml_ = Gnome::Glade::Xml::create(gladeName); Gtk::Button * button; xml_->get_widget("Close", button); setCancel(button); xml_->get_widget("Refresh", button); button->signal_clicked().connect( sigc::mem_fun(*this, >oc::update)); changing_views_ = true; // For both liststores listCols_.add(listCol_); listCols_.add(listColIndex_); // TOC ListView xml_->get_widget("Contents", tocview_); tocstore_ = Gtk::ListStore::create(listCols_); tocview_->set_model(tocstore_); tocview_->append_column("Entry", listCol_); listSel_ = tocview_->get_selection(); listSel_->signal_changed().connect( sigc::mem_fun(*this, >oc::onTocViewSelected)); // Type Selection Combobox xml_->get_widget("Type", typecombo_); typestore_ = Gtk::ListStore::create(listCols_); typecombo_->set_model(typestore_); Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText); typecombo_->pack_start(*cell, true); typecombo_->add_attribute(*cell,"text",0); typecombo_->set_size_request(130,-1); typecombo_->signal_changed().connect( sigc::mem_fun(*this, >oc::onTypeComboChanged)); changing_views_ = false; } void GToc::update() { updateType(); updateContents(); } void GToc::updateType() { changing_views_ = true; string const targettype = toc::getType(controller().params().getCmdName()); typestore_->clear(); vector<string> types = controller().getTypes(); vector<string>::iterator it = types.begin(); vector<string>::iterator end = types.end(); int rowindex = 0; for(;it != end; ++it) { Gtk::TreeModel::iterator row = typestore_->append(); (*row)[listCol_] = *it; if (*it == targettype) typecombo_->set_active(rowindex); ++rowindex; } typelistempty_ = rowindex ? false : true; // Because tiny empty ComboBoxes just look silly typecombo_->set_size_request(typelistempty_ ? 130 : -1, -1); changing_views_ = false; } void GToc::updateContents() { if (typelistempty_) { tocstore_->clear(); (*tocstore_->append())[listCol_] = "*** No Lists ***"; tocview_->set_sensitive(false); return; } Gtk::TreeModel::iterator it = typecombo_->get_active(); Glib::ustring const type = (*it)[listCol_]; toc::Toc const contents = controller().getContents(type); // Check if all elements are the same. if (toc_ == contents) { return; } // List has changed, so let's update our view toc_ = contents; if (contents.empty()) { tocstore_->clear(); (*tocstore_->append())[listCol_] = "*** No Lists ***"; tocview_->set_sensitive(false); return; } // Okay, we're definitely going to put stuff in now changing_views_ = true; tocview_->set_sensitive(true); tocstore_->clear(); toc::Toc::const_iterator cit = contents.begin(); toc::Toc::const_iterator end = contents.end(); int rowindex = 0; for (; cit != end; ++cit) { Gtk::ListStore::iterator row = tocstore_->append(); (*row)[listCol_] = cit->asString(); (*row)[listColIndex_] = rowindex; ++rowindex; } changing_views_ = false; } void GToc::onTocViewSelected() { // If we always do this, then an item is jumped to without // the user clicking on one when he changes type from TOC->figures or so if (!changing_views_) { unsigned int choice = (*listSel_->get_selected())[listColIndex_]; if (choice < toc_.size()) { controller().goTo(toc_[choice]); } } } void GToc::onTypeComboChanged() { updateContents(); } } // namespace frontend } // namespace lyx
// -*- C++ -*- /** * \file GToc.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author John Spray * * Full author contact details are available in file CREDITS. */ #ifndef GTOC_H #define GTOC_H #include "GViewBase.h" #include "toc.h" namespace lyx { namespace frontend { class ControlToc; /** This class provides a GTK+ implementation of the Toc Dialog. */ class GToc : public GViewCB<ControlToc, GViewGladeB> { public: /// GToc(Dialog &); private: /// not needed virtual void apply() {} /// Build the dialog virtual void doBuild(); /// Update dialog virtual void update(); void updateType(); void updateContents(); void onTocViewSelected(); void onTypeComboChanged(); // Makes TocViewSelected ignore events bool changing_views_; Gtk::TreeView * tocview_; Gtk::ComboBox * typecombo_; bool typelistempty_; Gtk::TreeModelColumn<Glib::ustring> listCol_; Gtk::TreeModelColumn<unsigned int> listColIndex_; Gtk::TreeModel::ColumnRecord listCols_; Glib::RefPtr<Gtk::ListStore> tocstore_; Glib::RefPtr<Gtk::ListStore> typestore_; Glib::RefPtr<Gtk::TreeSelection> listSel_; toc::Toc toc_; }; } // namespace frontend } // namespace lyx #endif // GTOC_H
toc.glade
Description: application/glade