--- /dev/null
+/**
+ * \file GRef.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, _("Cross-reference"), false)
+{}
+
+
+void GRef::doBuild()
+{
+ string const gladeName = findGladeFile("ref");
+ xml_ = Gnome::Glade::Xml::create(gladeName);
+ xml_->get_widget("Cancel", cancelbutton_);
+ setCancel(cancelbutton_);
+ xml_->get_widget("Apply", applybutton_);
+ setApply(applybutton_);
+ xml_->get_widget("OK", okbutton_);
+ setOK(okbutton_);
+
+ xml_->get_widget("Labels", refview_);
+ xml_->get_widget("Label", labelentry_);
+ xml_->get_widget("Name", nameentry_);
+ xml_->get_widget("Format", formatcombo_);
+ xml_->get_widget("Buffer", buffercombo_ );
+ xml_->get_widget("JumpTo", jumptobutton_);
+ xml_->get_widget("Back", backbutton_);
+ xml_->get_widget("Refresh", refreshbutton_);
+
+ refview_->append_column(_("Label"), refColumns.name);
+
+ buffercombo_->signal_changed().connect(
+ sigc::mem_fun(*this, &GRef::buffer_changed));
+ refview_->signal_cursor_changed().connect(
+ sigc::mem_fun(*this, &GRef::selection_changed));
+ refview_->signal_row_activated().connect(
+ sigc::mem_fun(*this, &GRef::refview_activated));
+ jumptobutton_->signal_clicked().connect(
+ sigc::mem_fun(*this, &GRef::jumpto));
+ backbutton_->signal_clicked().connect(
+ sigc::mem_fun(*this, &GRef::back));
+ refreshbutton_->signal_clicked().connect(
+ sigc::mem_fun(*this, &GRef::update_labels));
+
+ labelentry_->signal_changed().connect(
+ sigc::mem_fun(*this, &GRef::update_validity));
+ formatcombo_->signal_changed().connect(
+ sigc::mem_fun(*this, &GRef::update_validity));
+ nameentry_->signal_changed().connect(
+ sigc::mem_fun(*this, &GRef::update_validity));
+
+ applylock_ = false;
+ bc().valid(false);
+}
+
+
+void GRef::selection_changed ()
+{
+ if (applylock_)
+ return;
+
+ Gtk::TreeModel::iterator iter = refview_->get_selection()->get_selected();
+ if(iter) {
+ Gtk::TreeModel::Row row = *iter;
+ labelentry_->set_text(row[refColumns.name]);
+ }
+}
+
+
+void GRef::jumpto()
+{
+
+ if (backbutton_->is_sensitive()) {
+// controller().gotoAnotherRef(labelentry_->get_text());
+// OR
+// kernel().dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
+// OR
+ controller().gotoBookmark();
+ controller().gotoRef(labelentry_->get_text());
+ } else {
+ controller().gotoRef(labelentry_->get_text());
+ }
+ backbutton_->set_sensitive(true);
+}
+
+
+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::DocType doctype = kernel().docType();
+ if (doctype == Kernel::LATEX || doctype == Kernel::LITERATE) {
+ nameentry_->set_sensitive(false);
+ } else {
+ nameentry_->set_sensitive(true);
+ }
+
+ // Format is irrelevant to LinuxDoc/DocBook.
+ if (doctype == Kernel::LINUXDOC || doctype == Kernel::DOCBOOK) {
+ formatcombo_->set_active(0);
+ formatcombo_->set_sensitive(false);
+
+ } else {
+ formatcombo_->set_active(InsetRef::getType(controller().params().getCmdName()));
+ formatcombo_->set_sensitive(true);
+ }
+
+ bufferstore_ = Gtk::ListStore::create(bufferColumns);
+ vector<string> const buffers = controller().getBufferList();
+ buffercombo_->set_model(bufferstore_);
+
+ vector<string>::const_iterator it = buffers.begin();
+ vector<string>::const_iterator const end = buffers.end();
+ for (; it != end; ++it) {
+ Gtk::TreeModel::iterator iter = bufferstore_->append();
+ (*iter)[bufferColumns.name] = *it;
+ }
+
+ buffercombo_->set_active(controller().getBufferNum());
+
+ update_labels();
+ applylock_ = false;
+ bc().valid(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);
+
+ if (!keys.empty()) {
+ vector<string>::const_iterator it = keys.begin();
+ vector<string>::const_iterator end = keys.end();
+ for (;it != keys.end(); ++it) {
+ Gtk::TreeModel::iterator iter =refListStore_->append();
+ (*iter)[refColumns.name] = *it;
+ }
+ refview_->set_sensitive(true);
+ } else {
+ Gtk::TreeModel::iterator iter =refListStore_->append();
+ (*iter)[refColumns.name] = _("No labels found.");
+ refview_->set_sensitive(false);
+ }
+ 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));
+}
+
+
+void GRef::update_validity()
+{
+ bc().valid(!labelentry_->get_text().empty());
+}
+
+
+void GRef::refview_activated(const Gtk::TreeModel::Path&, Gtk::TreeViewColumn*)
+{
+ if (!labelentry_->get_text().empty())
+ okbutton_->clicked();
+}
+
+
+} // namespace frontend
+} // namespace lyx
--- /dev/null
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+
+<widget class="GtkDialog" id="dialog">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">dialog1</property>
+ <property name="type">GTK_WINDOW_TOPLEVEL</property>
+ <property name="window_position">GTK_WIN_POS_NONE</property>
+ <property name="modal">False</property>
+ <property name="resizable">False</property>
+ <property name="destroy_with_parent">False</property>
+ <property name="decorated">True</property>
+ <property name="skip_taskbar_hint">False</property>
+ <property name="skip_pager_hint">False</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+ <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+ <property name="focus_on_map">True</property>
+ <property name="has_separator">False</property>
+
+ <child internal-child="vbox">
+ <widget class="GtkVBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child internal-child="action_area">
+ <widget class="GtkHButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+ <child>
+ <widget class="GtkButton" id="Cancel">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-cancel</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="response_id">-6</property>
+ <accelerator key="Escape" modifiers="0" signal="clicked"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="Apply">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-apply</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="response_id">-10</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="OK">
+ <property name="visible">True</property>
+ <property name="can_default">True</property>
+ <property name="has_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-ok</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="response_id">-5</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">GTK_PACK_END</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkVBox" id="vbox2">
+ <property name="border_width">12</property>
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">12</property>
+
+ <child>
+ <widget class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">12</property>
+
+ <child>
+ <widget class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">_Document:</property>
+ <property name="use_underline">True</property>
+ <property name="use_markup">True</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">True</property>
+ <property name="xalign">0.490000009537</property>
+ <property name="yalign">0.490000009537</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkComboBox" id="Buffer">
+ <property name="width_request">150</property>
+ <property name="visible">True</property>
+ <property name="items" translatable="yes">help</property>
+ <property name="add_tearoffs">False</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkHBox" id="hbox3">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">12</property>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+ <child>
+ <widget class="GtkTreeView" id="Labels">
+ <property name="width_request">150</property>
+ <property name="height_request">300</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_visible">True</property>
+ <property name="rules_hint">False</property>
+ <property name="reorderable">False</property>
+ <property name="enable_search">True</property>
+ <property name="fixed_height_mode">False</property>
+ <property name="hover_selection">False</property>
+ <property name="hover_expand">False</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkVButtonBox" id="vbuttonbox1">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_START</property>
+ <property name="spacing">12</property>
+
+ <child>
+ <widget class="GtkButton" id="JumpTo">
+ <property name="visible">True</property>
+ <property name="tooltip" translatable="yes">Jump to the position of the selected label</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-jump-to</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="Back">
+ <property name="visible">True</property>
+ <property name="tooltip" translatable="yes">Return to original position in document</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-go-back</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="Refresh">
+ <property name="visible">True</property>
+ <property name="tooltip" translatable="yes">Refresh the label list</property>
+ <property name="can_default">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-refresh</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkTable" id="table1">
+ <property name="visible">True</property>
+ <property name="n_rows">3</property>
+ <property name="n_columns">2</property>
+ <property name="homogeneous">False</property>
+ <property name="row_spacing">6</property>
+ <property name="column_spacing">6</property>
+
+ <child>
+ <widget class="GtkEntry" id="Name">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">True</property>
+ <property name="editable">True</property>
+ <property name="visibility">True</property>
+ <property name="max_length">0</property>
+ <property name="text" translatable="yes"></property>
+ <property name="has_frame">True</property>
+ <property name="invisible_char">*</property>
+ <property name="activates_default">False</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label3">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Label:</property>
+ <property name="use_underline">True</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Format:</property>
+ <property name="use_underline">True</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">0</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="label" translatable="yes">_Name:</property>
+ <property name="use_underline">True</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkComboBox" id="Format">
+ <property name="visible">True</property>
+ <property name="items" translatable="yes"><reference>
+(<reference>)
+<page>
+on page <page>
+<reference> on page <page>
+Formatted reference</property>
+ <property name="add_tearoffs">False</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">fill</property>
+ <property name="y_options">fill</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkEntry" id="Label">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">True</property>
+ <property name="visibility">True</property>
+ <property name="max_length">0</property>
+ <property name="text" translatable="yes"></property>
+ <property name="has_frame">True</property>
+ <property name="invisible_char">*</property>
+ <property name="activates_default">False</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+</widget>
+
+</glade-interface>