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 #pragma implementation
17 #include "ControlRef.h"
19 #include "QRefDialog.h"
22 #include <qlineedit.h>
23 #include <qcheckbox.h>
25 #include <qcombobox.h>
26 #include <qpushbutton.h>
29 #include "helper_funcs.h" // getStringFromVector
30 #include "support/lstrings.h" // frontStrip, strip
31 #include "qt_helpers.h"
32 #include "insets/insetref.h"
41 typedef Qt2CB<ControlRef, Qt2DB<QRefDialog> > base_class;
45 : base_class(qt_("Cross Reference")),
46 sort_(false), at_ref_(false)
51 void QRef::build_dialog()
53 dialog_.reset(new QRefDialog(this));
55 bc().setOK(dialog_->okPB);
56 bc().setApply(dialog_->applyPB);
57 bc().setCancel(dialog_->closePB);
58 bc().addReadOnly(dialog_->refsLB);
59 bc().addReadOnly(dialog_->sortCB);
60 bc().addReadOnly(dialog_->nameED);
61 bc().addReadOnly(dialog_->referenceED);
62 bc().addReadOnly(dialog_->typeCO);
63 bc().addReadOnly(dialog_->bufferCO);
67 void QRef::update_contents()
69 InsetCommandParams const & params = controller().params();
71 dialog_->referenceED->setText(toqstr(params.getContents()));
73 dialog_->nameED->setText(toqstr(params.getOptions()));
74 dialog_->nameED->setReadOnly(!nameAllowed() && !readOnly());
76 dialog_->typeCO->setCurrentItem(InsetRef::getType(params.getCmdName()));
77 dialog_->typeCO->setEnabled(typeAllowed() && !readOnly());
79 dialog_->typeCO->setCurrentItem(0);
81 dialog_->sortCB->setChecked(sort_);
84 dialog_->bufferCO->clear();
85 vector<string> const buffers = controller().getBufferList();
86 for (vector<string>::const_iterator it = buffers.begin();
87 it != buffers.end(); ++it) {
88 dialog_->bufferCO->insertItem(toqstr(*it));
90 dialog_->bufferCO->setCurrentItem(controller().getBufferNum());
98 InsetCommandParams & params = controller().params();
100 params.setCmdName(InsetRef::getName(dialog_->typeCO->currentItem()));
101 params.setContents(fromqstr(dialog_->referenceED->text()));
102 params.setOptions(fromqstr(dialog_->nameED->text()));
106 bool QRef::nameAllowed()
108 return controller().docType() != ControlRef::LATEX &&
109 controller().docType() != ControlRef::LITERATE;
113 bool QRef::typeAllowed()
115 return controller().docType() != ControlRef::LINUXDOC &&
116 controller().docType() != ControlRef::DOCBOOK;
120 void QRef::setGoBack()
122 dialog_->gotoPB->setText(qt_("&Go back"));
123 QToolTip::remove(dialog_->gotoPB);
124 QToolTip::add(dialog_->gotoPB, qt_("Go back"));
128 void QRef::setGotoRef()
130 dialog_->gotoPB->setText(qt_("&Goto"));
131 QToolTip::remove(dialog_->gotoPB);
132 QToolTip::add(dialog_->gotoPB, qt_("Go to reference"));
138 string ref(fromqstr(dialog_->referenceED->text()));
143 controller().gotoBookmark();
147 controller().gotoRef(ref);
153 void QRef::redoRefs()
155 dialog_->refsLB->setAutoUpdate(false);
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) {
164 dialog_->refsLB->inSort(toqstr(*iter));
166 dialog_->refsLB->insertItem(toqstr(*iter));
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 dialog_->refsLB->clear();
187 string const name = controller().getBufferName(dialog_->bufferCO->currentItem());
188 refs_ = controller().getLabelList(name);
189 dialog_->sortCB->setEnabled(!refs_.empty());
190 dialog_->refsLB->setEnabled(!refs_.empty());