3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS
14 #include "ControlRef.h"
16 #include "QRefDialog.h"
19 #include <qlineedit.h>
20 #include <qcheckbox.h>
22 #include <qcombobox.h>
23 #include <qpushbutton.h>
26 #include "helper_funcs.h" // getStringFromVector
27 #include "support/lstrings.h" // frontStrip, strip
28 #include "qt_helpers.h"
29 #include "insets/insetref.h"
38 typedef QController<ControlRef, QView<QRefDialog> > base_class;
41 QRef::QRef(Dialog & parent)
42 : base_class(parent, _("LyX: Cross-reference")),
43 sort_(false), at_ref_(false)
48 void QRef::build_dialog()
50 dialog_.reset(new QRefDialog(this));
52 bcview().setOK(dialog_->okPB);
53 bcview().setApply(dialog_->applyPB);
54 bcview().setCancel(dialog_->closePB);
55 bcview().addReadOnly(dialog_->refsLB);
56 bcview().addReadOnly(dialog_->sortCB);
57 bcview().addReadOnly(dialog_->nameED);
58 bcview().addReadOnly(dialog_->referenceED);
59 bcview().addReadOnly(dialog_->typeCO);
60 bcview().addReadOnly(dialog_->bufferCO);
64 void QRef::update_contents()
66 InsetCommandParams const & params = controller().params();
68 dialog_->referenceED->setText(toqstr(params.getContents()));
70 dialog_->nameED->setText(toqstr(params.getOptions()));
71 dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
73 dialog_->typeCO->setCurrentItem(InsetRef::getType(params.getCmdName()));
74 dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
76 dialog_->typeCO->setCurrentItem(0);
78 dialog_->sortCB->setChecked(sort_);
81 dialog_->bufferCO->clear();
82 vector<string> const buffers = controller().getBufferList();
83 for (vector<string>::const_iterator it = buffers.begin();
84 it != buffers.end(); ++it) {
85 dialog_->bufferCO->insertItem(toqstr(*it));
87 dialog_->bufferCO->setCurrentItem(controller().getBufferNum());
95 InsetCommandParams & params = controller().params();
97 params.setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
98 params.setContents(fromqstr(dialog_->referenceED->text()));
99 params.setOptions(fromqstr(dialog_->nameED->text()));
103 bool QRef::nameAllowed()
105 Kernel::DocTypes doc_type = kernel().docType();
106 return doc_type != Kernel::LATEX &&
107 doc_type != Kernel::LITERATE;
111 bool QRef::typeAllowed()
113 Kernel::DocTypes doc_type = kernel().docType();
114 return doc_type != Kernel::LINUXDOC &&
115 doc_type != Kernel::DOCBOOK;
119 void QRef::setGoBack()
121 dialog_->gotoPB->setText(qt_("&Go Back"));
122 QToolTip::remove(dialog_->gotoPB);
123 QToolTip::add(dialog_->gotoPB, qt_("Jump back"));
127 void QRef::setGotoRef()
129 dialog_->gotoPB->setText(qt_("&Go to Reference"));
130 QToolTip::remove(dialog_->gotoPB);
131 QToolTip::add(dialog_->gotoPB, qt_("Jump to reference"));
137 string ref(fromqstr(dialog_->referenceED->text()));
142 controller().gotoBookmark();
146 controller().gotoRef(ref);
152 void QRef::redoRefs()
154 dialog_->refsLB->setAutoUpdate(false);
155 dialog_->refsLB->clear();
157 // need this because Qt will send a highlight() here for
158 // the first item inserted
159 QString const tmp(dialog_->referenceED->text());
161 for (std::vector<string>::const_iterator iter = refs_.begin();
162 iter != refs_.end(); ++iter) {
163 dialog_->refsLB->insertItem(toqstr(*iter));
167 dialog_->refsLB->sort();
169 dialog_->referenceED->setText(tmp);
171 for (unsigned int i = 0; i < dialog_->refsLB->count(); ++i) {
172 if (tmp == dialog_->refsLB->text(i))
173 dialog_->refsLB->setCurrentItem(i);
176 dialog_->refsLB->setAutoUpdate(true);
177 dialog_->refsLB->update();
181 void QRef::updateRefs()
186 string const name = controller().getBufferName(dialog_->bufferCO->currentItem());
187 refs_ = controller().getLabelList(name);
188 dialog_->sortCB->setEnabled(!refs_.empty());
189 dialog_->refsLB->setEnabled(!refs_.empty());