3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming <a.leeming@ic.ac.uk>
7 * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
13 #pragma implementation
16 #include "QCitationDialog.h"
17 #include "QCitation.h"
19 #include <qcheckbox.h>
20 #include <qcombobox.h>
21 #include <qlineedit.h>
23 #include <qmultilineedit.h>
24 #include <qpushbutton.h>
26 #include "QtLyXView.h"
28 #include "ControlCitation.h"
31 #include "support/lstrings.h"
32 #include "helper_funcs.h"
42 typedef Qt2CB<ControlCitation, Qt2DB<QCitationDialog> > base_class;
44 QCitation::QCitation(ControlCitation & c)
45 : base_class(c, _("Citation"))
49 void QCitation::apply()
51 controller().params().setCmdName("cite");
52 controller().params().setContents(getStringFromVector(citekeys));
54 string const after = dialog_->textAfterED->text().latin1();
55 controller().params().setOptions(after);
59 void QCitation::hide()
68 void QCitation::build()
70 dialog_.reset(new QCitationDialog(this));
72 dialog_->searchTypeCB->setChecked(false);
73 dialog_->searchCaseCB->setChecked(false);
75 // Manage the ok, apply, restore and cancel/close buttons
76 bc().setOK(dialog_->okPB);
77 bc().setApply(dialog_->applyPB);
78 bc().setCancel(dialog_->closePB);
79 bc().setRestore(dialog_->restorePB);
81 bc().addReadOnly(dialog_->addPB);
82 bc().addReadOnly(dialog_->delPB);
83 bc().addReadOnly(dialog_->upPB);
84 bc().addReadOnly(dialog_->downPB);
85 bc().addReadOnly(dialog_->citationStyleCO);
87 //bc().addReadOnly(dialog_->textBeforeED);
88 bc().addReadOnly(dialog_->textAfterED);
92 void QCitation::update_contents()
94 // Make the list of all available bibliography keys
95 bibkeys = biblio::getKeys(controller().bibkeysInfo());
96 updateBrowser(dialog_->bibLB, bibkeys);
98 // Ditto for the keys cited in this inset
99 citekeys = getVectorFromString(controller().params().getContents());
100 updateBrowser(dialog_->citeLB, citekeys);
102 // No keys have been selected yet, so...
103 dialog_->infoML->clear();
107 dialog_->textAfterED->setText(controller().params().getOptions().c_str());
111 void QCitation::updateBrowser(QListBox* browser,
112 vector<string> const & keys) const
116 for (vector<string>::const_iterator it = keys.begin();
117 it < keys.end(); ++it) {
118 string const key = frontStrip(strip(*it));
119 // FIXME: why the .empty() test ?
121 browser->insertItem(key.c_str());
126 void QCitation::setBibButtons(State status) const
128 dialog_->addPB->setEnabled((status == ON));
132 void QCitation::setCiteButtons(State status) const
134 int const sel = dialog_->citeLB->currentItem();
135 int const maxline = dialog_->citeLB->count() - 1;
136 bool const activate = (status == ON);
137 bool const activate_up = (activate && sel != 0);
138 bool const activate_down = (activate && sel != maxline);
140 dialog_->delPB->setEnabled(activate);
141 dialog_->upPB->setEnabled(activate_up);
142 dialog_->downPB->setEnabled(activate_down);