From ae8999aeba35627e9b85774d5b7ed6d643186de6 Mon Sep 17 00:00:00 2001 From: John Spray Date: Sat, 2 Oct 2004 16:17:21 +0000 Subject: [PATCH] add gtk TOC dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9034 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 5 + src/frontends/gtk/Dialogs.C | 5 +- src/frontends/gtk/GToc.C | 170 ++++++++++++++++++++++++++++ src/frontends/gtk/GToc.h | 61 ++++++++++ src/frontends/gtk/Makefile.am | 3 +- src/frontends/gtk/glade/toc.glade | 181 ++++++++++++++++++++++++++++++ 6 files changed, 422 insertions(+), 3 deletions(-) create mode 100644 src/frontends/gtk/GToc.C create mode 100644 src/frontends/gtk/GToc.h create mode 100644 src/frontends/gtk/glade/toc.glade diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 1b20f19217..4e72283f43 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,8 @@ +2004-10-02 John Spray + + * The Table of Contents dialog + * Dialogs.C, GToc.C, GToc.h, Makefile.am + 2004-09-29 John Spray * The Paragraph dialog diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index c06bcfc8b1..2ad6be6ea6 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -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 const & name) 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())); diff --git a/src/frontends/gtk/GToc.C b/src/frontends/gtk/GToc.C new file mode 100644 index 0000000000..1d60fe402b --- /dev/null +++ b/src/frontends/gtk/GToc.C @@ -0,0 +1,170 @@ +/** + * \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 + +#include "GToc.h" +#include "ControlToc.h" + +#include "ghelpers.h" + +using std::vector; +using std::string; + +namespace lyx { +namespace frontend { + +GToc::GToc(Dialog & parent) + : GViewCB(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::updateContents)); + + 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 types = controller().getTypes(); + + // Because tiny empty ComboBoxes just look silly + int const emptycombosize = 130; + typecombo_->set_size_request(types.empty() ? emptycombosize : -1, -1); + + vector::iterator it = types.begin(); + vector::iterator end = types.end(); + for(;it != end; ++it) { + Gtk::TreeModel::iterator row = typestore_->append(); + (*row)[listCol_] = *it; + if (*it == targettype) + typecombo_->set_active(row); + } + changing_views_ = false; +} + + +void GToc::updateContents() +{ + if (typestore_->children().empty()) { + 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 Items ***"); + 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(); + + for (int rowindex = 0; cit != end; ++cit, ++rowindex) { + Gtk::ListStore::iterator row = tocstore_->append(); + (*row)[listCol_] = cit->asString(); + (*row)[listColIndex_] = 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 diff --git a/src/frontends/gtk/GToc.h b/src/frontends/gtk/GToc.h new file mode 100644 index 0000000000..88c23f3669 --- /dev/null +++ b/src/frontends/gtk/GToc.h @@ -0,0 +1,61 @@ +// -*- 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 { +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_; + Gtk::TreeModelColumn listCol_; + Gtk::TreeModelColumn listColIndex_; + Gtk::TreeModel::ColumnRecord listCols_; + Glib::RefPtr tocstore_; + Glib::RefPtr typestore_; + Glib::RefPtr listSel_; + + toc::Toc toc_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // GTOC_H diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index 6157276489..f7e43aa728 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -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 \ diff --git a/src/frontends/gtk/glade/toc.glade b/src/frontends/gtk/glade/toc.glade new file mode 100644 index 0000000000..a86efad8b4 --- /dev/null +++ b/src/frontends/gtk/glade/toc.glade @@ -0,0 +1,181 @@ + + + + + + + True + Table of Contents + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER_ON_PARENT + False + 400 + 300 + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + True + gtk-refresh + True + GTK_RELIEF_NORMAL + True + 0 + + + + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + True + -7 + + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + False + 0 + + + + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + True + True + + + + + + True + _Type: + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 6 + False + False + + + + + + True + + + 0 + False + False + GTK_PACK_END + + + + + 0 + False + True + + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + False + True + + + + + 6 + True + True + + + + + 0 + True + True + + + + + + + -- 2.39.2