4 * John Levon, moz@compsoc.man.ac.uk
7 /***************************************************************************
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
14 ***************************************************************************/
18 #include "FormRefDialog.h"
29 #include <qpushbutton.h>
30 #include <qlineedit.h>
32 #include <qcombobox.h>
33 #include <qcheckbox.h>
37 FormRef::FormRef(LyXView *v, Dialogs *d)
38 : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0),
39 sort(0), gotowhere(GOTOREF), type(REF), refs(0)
41 // let the dialog be shown
42 // This is a permanent connection so we won't bother
43 // storing a copy because we won't be disconnecting.
44 d->showRef.connect(slot(this, &FormRef::showRef));
45 d->createRef.connect(slot(this, &FormRef::createRef));
53 void FormRef::showRef(InsetCommand * const inset)
55 // FIXME: when could inset be 0 here ?
60 readonly = lv_->buffer()->isReadonly();
61 ih_ = inset_->hide.connect(slot(this,&FormRef::hide));
62 params = inset->params();
67 void FormRef::createRef(string const & arg)
72 readonly = lv_->buffer()->isReadonly();
73 params.setFromString(arg);
77 void FormRef::select(const char *text)
83 void FormRef::highlight(const char *text)
85 if (gotowhere==GOTOBACK)
88 dialog_->gotoPB->setEnabled(true);
90 dialog_->typeCO->setEnabled(true);
91 dialog_->referenceED->setText(text);
92 dialog_->okPB->setEnabled(true);
96 void FormRef::set_sort(bool on)
100 dialog_->refsLB->clear();
105 void FormRef::goto_ref()
109 lv_->getLyXFunc()->Dispatch(LFUN_REF_GOTO, dialog_->referenceED->text().latin1());
111 dialog_->gotoPB->setText(_("&Go back"));
114 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
116 dialog_->gotoPB->setText(_("&Goto reference"));
121 void FormRef::updateRefs()
123 // list will be re-done, should go back if necessary
124 if (gotowhere==GOTOBACK) {
125 lv_->getLyXFunc()->Dispatch(LFUN_REF_BACK);
127 dialog_->gotoPB->setText(_("&Goto reference"));
130 dialog_->refsLB->setAutoUpdate(false);
132 // need this because Qt will send a highlight() here for
133 // the first item inserted
134 string tmp(dialog_->referenceED->text());
136 for (vector< string >::const_iterator iter = refs.begin();
137 iter != refs.end(); ++iter) {
139 dialog_->refsLB->inSort(iter->c_str());
141 dialog_->refsLB->insertItem(iter->c_str());
144 dialog_->referenceED->setText(tmp.c_str());
146 for (unsigned int i = 0; i < dialog_->refsLB->count(); ++i) {
147 if (!strcmp(dialog_->referenceED->text(),dialog_->refsLB->text(i)))
148 dialog_->refsLB->setCurrentItem(i);
151 dialog_->refsLB->setAutoUpdate(true);
152 dialog_->refsLB->update();
155 void FormRef::do_ref_update()
158 dialog_->refsLB->clear();
159 refs = lv_->buffer()->getLabelList();
161 dialog_->sortCB->setEnabled(true);
165 void FormRef::update()
167 dialog_->referenceED->setText(params.getContents().c_str());
168 dialog_->nameED->setText(params.getOptions().c_str());
170 if (params.getCmdName()=="pageref") {
172 dialog_->typeCO->setCurrentItem(1);
173 } else if (params.getCmdName()=="vref") {
175 dialog_->typeCO->setCurrentItem(2);
176 } else if (params.getCmdName()=="vpageref") {
178 dialog_->typeCO->setCurrentItem(3);
179 } else if (params.getCmdName()=="prettyref") {
181 dialog_->typeCO->setCurrentItem(4);
184 dialog_->typeCO->setCurrentItem(0);
187 dialog_->gotoPB->setText(_("&Goto reference"));
191 dialog_->sortCB->setChecked(sort);
195 dialog_->gotoPB->setEnabled(params.getContents()!="");
196 dialog_->okPB->setEnabled(params.getContents()!="");
198 dialog_->typeCO->setEnabled(!readonly);
199 dialog_->sortCB->setEnabled(!readonly);
200 dialog_->refsLB->setEnabled(!readonly);
201 dialog_->okPB->setEnabled(!readonly);
202 dialog_->updatePB->setEnabled(!readonly);
204 dialog_->cancelPB->setText(_("&Close"));
206 dialog_->cancelPB->setText(_("&Cancel"));
209 void FormRef::apply()
214 if (!lv_->view()->available())
217 switch (dialog_->typeCO->currentItem()) {
219 params.setCmdName("ref");
222 params.setCmdName("pageref");
225 params.setCmdName("vref");
228 params.setCmdName("vpageref");
231 params.setCmdName("prettyref");
234 lyxerr[Debug::GUI] << "Unknown Ref Type" << endl;
237 params.setContents(dialog_->referenceED->text().latin1());
238 params.setOptions(dialog_->nameED->text().latin1());
241 if (params != inset_->params()) {
242 inset_->setParams(params);
243 lv_->view()->updateInset(inset_, true);
246 lv_->getLyXFunc()->Dispatch(LFUN_REF_INSERT, params.getAsString().c_str());
252 dialog_ = new FormRefDialog(this, 0, _("LyX: Cross Reference"), false);
254 if (!dialog_->isVisible()) {
255 h_ = d_->hideBufferDependent.connect(slot(this, &FormRef::hide));
256 u_ = d_->updateBufferDependent.connect(slot(this, &FormRef::update));
260 dialog_->setActiveWindow();
266 void FormRef::close()