2 * \file QCitationDialog.C
3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
13 #include "QCitationDialog.h"
15 #include "controllers/ControlCitation.h"
17 #include <qcheckbox.h>
18 #include <qcombobox.h>
19 #include <qlineedit.h>
21 #include <qmultilineedit.h>
22 #include <qpushbutton.h>
24 #include "QtLyXView.h"
33 QCitationDialog::QCitationDialog(QCitation * form)
34 : QCitationDialogBase(0, 0, false, 0),
37 connect(restorePB, SIGNAL(clicked()),
38 form, SLOT(slotRestore()));
39 connect(okPB, SIGNAL(clicked()),
40 form, SLOT(slotOK()));
41 connect(applyPB, SIGNAL(clicked()),
42 form, SLOT(slotApply()));
43 connect(closePB, SIGNAL(clicked()),
44 form, SLOT(slotClose()));
45 connect(searchED, SIGNAL(returnPressed()),
46 this, SLOT(slotNextClicked()));
48 textBeforeED->setText(_("Not yet supported"));
49 textBeforeED->setReadOnly(true);
50 textBeforeED->setFocusPolicy(QWidget::NoFocus);
51 citationStyleCO->setEnabled(false);
52 citationStyleCO->setFocusPolicy(QWidget::NoFocus);
56 QCitationDialog::~QCitationDialog()
61 void QCitationDialog::slotBibSelected(int sel)
63 slotBibHighlighted(sel);
65 if (form_->controller().isReadonly())
72 void QCitationDialog::slotBibHighlighted(int sel)
74 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
76 citeLB->clearSelection();
78 // FIXME: why would this happen ?
79 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
83 // Put into browser_info the additional info associated with
84 // the selected browser_bib key
87 infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
89 // Highlight the selected browser_bib key in browser_cite if
91 vector<string>::const_iterator cit =
92 std::find(form_->citekeys.begin(), form_->citekeys.end(),
95 if (cit != form_->citekeys.end()) {
96 int const n = int(cit - form_->citekeys.begin());
97 citeLB->setSelected(n, true);
98 citeLB->setTopItem(n);
101 if (!form_->controller().isReadonly()) {
102 if (cit != form_->citekeys.end()) {
103 form_->setBibButtons(QCitation::OFF);
104 form_->setCiteButtons(QCitation::ON);
106 form_->setBibButtons(QCitation::ON);
107 form_->setCiteButtons(QCitation::OFF);
113 void QCitationDialog::slotCiteHighlighted(int sel)
115 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
117 // FIXME: why would this happen ?
118 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
122 if (!form_->controller().isReadonly()) {
123 form_->setBibButtons(QCitation::OFF);
124 form_->setCiteButtons(QCitation::ON);
127 // Highlight the selected browser_cite key in browser_bib
128 vector<string>::const_iterator cit =
129 std::find(form_->bibkeys.begin(),
130 form_->bibkeys.end(), form_->citekeys[sel]);
132 if (cit != form_->bibkeys.end()) {
133 int const n = int(cit - form_->bibkeys.begin());
134 bibLB->setSelected(n, true);
135 bibLB->setTopItem(n);
137 // Put into browser_info the additional info associated
138 // with the selected browser_cite key
140 infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
145 void QCitationDialog::slotAddClicked()
147 int const sel = bibLB->currentItem();
150 if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
154 // Add the selected browser_bib key to browser_cite
155 citeLB->insertItem(form_->bibkeys[sel].c_str());
156 form_->citekeys.push_back(form_->bibkeys[sel]);
158 int const n = int(form_->citekeys.size());
159 citeLB->setSelected(n - 1, true);
161 form_->setBibButtons(QCitation::OFF);
162 form_->setCiteButtons(QCitation::ON);
167 void QCitationDialog::slotDelClicked()
169 int const sel = citeLB->currentItem();
172 if (sel < 0 || sel >= (int)form_->citekeys.size()) {
176 // Remove the selected key from browser_cite
177 citeLB->removeItem(sel);
178 form_->citekeys.erase(form_->citekeys.begin() + sel);
180 form_->setBibButtons(QCitation::ON);
181 form_->setCiteButtons(QCitation::OFF);
186 void QCitationDialog::slotUpClicked()
188 int const sel = citeLB->currentItem();
191 if (sel < 1 || sel >= (int)form_->citekeys.size()) {
195 // Move the selected key up one line
196 vector<string>::iterator it = form_->citekeys.begin() + sel;
197 string const tmp = *it;
199 citeLB->removeItem(sel);
200 form_->citekeys.erase(it);
202 citeLB->insertItem(tmp.c_str(), sel - 1);
203 citeLB->setSelected(sel - 1, true);
204 form_->citekeys.insert(it - 1, tmp);
205 form_->setCiteButtons(QCitation::ON);
210 void QCitationDialog::slotDownClicked()
212 int const sel = citeLB->currentItem();
215 if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
219 // Move the selected key down one line
220 vector<string>::iterator it = form_->citekeys.begin() + sel;
221 string const tmp = *it;
223 citeLB->removeItem(sel);
224 form_->citekeys.erase(it);
226 citeLB->insertItem(tmp.c_str(), sel + 1);
227 citeLB->setSelected(sel + 1, true);
228 form_->citekeys.insert(it + 1, tmp);
229 form_->setCiteButtons(QCitation::ON);
234 void QCitationDialog::slotPreviousClicked()
236 doFind(biblio::BACKWARD);
240 void QCitationDialog::slotNextClicked()
242 doFind(biblio::FORWARD);
246 void QCitationDialog::doFind(biblio::Direction const dir)
248 biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
249 string const str = searchED->text().latin1();
251 biblio::Search const type =
252 searchTypeCB->isChecked() ?
253 biblio::REGEX : biblio::SIMPLE;
255 vector<string>::const_iterator start = form_->bibkeys.begin();
256 int const sel = bibLB->currentItem();
257 if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
260 // Find the NEXT instance...
261 if (dir == biblio::FORWARD)
266 bool const caseSensitive = searchCaseCB->isChecked();
268 vector<string>::const_iterator const cit =
269 biblio::searchKeys(theMap, form_->bibkeys, str,
270 start, type, dir, caseSensitive);
272 if (cit == form_->bibkeys.end()) {
276 int const found = int(cit - form_->bibkeys.begin());
281 // Update the display
282 int const top = max(found - 5, 1);
283 bibLB->setTopItem(top);
284 bibLB->setSelected(found, true);
285 slotBibHighlighted(0);