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"
14 #include "controllers/ControlCitation.h"
16 #include <qcheckbox.h>
17 #include <qlineedit.h>
19 #include <qmultilineedit.h>
20 #include <qpushbutton.h>
22 #include "QtLyXView.h"
31 QCitationDialog::QCitationDialog(QCitation * form, QWidget * parent, const char * name, bool modal, WFlags fl)
32 : QCitationDialogBase(parent, name, modal, fl),
35 connect(okPB, SIGNAL(clicked()),
36 form, SLOT(slotOK()));
37 connect(cancelPB, SIGNAL(clicked()),
38 form, SLOT(slotCancel()));
39 connect(restorePB, SIGNAL(clicked()),
40 form, SLOT(slotRestore()));
41 connect(applyPB, SIGNAL(clicked()),
42 form, SLOT(slotApply()));
43 connect(searchED, SIGNAL(returnPressed()),
44 form, SLOT(slotNextClicked()));
48 QCitationDialog::~QCitationDialog()
53 void QCitationDialog::slotBibSelected( int sel )
55 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
57 citeLB->clearSelection();
59 // FIXME: why would this happen ?
60 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
64 // Put into browser_info the additional info associated with
65 // the selected browser_bib key
68 infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
70 // Highlight the selected browser_bib key in browser_cite if
72 vector<string>::const_iterator cit =
73 std::find(form_->citekeys.begin(), form_->citekeys.end(),
76 if (cit != form_->citekeys.end()) {
77 int const n = int(cit - form_->citekeys.begin());
78 citeLB->setSelected(n, true);
79 citeLB->setTopItem(n);
82 if (!form_->controller().isReadonly()) {
83 if (cit != form_->citekeys.end()) {
84 form_->setBibButtons(QCitation::OFF);
85 form_->setCiteButtons(QCitation::ON);
87 form_->setBibButtons(QCitation::ON);
88 form_->setCiteButtons(QCitation::OFF);
94 void QCitationDialog::slotCiteSelected(int sel)
96 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
98 // FIXME: why would this happen ?
99 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
103 if (!form_->controller().isReadonly()) {
104 form_->setBibButtons(QCitation::OFF);
105 form_->setCiteButtons(QCitation::ON);
108 // Highlight the selected browser_cite key in browser_bib
109 vector<string>::const_iterator cit =
110 std::find(form_->bibkeys.begin(),
111 form_->bibkeys.end(), form_->citekeys[sel]);
113 if (cit != form_->bibkeys.end()) {
114 int const n = int(cit - form_->bibkeys.begin());
115 bibLB->setSelected(n, true);
116 bibLB->setTopItem(n);
118 // Put into browser_info the additional info associated
119 // with the selected browser_cite key
121 infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
126 void QCitationDialog::slotAddClicked()
128 int const sel = bibLB->currentItem();
131 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
135 // Add the selected browser_bib key to browser_cite
136 citeLB->insertItem(form_->bibkeys[sel].c_str());
137 form_->citekeys.push_back(form_->bibkeys[sel]);
139 int const n = int(form_->citekeys.size());
140 citeLB->setSelected(n - 1, true);
142 form_->setBibButtons(QCitation::OFF);
143 form_->setCiteButtons(QCitation::ON);
148 void QCitationDialog::slotDelClicked()
150 int const sel = citeLB->currentItem();
153 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
157 // Remove the selected key from browser_cite
158 citeLB->removeItem(sel);
159 form_->citekeys.erase(form_->citekeys.begin() + sel);
161 form_->setBibButtons(QCitation::ON);
162 form_->setCiteButtons(QCitation::OFF);
167 void QCitationDialog::slotUpClicked()
169 int const sel = citeLB->currentItem();
172 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
176 // Move the selected key up one line
177 vector<string>::iterator it = form_->citekeys.begin() + sel;
178 string const tmp = *it;
180 citeLB->removeItem(sel);
181 form_->citekeys.erase(it);
183 citeLB->insertItem(tmp.c_str(), sel - 1);
184 citeLB->setSelected(sel - 1, true);
185 form_->citekeys.insert(it - 1, tmp);
186 form_->setCiteButtons(QCitation::ON);
191 void QCitationDialog::slotDownClicked()
193 int const sel = citeLB->currentItem();
196 if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
200 // Move the selected key down one line
201 vector<string>::iterator it = form_->citekeys.begin() + sel;
202 string const tmp = *it;
204 citeLB->removeItem(sel);
205 form_->citekeys.erase(it);
207 citeLB->insertItem(tmp.c_str(), sel + 1);
208 citeLB->setSelected(sel + 1, true);
209 form_->citekeys.insert(it + 1, tmp);
210 form_->setCiteButtons(QCitation::ON);
215 void QCitationDialog::slotPreviousClicked()
217 doFind(biblio::BACKWARD);
221 void QCitationDialog::slotNextClicked()
223 doFind(biblio::FORWARD);
227 void QCitationDialog::doFind(biblio::Direction const dir)
229 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
230 string const str = searchED->text().latin1();
232 biblio::Search const type =
233 searchTypeCB->isChecked() ?
234 biblio::REGEX : biblio::SIMPLE;
236 vector<string>::const_iterator start = form_->bibkeys.begin();
237 int const sel = bibLB->currentItem();
238 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
241 // Find the NEXT instance...
242 if (dir == biblio::FORWARD)
247 bool const caseSensitive = searchCaseCB->isChecked();
249 vector<string>::const_iterator const cit =
250 biblio::searchKeys(theMap, form_->bibkeys, str,
251 start, type, dir, caseSensitive);
253 if (cit == form_->bibkeys.end()) {
257 int const found = int(cit - form_->bibkeys.begin());
262 // Update the display
263 int const top = max(found - 5, 1);
264 bibLB->setTopItem(top);
265 bibLB->setSelected(found, true);
270 void QCitationDialog::slotCitationStyleSelected( int )
276 void QCitationDialog::slotTextBeforeReturn()
282 void QCitationDialog::slotTextAfterReturn()