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>
44 FormCitation::FormCitation(LyXView *v, Dialogs *d)
45 : dialog_(0), lv_(v), d_(d), inset_(0), ih_(0)
47 // let the dialog be shown
48 // This is a permanent connection so we won't bother
49 // storing a copy because we won't be disconnecting.
50 d->showCitation.connect(slot(this, &FormCitation::showCitation));
51 d->createCitation.connect(slot(this, &FormCitation::createCitation));
54 FormCitation::~FormCitation()
60 void FormCitation::showCitation(InsetCommand * inset)
62 if (inset == 0) return; // maybe we should Assert this?
64 // If connected to another inset, disconnect from it.
69 params = inset->params();
70 ih_ = inset->hideDialog.connect(slot(this, &FormCitation::hide));
75 void FormCitation::createCitation(string const & arg)
82 params.setFromString(arg);
87 void FormCitation::hide()
95 void FormCitation::show()
98 dialog_ = new FormCitationDialogImpl(this, 0, _("LyX: Citation Reference"), false);
106 void FormCitation::update()
111 vector<pair<string,string> > blist =
112 lv_->buffer()->getBibkeyList();
113 sort(blist.begin(), blist.end());
115 for (unsigned int i = 0; i < blist.size(); ++i) {
116 bibkeys.push_back(blist[i].first);
117 bibkeysInfo.push_back(blist[i].second);
121 updateBrowser(dialog_->bibliographyKeysLB, bibkeys);
123 // Ditto for the keys cited in this inset
125 string tmp, keys(params.getContents());
126 keys = frontStrip(split(keys, tmp, ','));
127 while (!tmp.empty()) {
128 citekeys.push_back(tmp);
129 keys = frontStrip(split(keys, tmp, ','));
131 updateBrowser(dialog_->insetKeysLB, citekeys);
133 // No keys have been selected yet, so...
134 dialog_->infoML->clear();
138 dialog_->textAfterED->setText( params.getOptions().c_str() );
142 void FormCitation::updateBrowser( QListBox* listbox,
143 vector<string> const & keys) const
147 for (unsigned int i = 0; i < keys.size(); ++i)
148 listbox->insertItem( keys[i].c_str() );
152 void FormCitation::setBibButtons(State status) const
154 dialog_->leftPB->setEnabled( status == ON );
158 void FormCitation::setCiteButtons(State status) const
160 int const sel = dialog_->insetKeysLB->currentItem();
161 int const maxline = dialog_->insetKeysLB->count();
163 bool const activate = (status == ON);
164 bool const activate_up = (activate && sel != 1);
165 bool const activate_down = (activate && sel != maxline);
167 dialog_->stopPB->setEnabled(activate);
168 dialog_->upPB->setEnabled(activate_up);
169 dialog_->downPB->setEnabled(activate_down);
173 void FormCitation::apply()
175 if (lv_->buffer()->isReadonly()) return;
178 for (unsigned int i = 0; i < citekeys.size(); ++i) {
179 if (i > 0) contents += ",";
180 contents += citekeys[i];
183 params.setContents(contents);
184 params.setOptions( dialog_->textAfterED->text().latin1() );
187 // Only update if contents have changed
188 if (params != inset_->params()) {
189 inset_->setParams(params);
190 lv_->view()->updateInset(inset_, true);
193 lv_->getLyXFunc()->Dispatch(LFUN_CITATION_INSERT,
194 params.getAsString());