4 * John Levon, moz@compsoc.man.ac.uk
5 * Changed for Qt2 implementation by Kalle Dalheimer, kalle@klaralvdalens-datakonsult.se
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 ***************************************************************************/
20 #include <support/lstrings.h>
22 #include "FormCitationDialogImpl.h"
26 #include "FormCitation.h"
33 #include <qlineedit.h>
35 #include <qmultilineedit.h>
36 #include <qpushbutton.h>
42 FormCitation::FormCitation(LyXView *v, Dialogs *d)
43 : dialog_(0), lv_(v), d_(d), inset_(0), ih_(0)
45 // let the dialog be shown
46 // This is a permanent connection so we won't bother
47 // storing a copy because we won't be disconnecting.
48 d->showCitation.connect(slot(this, &FormCitation::showCitation));
49 d->createCitation.connect(slot(this, &FormCitation::createCitation));
52 FormCitation::~FormCitation()
58 void FormCitation::showCitation(InsetCommand * inset)
60 if (inset == 0) return; // maybe we should Assert this?
62 // If connected to another inset, disconnect from it.
67 params = inset->params();
68 ih_ = inset->hideDialog.connect(slot(this, &FormCitation::hide));
73 void FormCitation::createCitation(string const & arg)
80 params.setFromString(arg);
85 void FormCitation::hide()
93 void FormCitation::show()
96 dialog_ = new FormCitationDialogImpl(this, 0, _("LyX: Citation Reference"), false);
104 void FormCitation::update()
109 vector<pair<string,string> > blist =
110 lv_->buffer()->getBibkeyList();
111 sort(blist.begin(), blist.end());
113 for (unsigned int i = 0; i < blist.size(); ++i) {
114 bibkeys.push_back(blist[i].first);
115 bibkeysInfo.push_back(blist[i].second);
119 updateBrowser(dialog_->bibliographyKeysLB, bibkeys);
121 // Ditto for the keys cited in this inset
123 string tmp, keys(params.getContents());
124 keys = frontStrip(split(keys, tmp, ','));
125 while (!tmp.empty()) {
126 citekeys.push_back(tmp);
127 keys = frontStrip(split(keys, tmp, ','));
129 updateBrowser(dialog_->insetKeysLB, citekeys);
131 // No keys have been selected yet, so...
132 dialog_->infoML->clear();
136 dialog_->textAfterED->setText( params.getOptions().c_str() );
140 void FormCitation::updateBrowser( QListBox* listbox,
141 vector<string> const & keys) const
145 for (unsigned int i = 0; i < keys.size(); ++i)
146 listbox->insertItem( keys[i].c_str() );
150 void FormCitation::setBibButtons(State status) const
152 dialog_->leftPB->setEnabled( status == ON );
156 void FormCitation::setCiteButtons(State status) const
158 int const sel = dialog_->insetKeysLB->currentItem();
159 int const maxline = dialog_->insetKeysLB->count();
161 bool const activate = (status == ON);
162 bool const activate_up = (activate && sel != 1);
163 bool const activate_down = (activate && sel != maxline);
165 dialog_->stopPB->setEnabled(activate);
166 dialog_->upPB->setEnabled(activate_up);
167 dialog_->downPB->setEnabled(activate_down);
171 void FormCitation::apply()
173 if (lv_->buffer()->isReadonly()) return;
176 for (unsigned int i = 0; i < citekeys.size(); ++i) {
177 if (i > 0) contents += ",";
178 contents += citekeys[i];
181 params.setContents(contents);
182 params.setOptions( dialog_->textAfterED->text().latin1() );
185 // Only update if contents have changed
186 if (params != inset_->params()) {
187 inset_->setParams(params);
188 lv_->view()->updateInset(inset_, true);
191 lv_->getLyXFunc()->Dispatch(LFUN_CITATION_INSERT,
192 params.getAsString());