Hey all, I changed a lot of the things that where brought up. No instant apply anymore, and the jumpto/back buttons get reset when selecting another label from the list. I changed the glade file, too. The main reason for not using patches in this post is, that this version is a major restructuring of code, and probably all changes someone else may have done to my code wouldn't work anymore with the patch either. Same for the glade file.
Greetings, Andreas
/** * \file GNote.C * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author John Spray * \author Andreas Klostermann * Full author contact details are available in file CREDITS. */ #include <config.h> // Too hard to make concept checks work with this file #ifdef _GLIBCXX_CONCEPT_CHECKS #undef _GLIBCXX_CONCEPT_CHECKS #endif #ifdef _GLIBCPP_CONCEPT_CHECKS #undef _GLIBCPP_CONCEPT_CHECKS #endif #include "GRef.h" #include "ControlRef.h" #include "ghelpers.h" #include "insets/insetref.h" #include "debug.h" #include "buffer.h" #include "insets/insetnote.h" #include <libglademm.h> using std::string; using std::vector; namespace lyx { namespace frontend { class refModelColumns : public Gtk::TreeModel::ColumnRecord { public: refModelColumns() { add(name);} Gtk::TreeModelColumn<Glib::ustring> name; }; refModelColumns refColumns; class bufferModelColumns : public Gtk::TreeModel::ColumnRecord { public: bufferModelColumns() { add(name);} Gtk::TreeModelColumn<Glib::ustring> name; }; bufferModelColumns bufferColumns; GRef::GRef(Dialog & parent) : GViewCB<ControlRef, GViewGladeB>(parent, _("Reference Settings"), false) {} void GRef::doBuild() { string const gladeName = findGladeFile("ref"); xml_ = Gnome::Glade::Xml::create(gladeName); xml_->get_widget("cancelbutton", cancelbutton_); setCancel(cancelbutton_); xml_->get_widget("applybutton", applybutton_); setApply(applybutton_); xml_->get_widget("okbutton", okbutton_); setApply(okbutton_); xml_->get_widget("refview", refview_); xml_->get_widget("labelentry", labelentry_); xml_->get_widget("nameentry", nameentry_); xml_->get_widget("formatcombo", formatcombo_); xml_->get_widget("buffercombo", buffercombo_ ); xml_->get_widget("jumptobutton", jumptobutton_); xml_->get_widget("backbutton", backbutton_); refview_->append_column("Name",refColumns.name); refview_->signal_cursor_changed().connect( sigc::mem_fun(*this, &GRef::selection_changed)); buffercombo_->signal_changed().connect( sigc::mem_fun(*this, &GRef::buffer_changed)); jumptobutton_->signal_clicked().connect( sigc::mem_fun(*this, &GRef::jumpto)); backbutton_->signal_clicked().connect( sigc::mem_fun(*this, &GRef::back)); } void GRef::selection_changed () { if (applylock_) return; Gtk::TreeModel::iterator iter = refview_->get_selection()->get_selected(); if(iter) // If anything is selected { Gtk::TreeModel::Row row = *iter; labelentry_->set_text(row[refColumns.name]); } if (backbutton_->is_sensitive()) controller().gotoBookmark(); jumptobutton_->set_sensitive(true); backbutton_->set_sensitive(false); } void GRef::jumpto() { controller().gotoRef(labelentry_->get_text()); backbutton_->set_sensitive(true); jumptobutton_->set_sensitive(false); } void GRef::back() { controller().gotoBookmark(); backbutton_->set_sensitive(false); jumptobutton_->set_sensitive(true); } void GRef::buffer_changed() { if (applylock_) return; update_labels(); } void GRef::update() { applylock_ = true; bc().refreshReadOnly(); jumptobutton_->set_sensitive(true); backbutton_->set_sensitive(false); labelentry_->set_text(controller().params().getContents()); nameentry_->set_text(controller().params().getOptions()); // Name is irrelevant to LaTeX/Literate documents Kernel::DocTypes doctype = kernel().docType(); if (doctype == Kernel::LATEX || doctype == Kernel::LITERATE) { nameentry_->set_sensitive(false); } else { nameentry_->set_sensitive(true); } // type is irrelevant to LinuxDoc/DocBook. if (doctype == Kernel::LINUXDOC || doctype == Kernel::DOCBOOK) { formatcombo_->set_active(0); formatcombo_->set_sensitive(false); } else { formatcombo_->set_sensitive(true); } bufferstore_ = Gtk::ListStore::create(bufferColumns); vector<string> const buffers = controller().getBufferList(); buffercombo_->set_model(bufferstore_); string const buffername = kernel().buffer().fileName(); int i=0; for (vector<string>::const_iterator it = buffers.begin(); it != buffers.end(); ++it) { Gtk::TreeModel::iterator iter = bufferstore_->append(); (*iter)[bufferColumns.name] = *it; lyxerr << i << "\n"; if (buffername == *it) { buffercombo_->set_active(i); } i++; } formatcombo_->set_active(InsetRef::getType(controller().params().getCmdName())); update_labels(); applylock_ = false; } void GRef::update_labels() { int buffernum = buffercombo_->get_active_row_number(); if (buffernum<0) { buffernum=0; } string const name = controller(). getBufferName(buffernum); vector<string> keys = controller().getLabelList(name); refListStore_ = Gtk::ListStore::create(refColumns); for (vector<string>::const_iterator it = keys.begin(); it != keys.end(); ++it) { Gtk::TreeModel::iterator iter =refListStore_->append(); (*iter)[refColumns.name] = *it; } refview_->set_model(refListStore_); } void GRef::apply() { if (applylock_) return; controller().params().setContents(labelentry_->get_text()); controller().params().setOptions(nameentry_->get_text()); int const type = formatcombo_->get_active_row_number(); controller().params().setCmdName(InsetRef::getName(type)); //controller().params().type = type; controller().dispatchParams(); } } // namespace frontend } // namespace lyx
// -*- C++ -*- /** * \file GNote.h * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author John Spray * \author Andreas Klostermann * * Full author contact details are available in file CREDITS. */ #ifndef GREF_H #define GREF_H #include "GViewBase.h" #include <string> namespace lyx { namespace frontend { class ControlRef; /** This class provides a GTK+ implementation of the Note Dialog. */ class GRef : public GViewCB<ControlRef, GViewGladeB> { public: GRef(Dialog & parent); private: virtual void apply(); virtual void doBuild(); virtual void update(); virtual void update_labels(); // Signal callbacks void selection_changed (); void buffer_changed(); void jumpto(); void back(); // apply() won't act when this is true bool applylock_; std::string lastbuffer_; Gtk::Entry * labelentry_; Gtk::Entry * nameentry_; Gtk::TreeView * refview_; Glib::RefPtr<Gtk::ListStore> refListStore_; Glib::RefPtr<Gtk::ListStore> bufferstore_; Gtk::ComboBox * formatcombo_; Gtk::ComboBox * buffercombo_; Gtk::Button * jumptobutton_; Gtk::Button * backbutton_; Gtk::Button * cancelbutton_; Gtk::Button * okbutton_; Gtk::Button * applybutton_; }; } // namespace frontend } // namespace lyx #endif // GREF_H
ref.glade
Description: application/glade
Index: lyx-devel/src/frontends/gtk/glade/Makefile.am =================================================================== RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/glade/Makefile.am,v retrieving revision 1.5 diff -u -p -r1.5 Makefile.am --- lyx-devel/src/frontends/gtk/glade/Makefile.am 2004/12/12 22:48:58 1.5 +++ lyx-devel/src/frontends/gtk/glade/Makefile.am 2005/03/11 19:43:37 @@ -20,6 +20,7 @@ dist_glade_DATA = \ note.glade \ paragraph.glade \ print.glade \ + ref.glade \ search.glade \ sendto.glade \ showfile.glade \