3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
11 #include "QRefDialog.h"
13 #include "QtLyXView.h"
14 #include "BufferView.h"
22 #include <qpushbutton.h>
23 #include <qlineedit.h>
25 #include <qcombobox.h>
26 #include <qcheckbox.h>
30 QRef::QRef(LyXView *v, Dialogs *d)
31 : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0),
32 sort(0), gotowhere(GOTOREF), type(REF), refs(0)
34 // let the dialog be shown
35 // This is a permanent connection so we won't bother
36 // storing a copy because we won't be disconnecting.
37 d->showRef.connect(slot(this, &QRef::showRef));
38 d->createRef.connect(slot(this, &QRef::createRef));
48 void QRef::showRef(InsetCommand * const inset)
50 // FIXME: when could inset be 0 here ?
55 readonly = lv_->buffer()->isReadonly();
56 //ih_ = inset_->hide.connect(slot(this,&QRef::hide));
57 params = inset->params();
63 void QRef::createRef(string const & arg)
68 readonly = lv_->buffer()->isReadonly();
69 params.setFromString(arg);
74 void QRef::select(const char *text)
81 void QRef::highlight(const char *text)
83 if (gotowhere==GOTOBACK)
86 dialog_->gotoPB->setEnabled(true);
88 dialog_->typeCO->setEnabled(true);
89 dialog_->referenceED->setText(text);
90 dialog_->okPB->setEnabled(true);
95 void QRef::set_sort(bool on)
99 dialog_->refsLB->clear();
105 void QRef::goto_ref()
109 lv_->getLyXFunc()->dispatch(LFUN_REF_GOTO, dialog_->referenceED->text().latin1());
111 dialog_->gotoPB->setText(_("&Go back"));
114 //FIXME lv_->getLyXFunc()->dispatch(LFUN_REF_BACK);
116 dialog_->gotoPB->setText(_("&Goto reference"));
122 void QRef::updateRefs()
124 // list will be re-done, should go back if necessary
125 if (gotowhere==GOTOBACK) {
126 //FIXME lv_->getLyXFunc()->dispatch(LFUN_REF_BACK);
128 dialog_->gotoPB->setText(_("&Goto reference"));
131 dialog_->refsLB->setAutoUpdate(false);
133 // need this because Qt will send a highlight() here for
134 // the first item inserted
135 string tmp(dialog_->referenceED->text());
137 for (std::vector< string >::const_iterator iter = refs.begin();
138 iter != refs.end(); ++iter) {
140 dialog_->refsLB->inSort(iter->c_str());
142 dialog_->refsLB->insertItem(iter->c_str());
145 dialog_->referenceED->setText(tmp.c_str());
147 for (unsigned int i = 0; i < dialog_->refsLB->count(); ++i) {
148 if (!strcmp(dialog_->referenceED->text(),dialog_->refsLB->text(i)))
149 dialog_->refsLB->setCurrentItem(i);
152 dialog_->refsLB->setAutoUpdate(true);
153 dialog_->refsLB->update();
157 void QRef::do_ref_update()
160 dialog_->refsLB->clear();
161 refs = lv_->buffer()->getLabelList();
163 dialog_->sortCB->setEnabled(true);
170 // FIXME: needs updating
172 dialog_->referenceED->setText(params.getContents().c_str());
173 dialog_->nameED->setText(params.getOptions().c_str());
175 if (params.getCmdName()=="pageref") {
177 dialog_->typeCO->setCurrentItem(1);
178 } else if (params.getCmdName()=="vref") {
180 dialog_->typeCO->setCurrentItem(2);
181 } else if (params.getCmdName()=="vpageref") {
183 dialog_->typeCO->setCurrentItem(3);
184 } else if (params.getCmdName()=="prettyref") {
186 dialog_->typeCO->setCurrentItem(4);
189 dialog_->typeCO->setCurrentItem(0);
192 dialog_->gotoPB->setText(_("&Goto reference"));
196 dialog_->sortCB->setChecked(sort);
200 dialog_->gotoPB->setEnabled(params.getContents()!="");
201 dialog_->okPB->setEnabled(params.getContents()!="");
203 dialog_->typeCO->setEnabled(!readonly);
204 dialog_->sortCB->setEnabled(!readonly);
205 dialog_->refsLB->setEnabled(!readonly);
206 dialog_->okPB->setEnabled(!readonly);
207 dialog_->updatePB->setEnabled(!readonly);
209 dialog_->cancelPB->setText(_("&Close"));
211 dialog_->cancelPB->setText(_("&Cancel"));
220 if (!lv_->view()->available())
223 switch (dialog_->typeCO->currentItem()) {
225 params.setCmdName("ref");
228 params.setCmdName("pageref");
231 params.setCmdName("vref");
234 params.setCmdName("vpageref");
237 params.setCmdName("prettyref");
240 lyxerr[Debug::GUI] << "Unknown Ref Type" << endl;
243 params.setContents(dialog_->referenceED->text().latin1());
244 params.setOptions(dialog_->nameED->text().latin1());
247 if (params != inset_->params()) {
248 inset_->setParams(params);
249 lv_->view()->updateInset(inset_, true);
252 lv_->getLyXFunc()->dispatch(LFUN_REF_INSERT, params.getAsString().c_str());
259 dialog_ = new QRefDialog(this, 0, _("LyX: Cross Reference"), false);
261 if (!dialog_->isVisible()) {
262 h_ = d_->hideBufferDependent.connect(slot(this, &QRef::hide));
263 //u_ = d_->updateBufferDependent.connect(slot(this, &QRef::update));
267 dialog_->setActiveWindow();