#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
#include <algorithm>
#include "qt_helpers.h"
#include "controllers/ControlCitation.h"
-#include "LyXView.h"
-#include "buffer.h"
+#include "debug.h"
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qlistbox.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
+#include <qlabel.h>
+#include "ui/QCitationFindDialogBase.h"
#include "QCitationDialog.h"
#include "QCitation.h"
#include "support/lstrings.h"
using std::vector;
using std::find;
using std::max;
+using std::endl;
QCitationDialog::QCitationDialog(QCitation * form)
form, SLOT(slotApply()));
connect(closePB, SIGNAL(clicked()),
form, SLOT(slotClose()));
- connect(searchED, SIGNAL(returnPressed()),
- this, SLOT(slotNextClicked()));
-
- textBeforeED->setText(qt_("Not yet supported"));
- textBeforeED->setReadOnly(true);
- textBeforeED->setFocusPolicy(QWidget::NoFocus);
- citationStyleCO->setEnabled(false);
- citationStyleCO->setFocusPolicy(QWidget::NoFocus);
+
+ add_ = new QCitationFindDialogBase(this, "", true);
+ connect(add_->previousPB, SIGNAL(clicked()), this, SLOT(previous()));
+ connect(add_->nextPB, SIGNAL(clicked()), this, SLOT(next()));
+ connect(add_->availableLB, SIGNAL(currentChanged(QListBoxItem *)), this, SLOT(availableChanged()));
+ connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), this, SLOT(addCitation()));
+ connect(add_->availableLB, SIGNAL(selected(QListBoxItem *)), add_, SLOT(accept()));
+ connect(add_->addPB, SIGNAL(clicked()), this, SLOT(addCitation()));
+ connect(selectedLB, SIGNAL(returnPressed(QListBoxItem *)), form, SLOT(slotOK()));
}
}
-void QCitationDialog::slotBibSelected(int sel)
+void QCitationDialog::setButtons()
{
- slotBibHighlighted(sel);
-
if (form_->readOnly())
return;
- slotAddClicked();
+ int const sel_nr = selectedLB->currentItem();
+ int const avail_nr = add_->availableLB->currentItem();
+
+ add_->addPB->setEnabled(avail_nr >= 0);
+ deletePB->setEnabled(sel_nr >= 0);
+ upPB->setEnabled(sel_nr > 0);
+ downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1));
}
-void QCitationDialog::slotBibHighlighted(int sel)
+void QCitationDialog::selectedChanged()
{
+ form_->fillStyles();
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
+ infoML->clear();
- citeLB->clearSelection();
-
- // FIXME: why would this happen ?
- if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
+ int const sel = selectedLB->currentItem();
+ if (sel < 0) {
+ setButtons();
return;
}
- // Put into browser_info the additional info associated with
- // the selected browser_bib key
- infoML->clear();
+ infoML->setText(toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
+ setButtons();
+}
- infoML->setText(toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
- // Highlight the selected browser_bib key in browser_cite if
- // present
- vector<string>::const_iterator cit =
- std::find(form_->citekeys.begin(), form_->citekeys.end(),
- form_->bibkeys[sel]);
+void QCitationDialog::previous()
+{
+ find(biblio::BACKWARD);
+}
- if (cit != form_->citekeys.end()) {
- int const n = int(cit - form_->citekeys.begin());
- citeLB->setSelected(n, true);
- citeLB->setTopItem(n);
- }
- if (!form_->readOnly()) {
- if (cit != form_->citekeys.end()) {
- form_->setBibButtons(QCitation::OFF);
- form_->setCiteButtons(QCitation::ON);
- } else {
- form_->setBibButtons(QCitation::ON);
- form_->setCiteButtons(QCitation::OFF);
- }
- }
+void QCitationDialog::next()
+{
+ find(biblio::FORWARD);
}
-void QCitationDialog::slotCiteHighlighted(int sel)
+void QCitationDialog::availableChanged()
{
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
+ add_->infoML->clear();
- // FIXME: why would this happen ?
- if (sel < 0 || sel >= (int)form_->citekeys.size()) {
+ int const sel = add_->availableLB->currentItem();
+ if (sel < 0) {
+ setButtons();
return;
}
- if (!form_->readOnly()) {
- form_->setBibButtons(QCitation::OFF);
- form_->setCiteButtons(QCitation::ON);
- }
-
- // Highlight the selected browser_cite key in browser_bib
- vector<string>::const_iterator cit =
- std::find(form_->bibkeys.begin(),
- form_->bibkeys.end(), form_->citekeys[sel]);
-
- if (cit != form_->bibkeys.end()) {
- int const n = int(cit - form_->bibkeys.begin());
- bibLB->setSelected(n, true);
- bibLB->setTopItem(n);
-
- // Put into browser_info the additional info associated
- // with the selected browser_cite key
- infoML->clear();
- infoML->setText(toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
- }
+ add_->infoML->setText(toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
+ setButtons();
}
-void QCitationDialog::slotAddClicked()
+void QCitationDialog::addCitation()
{
- int const sel = bibLB->currentItem();
+ int const sel = add_->availableLB->currentItem();
- // FIXME: why ?
- if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
+ if (sel < 0)
return;
- }
- // Add the selected browser_bib key to browser_cite
- citeLB->insertItem(toqstr(form_->bibkeys[sel]));
- form_->citekeys.push_back(form_->bibkeys[sel]);
+ // Add the selected browser_bib keys to browser_cite
+ // multiple selections are possible
+ for (unsigned int i = 0; i != add_->availableLB->count(); i++) {
+ if (add_->availableLB->isSelected(i)) {
+ // do not allow duplicates
+ if ((selectedLB->findItem(add_->availableLB->text(i))) == 0) {
+ selectedLB->insertItem(toqstr(form_->bibkeys[i]));
+ form_->citekeys.push_back(form_->bibkeys[i]);
+ }
+ }
+ }
int const n = int(form_->citekeys.size());
- citeLB->setSelected(n - 1, true);
+ selectedLB->setSelected(n - 1, true);
- slotBibHighlighted(sel);
- form_->setBibButtons(QCitation::OFF);
- form_->setCiteButtons(QCitation::ON);
form_->changed();
+ form_->fillStyles();
+ setButtons();
}
-void QCitationDialog::slotDelClicked()
+void QCitationDialog::del()
{
- int const sel = citeLB->currentItem();
-
- // FIXME: why ?
- if (sel < 0 || sel >= (int)form_->citekeys.size()) {
- return;
- }
+ int const sel = selectedLB->currentItem();
// Remove the selected key from browser_cite
- citeLB->removeItem(sel);
+ selectedLB->removeItem(sel);
form_->citekeys.erase(form_->citekeys.begin() + sel);
- form_->setBibButtons(QCitation::ON);
- form_->setCiteButtons(QCitation::OFF);
form_->changed();
+ form_->fillStyles();
+ setButtons();
}
-void QCitationDialog::slotUpClicked()
+void QCitationDialog::up()
{
- int const sel = citeLB->currentItem();
-
- // FIXME: why ?
- if (sel < 1 || sel >= (int)form_->citekeys.size()) {
- return;
- }
+ int const sel = selectedLB->currentItem();
// Move the selected key up one line
vector<string>::iterator it = form_->citekeys.begin() + sel;
string const tmp = *it;
- citeLB->removeItem(sel);
+ selectedLB->removeItem(sel);
form_->citekeys.erase(it);
- citeLB->insertItem(toqstr(tmp), sel - 1);
- citeLB->setSelected(sel - 1, true);
+ selectedLB->insertItem(toqstr(tmp), sel - 1);
+ selectedLB->setSelected(sel - 1, true);
form_->citekeys.insert(it - 1, tmp);
- form_->setCiteButtons(QCitation::ON);
+
form_->changed();
+ form_->fillStyles();
+ setButtons();
}
-void QCitationDialog::slotDownClicked()
+void QCitationDialog::down()
{
- int const sel = citeLB->currentItem();
-
- // FIXME: ?
- if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
- return;
- }
+ int const sel = selectedLB->currentItem();
// Move the selected key down one line
vector<string>::iterator it = form_->citekeys.begin() + sel;
string const tmp = *it;
- citeLB->removeItem(sel);
+ selectedLB->removeItem(sel);
form_->citekeys.erase(it);
- citeLB->insertItem(toqstr(tmp), sel + 1);
- citeLB->setSelected(sel + 1, true);
+ selectedLB->insertItem(toqstr(tmp), sel + 1);
+ selectedLB->setSelected(sel + 1, true);
form_->citekeys.insert(it + 1, tmp);
- form_->setCiteButtons(QCitation::ON);
- form_->changed();
-}
-
-void QCitationDialog::slotPreviousClicked()
-{
- doFind(biblio::BACKWARD);
+ form_->changed();
+ form_->fillStyles();
+ setButtons();
}
-void QCitationDialog::slotNextClicked()
+void QCitationDialog::add()
{
- doFind(biblio::FORWARD);
+ add_->exec();
}
}
-void QCitationDialog::doFind(biblio::Direction dir)
+void QCitationDialog::find(biblio::Direction dir)
{
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
- string const str = fromqstr(searchED->text());
- biblio::Search const type =
- searchTypeCB->isChecked() ?
- biblio::REGEX : biblio::SIMPLE;
+ biblio::Search const type = add_->searchTypeCB->isChecked()
+ ? biblio::REGEX : biblio::SIMPLE;
vector<string>::const_iterator start = form_->bibkeys.begin();
- int const sel = bibLB->currentItem();
+ int const sel = add_->availableLB->currentItem();
if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
start += sel;
else
start -= 1;
- bool const caseSensitive = searchCaseCB->isChecked();
+ bool const casesens = add_->searchCaseCB->isChecked();
+ string const str = fromqstr(add_->searchED->text());
vector<string>::const_iterator cit =
biblio::searchKeys(theMap, form_->bibkeys, str,
- start, type, dir, caseSensitive);
+ start, type, dir, casesens);
// not found. let's loop round
if (cit == form_->bibkeys.end()) {
else start = form_->bibkeys.end() - 1;
cit = biblio::searchKeys(theMap, form_->bibkeys, str,
- start, type, dir, caseSensitive);
+ start, type, dir, casesens);
if (cit == form_->bibkeys.end())
return;
}
// Update the display
- int const top = max(found - 5, 1);
- bibLB->setTopItem(top);
- bibLB->setSelected(found, true);
- slotBibHighlighted(0);
+ add_->availableLB->setSelected(found, true);
+ add_->availableLB->ensureCurrentVisible();
}