3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Andreas Klostermann
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
22 #include "ControlRef.h"
24 #include "insets/insetref.h"
27 #include "insets/insetnote.h"
29 #include <libglademm.h>
38 class refModelColumns : public Gtk::TreeModel::ColumnRecord
45 Gtk::TreeModelColumn<Glib::ustring> name;
48 refModelColumns refColumns;
51 class bufferModelColumns : public Gtk::TreeModel::ColumnRecord
58 Gtk::TreeModelColumn<Glib::ustring> name;
61 bufferModelColumns bufferColumns;
64 GRef::GRef(Dialog & parent)
65 : GViewCB<ControlRef, GViewGladeB>(parent, lyx::to_utf8(_("Cross-reference")), false)
71 string const gladeName = findGladeFile("ref");
72 xml_ = Gnome::Glade::Xml::create(gladeName);
73 xml_->get_widget("Cancel", cancelbutton_);
74 setCancel(cancelbutton_);
75 xml_->get_widget("Apply", applybutton_);
76 setApply(applybutton_);
77 xml_->get_widget("OK", okbutton_);
80 xml_->get_widget("Labels", refview_);
81 xml_->get_widget("Label", labelentry_);
82 xml_->get_widget("Name", nameentry_);
83 xml_->get_widget("Format", formatcombo_);
84 xml_->get_widget("Buffer", buffercombo_ );
85 xml_->get_widget("JumpTo", jumptobutton_);
86 xml_->get_widget("Back", backbutton_);
87 xml_->get_widget("Refresh", refreshbutton_);
89 refview_->append_column(lyx::to_utf8(_("Label")), refColumns.name);
91 buffercombo_->signal_changed().connect(
92 sigc::mem_fun(*this, &GRef::buffer_changed));
93 refview_->signal_cursor_changed().connect(
94 sigc::mem_fun(*this, &GRef::selection_changed));
95 refview_->signal_row_activated().connect(
96 sigc::mem_fun(*this, &GRef::refview_activated));
97 jumptobutton_->signal_clicked().connect(
98 sigc::mem_fun(*this, &GRef::jumpto));
99 backbutton_->signal_clicked().connect(
100 sigc::mem_fun(*this, &GRef::back));
101 refreshbutton_->signal_clicked().connect(
102 sigc::mem_fun(*this, &GRef::update_labels));
104 labelentry_->signal_changed().connect(
105 sigc::mem_fun(*this, &GRef::update_validity));
106 formatcombo_->signal_changed().connect(
107 sigc::mem_fun(*this, &GRef::update_validity));
108 nameentry_->signal_changed().connect(
109 sigc::mem_fun(*this, &GRef::update_validity));
116 void GRef::selection_changed ()
121 Gtk::TreeModel::iterator iter = refview_->get_selection()->get_selected();
123 Gtk::TreeModel::Row row = *iter;
124 labelentry_->set_text(row[refColumns.name]);
132 if (backbutton_->is_sensitive()) {
133 // controller().gotoAnotherRef(labelentry_->get_text());
135 // kernel().dispatch(FuncRequest(LFUN_LABEL_GOTO, ref));
137 controller().gotoBookmark();
138 controller().gotoRef(labelentry_->get_text());
140 controller().gotoRef(labelentry_->get_text());
142 backbutton_->set_sensitive(true);
148 controller().gotoBookmark();
149 backbutton_->set_sensitive(false);
150 jumptobutton_->set_sensitive(true);
154 void GRef::buffer_changed()
166 bc().refreshReadOnly();
167 jumptobutton_->set_sensitive(true);
168 backbutton_->set_sensitive(false);
169 labelentry_->set_text(controller().params().getContents());
170 nameentry_->set_text(controller().params().getOptions());
172 // Name is irrelevant to LaTeX/Literate documents
173 Kernel::DocType doctype = kernel().docType();
174 if (doctype == Kernel::LATEX || doctype == Kernel::LITERATE) {
175 nameentry_->set_sensitive(false);
177 nameentry_->set_sensitive(true);
180 // Format is irrelevant to DocBook.
181 if (doctype == Kernel::DOCBOOK) {
182 formatcombo_->set_active(0);
183 formatcombo_->set_sensitive(false);
186 formatcombo_->set_active(InsetRef::getType(controller().params().getCmdName()));
187 formatcombo_->set_sensitive(true);
190 bufferstore_ = Gtk::ListStore::create(bufferColumns);
191 vector<string> const buffers = controller().getBufferList();
192 buffercombo_->set_model(bufferstore_);
194 vector<string>::const_iterator it = buffers.begin();
195 vector<string>::const_iterator const end = buffers.end();
196 for (; it != end; ++it) {
197 Gtk::TreeModel::iterator iter = bufferstore_->append();
198 (*iter)[bufferColumns.name] = *it;
201 buffercombo_->set_active(controller().getBufferNum());
209 void GRef::update_labels()
211 int buffernum = buffercombo_->get_active_row_number();
215 string const name = controller().getBufferName(buffernum);
216 vector<string> keys = controller().getLabelList(name);
217 refListStore_ = Gtk::ListStore::create(refColumns);
220 vector<string>::const_iterator it = keys.begin();
221 vector<string>::const_iterator end = keys.end();
222 for (;it != keys.end(); ++it) {
223 Gtk::TreeModel::iterator iter =refListStore_->append();
224 (*iter)[refColumns.name] = *it;
226 refview_->set_sensitive(true);
228 Gtk::TreeModel::iterator iter =refListStore_->append();
229 (*iter)[refColumns.name] = lyx::to_utf8(_("No labels found."));
230 refview_->set_sensitive(false);
232 refview_->set_model(refListStore_);
241 controller().params().setContents(labelentry_->get_text());
242 controller().params().setOptions(nameentry_->get_text());
243 int const type = formatcombo_->get_active_row_number();
244 controller().params().setCmdName(InsetRef::getName(type));
248 void GRef::update_validity()
250 bc().valid(!labelentry_->get_text().empty());
254 void GRef::refview_activated(const Gtk::TreeModel::Path&, Gtk::TreeViewColumn*)
256 if (!labelentry_->get_text().empty())
257 okbutton_->clicked();
261 } // namespace frontend