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);
146 void QCitationDialog::slotDelClicked()
148 int const sel = citeLB->currentItem();
151 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
155 // Remove the selected key from browser_cite
156 citeLB->removeItem(sel);
157 form_->citekeys.erase(form_->citekeys.begin() + sel);
159 form_->setBibButtons(QCitation::ON);
160 form_->setCiteButtons(QCitation::OFF);
164 void QCitationDialog::slotUpClicked()
166 int const sel = citeLB->currentItem();
169 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
173 // Move the selected key up one line
174 vector<string>::iterator it = form_->citekeys.begin() + sel;
175 string const tmp = *it;
177 citeLB->removeItem(sel);
178 form_->citekeys.erase(it);
180 citeLB->insertItem(tmp.c_str(), sel - 1);
181 citeLB->setSelected(sel - 1, true);
182 form_->citekeys.insert(it - 1, tmp);
183 form_->setCiteButtons(QCitation::ON);
187 void QCitationDialog::slotDownClicked()
189 int const sel = citeLB->currentItem();
192 if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
196 // Move the selected key down one line
197 vector<string>::iterator it = form_->citekeys.begin() + sel;
198 string const tmp = *it;
200 citeLB->removeItem(sel);
201 form_->citekeys.erase(it);
203 citeLB->insertItem(tmp.c_str(), sel + 1);
204 citeLB->setSelected(sel + 1, true);
205 form_->citekeys.insert(it + 1, tmp);
206 form_->setCiteButtons(QCitation::ON);
210 void QCitationDialog::slotPreviousClicked()
212 doFind(biblio::BACKWARD);
216 void QCitationDialog::slotNextClicked()
218 doFind(biblio::FORWARD);
222 void QCitationDialog::doFind(biblio::Direction const dir)
224 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
225 string const str = searchED->text().latin1();
227 biblio::Search const type =
228 searchTypeCB->isChecked() ?
229 biblio::REGEX : biblio::SIMPLE;
231 vector<string>::const_iterator start = form_->bibkeys.begin();
232 int const sel = bibLB->currentItem();
233 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
236 // Find the NEXT instance...
237 if (dir == biblio::FORWARD)
242 bool const caseSensitive = searchCaseCB->isChecked();
244 vector<string>::const_iterator const cit =
245 biblio::searchKeys(theMap, form_->bibkeys, str,
246 start, type, dir, caseSensitive);
248 if (cit == form_->bibkeys.end()) {
252 int const found = int(cit - form_->bibkeys.begin());
257 // Update the display
258 int const top = max(found - 5, 1);
259 bibLB->setTopItem(top);
260 bibLB->setSelected(found, true);
265 void QCitationDialog::slotCitationStyleSelected( int )
270 void QCitationDialog::slotTextBeforeReturn()
275 void QCitationDialog::slotTextAfterReturn()