2 * \file QCitationDialog.C
3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
11 #include "QCitationDialog.h"
13 #include "QCitation.h"
15 #include "controllers/ControlCitation.h"
17 #include <qcheckbox.h>
18 #include <qlineedit.h>
20 #include <qmultilineedit.h>
21 #include <qpushbutton.h>
23 #include "QtLyXView.h"
32 QCitationDialog::QCitationDialog(QCitation * form, QWidget * parent, const char * name, bool modal, WFlags fl)
33 : QCitationDialogBase(parent, name, modal, fl),
36 connect(okPB, SIGNAL(clicked()),
37 form, SLOT(slotOK()));
38 connect(cancelPB, SIGNAL(clicked()),
39 form, SLOT(slotCancel()));
40 connect(restorePB, SIGNAL(clicked()),
41 form, SLOT(slotRestore()));
42 connect(applyPB, SIGNAL(clicked()),
43 form, SLOT(slotApply()));
47 QCitationDialog::~QCitationDialog()
52 void QCitationDialog::slotBibSelected( int sel )
54 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
56 citeLB->clearSelection();
58 // FIXME: why would this happen ?
59 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
63 // Put into browser_info the additional info associated with
64 // the selected browser_bib key
67 infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
69 // Highlight the selected browser_bib key in browser_cite if
71 vector<string>::const_iterator cit =
72 std::find(form_->citekeys.begin(), form_->citekeys.end(),
75 if (cit != form_->citekeys.end()) {
76 int const n = int(cit - form_->citekeys.begin());
77 citeLB->setSelected(n, true);
78 citeLB->setTopItem(n);
81 if (!form_->controller().isReadonly()) {
82 if (cit != form_->citekeys.end()) {
83 form_->setBibButtons(QCitation::OFF);
84 form_->setCiteButtons(QCitation::ON);
86 form_->setBibButtons(QCitation::ON);
87 form_->setCiteButtons(QCitation::OFF);
93 void QCitationDialog::slotCiteSelected(int sel)
95 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
97 // FIXME: why would this happen ?
98 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
102 if (!form_->controller().isReadonly()) {
103 form_->setBibButtons(QCitation::OFF);
104 form_->setCiteButtons(QCitation::ON);
107 // Highlight the selected browser_cite key in browser_bib
108 vector<string>::const_iterator cit =
109 std::find(form_->bibkeys.begin(),
110 form_->bibkeys.end(), form_->citekeys[sel]);
112 if (cit != form_->bibkeys.end()) {
113 int const n = int(cit - form_->bibkeys.begin());
114 bibLB->setSelected(n, true);
115 bibLB->setTopItem(n);
117 // Put into browser_info the additional info associated
118 // with the selected browser_cite key
120 infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
125 void QCitationDialog::slotAddClicked()
127 int const sel = bibLB->currentItem();
130 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
134 // Add the selected browser_bib key to browser_cite
135 citeLB->insertItem(form_->bibkeys[sel].c_str());
136 form_->citekeys.push_back(form_->bibkeys[sel]);
138 int const n = int(form_->citekeys.size());
139 citeLB->setSelected(n - 1, true);
141 form_->setBibButtons(QCitation::OFF);
142 form_->setCiteButtons(QCitation::ON);
147 void QCitationDialog::slotDelClicked()
149 int const sel = citeLB->currentItem();
152 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
156 // Remove the selected key from browser_cite
157 citeLB->removeItem(sel);
158 form_->citekeys.erase(form_->citekeys.begin() + sel);
160 form_->setBibButtons(QCitation::ON);
161 form_->setCiteButtons(QCitation::OFF);
166 void QCitationDialog::slotUpClicked()
168 int const sel = citeLB->currentItem();
171 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
175 // Move the selected key up one line
176 vector<string>::iterator it = form_->citekeys.begin() + sel;
177 string const tmp = *it;
179 citeLB->removeItem(sel);
180 form_->citekeys.erase(it);
182 citeLB->insertItem(tmp.c_str(), sel - 1);
183 citeLB->setSelected(sel - 1, true);
184 form_->citekeys.insert(it - 1, tmp);
185 form_->setCiteButtons(QCitation::ON);
190 void QCitationDialog::slotDownClicked()
192 int const sel = citeLB->currentItem();
195 if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
199 // Move the selected key down one line
200 vector<string>::iterator it = form_->citekeys.begin() + sel;
201 string const tmp = *it;
203 citeLB->removeItem(sel);
204 form_->citekeys.erase(it);
206 citeLB->insertItem(tmp.c_str(), sel + 1);
207 citeLB->setSelected(sel + 1, true);
208 form_->citekeys.insert(it + 1, tmp);
209 form_->setCiteButtons(QCitation::ON);
214 void QCitationDialog::slotPreviousClicked()
216 doFind(biblio::BACKWARD);
220 void QCitationDialog::slotNextClicked()
222 doFind(biblio::FORWARD);
226 void QCitationDialog::doFind(biblio::Direction const dir)
228 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
229 string const str = searchED->text().latin1();
231 biblio::Search const type =
232 searchTypeCB->isChecked() ?
233 biblio::REGEX : biblio::SIMPLE;
235 vector<string>::const_iterator start = form_->bibkeys.begin();
236 int const sel = bibLB->currentItem();
237 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
240 // Find the NEXT instance...
241 if (dir == biblio::FORWARD)
246 bool const caseSensitive = searchCaseCB->isChecked();
248 vector<string>::const_iterator const cit =
249 biblio::searchKeys(theMap, form_->bibkeys, str,
250 start, type, dir, caseSensitive);
252 if (cit == form_->bibkeys.end()) {
256 int const found = int(cit - form_->bibkeys.begin());
261 // Update the display
262 int const top = max(found - 5, 1);
263 bibLB->setTopItem(top);
264 bibLB->setSelected(found, true);
269 void QCitationDialog::slotCitationStyleSelected( int )
275 void QCitationDialog::slotTextBeforeReturn()
281 void QCitationDialog::slotTextAfterReturn()