2001-08-19 13:25:15 +00:00
|
|
|
/**
|
|
|
|
* \file QCitationDialog.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-06-19 03:38:44 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
2001-08-25 03:00:19 +00:00
|
|
|
|
|
|
|
#include "gettext.h"
|
2001-08-19 13:25:15 +00:00
|
|
|
#include "controllers/ControlCitation.h"
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "LyXView.h"
|
|
|
|
#include "buffer.h"
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
#include <qcheckbox.h>
|
2001-08-25 03:00:19 +00:00
|
|
|
#include <qcombobox.h>
|
2001-08-19 13:25:15 +00:00
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qlistbox.h>
|
|
|
|
#include <qmultilineedit.h>
|
|
|
|
#include <qpushbutton.h>
|
2001-08-25 03:00:19 +00:00
|
|
|
|
2002-06-19 03:38:44 +00:00
|
|
|
#include "QCitationDialog.h"
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::find;
|
|
|
|
using std::max;
|
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
QCitationDialog::QCitationDialog(QCitation * form)
|
|
|
|
: QCitationDialogBase(0, 0, false, 0),
|
2001-08-19 13:25:15 +00:00
|
|
|
form_(form)
|
|
|
|
{
|
|
|
|
connect(restorePB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotRestore()));
|
2001-08-25 03:00:19 +00:00
|
|
|
connect(okPB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotOK()));
|
2001-08-19 13:25:15 +00:00
|
|
|
connect(applyPB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotApply()));
|
2001-08-25 03:00:19 +00:00
|
|
|
connect(closePB, SIGNAL(clicked()),
|
|
|
|
form, SLOT(slotClose()));
|
2001-08-23 21:21:50 +00:00
|
|
|
connect(searchED, SIGNAL(returnPressed()),
|
2001-08-25 03:00:19 +00:00
|
|
|
this, SLOT(slotNextClicked()));
|
|
|
|
|
|
|
|
textBeforeED->setText(_("Not yet supported"));
|
|
|
|
textBeforeED->setReadOnly(true);
|
|
|
|
textBeforeED->setFocusPolicy(QWidget::NoFocus);
|
|
|
|
citationStyleCO->setEnabled(false);
|
|
|
|
citationStyleCO->setFocusPolicy(QWidget::NoFocus);
|
2001-08-19 13:25:15 +00:00
|
|
|
}
|
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
QCitationDialog::~QCitationDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
void QCitationDialog::slotBibSelected(int sel)
|
|
|
|
{
|
|
|
|
slotBibHighlighted(sel);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
if (form_->readOnly())
|
2001-08-25 03:00:19 +00:00
|
|
|
return;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
slotAddClicked();
|
|
|
|
}
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
void QCitationDialog::slotBibHighlighted(int sel)
|
2001-08-19 13:25:15 +00:00
|
|
|
{
|
|
|
|
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
|
|
|
|
|
|
|
|
citeLB->clearSelection();
|
|
|
|
|
|
|
|
// FIXME: why would this happen ?
|
|
|
|
if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put into browser_info the additional info associated with
|
|
|
|
// the selected browser_bib key
|
|
|
|
infoML->clear();
|
|
|
|
|
|
|
|
infoML->setText(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
|
|
|
|
|
|
|
|
// 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]);
|
|
|
|
|
|
|
|
if (cit != form_->citekeys.end()) {
|
|
|
|
int const n = int(cit - form_->citekeys.begin());
|
|
|
|
citeLB->setSelected(n, true);
|
|
|
|
citeLB->setTopItem(n);
|
|
|
|
}
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
if (!form_->readOnly()) {
|
2001-08-19 13:25:15 +00:00
|
|
|
if (cit != form_->citekeys.end()) {
|
|
|
|
form_->setBibButtons(QCitation::OFF);
|
|
|
|
form_->setCiteButtons(QCitation::ON);
|
|
|
|
} else {
|
|
|
|
form_->setBibButtons(QCitation::ON);
|
|
|
|
form_->setCiteButtons(QCitation::OFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
void QCitationDialog::slotCiteHighlighted(int sel)
|
2001-08-19 13:25:15 +00:00
|
|
|
{
|
|
|
|
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
|
|
|
|
|
|
|
|
// FIXME: why would this happen ?
|
|
|
|
if (sel < 0 || sel >= (int)form_->citekeys.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
if (!form_->readOnly()) {
|
2001-08-19 13:25:15 +00:00
|
|
|
form_->setBibButtons(QCitation::OFF);
|
|
|
|
form_->setCiteButtons(QCitation::ON);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Highlight the selected browser_cite key in browser_bib
|
|
|
|
vector<string>::const_iterator cit =
|
2001-08-25 03:00:19 +00:00
|
|
|
std::find(form_->bibkeys.begin(),
|
2001-08-19 13:25:15 +00:00
|
|
|
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(biblio::getInfo(theMap, form_->bibkeys[sel]).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QCitationDialog::slotAddClicked()
|
|
|
|
{
|
|
|
|
int const sel = bibLB->currentItem();
|
|
|
|
|
|
|
|
// FIXME: why ?
|
|
|
|
if (sel < 0 || sel >= (int)form_->bibkeys.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the selected browser_bib key to browser_cite
|
|
|
|
citeLB->insertItem(form_->bibkeys[sel].c_str());
|
|
|
|
form_->citekeys.push_back(form_->bibkeys[sel]);
|
|
|
|
|
|
|
|
int const n = int(form_->citekeys.size());
|
|
|
|
citeLB->setSelected(n - 1, true);
|
|
|
|
|
2002-07-22 15:30:24 +00:00
|
|
|
slotBibHighlighted(sel);
|
2001-08-19 13:25:15 +00:00
|
|
|
form_->setBibButtons(QCitation::OFF);
|
|
|
|
form_->setCiteButtons(QCitation::ON);
|
2001-08-21 01:14:54 +00:00
|
|
|
form_->changed();
|
2001-08-19 13:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QCitationDialog::slotDelClicked()
|
|
|
|
{
|
|
|
|
int const sel = citeLB->currentItem();
|
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
// FIXME: why ?
|
2001-08-19 13:25:15 +00:00
|
|
|
if (sel < 0 || sel >= (int)form_->citekeys.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the selected key from browser_cite
|
|
|
|
citeLB->removeItem(sel);
|
|
|
|
form_->citekeys.erase(form_->citekeys.begin() + sel);
|
|
|
|
|
|
|
|
form_->setBibButtons(QCitation::ON);
|
|
|
|
form_->setCiteButtons(QCitation::OFF);
|
2001-08-21 01:14:54 +00:00
|
|
|
form_->changed();
|
2001-08-19 13:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QCitationDialog::slotUpClicked()
|
|
|
|
{
|
|
|
|
int const sel = citeLB->currentItem();
|
|
|
|
|
|
|
|
// FIXME: why ?
|
|
|
|
if (sel < 1 || sel >= (int)form_->citekeys.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move the selected key up one line
|
|
|
|
vector<string>::iterator it = form_->citekeys.begin() + sel;
|
|
|
|
string const tmp = *it;
|
|
|
|
|
|
|
|
citeLB->removeItem(sel);
|
|
|
|
form_->citekeys.erase(it);
|
|
|
|
|
|
|
|
citeLB->insertItem(tmp.c_str(), sel - 1);
|
|
|
|
citeLB->setSelected(sel - 1, true);
|
|
|
|
form_->citekeys.insert(it - 1, tmp);
|
|
|
|
form_->setCiteButtons(QCitation::ON);
|
2001-08-21 01:14:54 +00:00
|
|
|
form_->changed();
|
2001-08-19 13:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QCitationDialog::slotDownClicked()
|
|
|
|
{
|
|
|
|
int const sel = citeLB->currentItem();
|
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
// FIXME: ?
|
2001-08-19 13:25:15 +00:00
|
|
|
if (sel < 0 || sel >= (int)form_->citekeys.size() - 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move the selected key down one line
|
|
|
|
vector<string>::iterator it = form_->citekeys.begin() + sel;
|
|
|
|
string const tmp = *it;
|
|
|
|
|
|
|
|
citeLB->removeItem(sel);
|
|
|
|
form_->citekeys.erase(it);
|
|
|
|
|
|
|
|
citeLB->insertItem(tmp.c_str(), sel + 1);
|
|
|
|
citeLB->setSelected(sel + 1, true);
|
|
|
|
form_->citekeys.insert(it + 1, tmp);
|
|
|
|
form_->setCiteButtons(QCitation::ON);
|
2001-08-21 01:14:54 +00:00
|
|
|
form_->changed();
|
2001-08-19 13:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QCitationDialog::slotPreviousClicked()
|
|
|
|
{
|
|
|
|
doFind(biblio::BACKWARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QCitationDialog::slotNextClicked()
|
|
|
|
{
|
|
|
|
doFind(biblio::FORWARD);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-29 15:37:39 +00:00
|
|
|
void QCitationDialog::doFind(biblio::Direction dir)
|
2001-08-19 13:25:15 +00:00
|
|
|
{
|
|
|
|
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
|
|
|
|
string const str = searchED->text().latin1();
|
|
|
|
|
|
|
|
biblio::Search const type =
|
|
|
|
searchTypeCB->isChecked() ?
|
|
|
|
biblio::REGEX : biblio::SIMPLE;
|
|
|
|
|
|
|
|
vector<string>::const_iterator start = form_->bibkeys.begin();
|
|
|
|
int const sel = bibLB->currentItem();
|
|
|
|
if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
|
|
|
|
start += sel;
|
|
|
|
|
|
|
|
// Find the NEXT instance...
|
|
|
|
if (dir == biblio::FORWARD)
|
|
|
|
start += 1;
|
|
|
|
else
|
|
|
|
start -= 1;
|
|
|
|
|
|
|
|
bool const caseSensitive = searchCaseCB->isChecked();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
vector<string>::const_iterator cit =
|
2001-08-19 13:25:15 +00:00
|
|
|
biblio::searchKeys(theMap, form_->bibkeys, str,
|
2002-07-22 15:30:24 +00:00
|
|
|
start, type, dir, caseSensitive);
|
2001-08-19 13:25:15 +00:00
|
|
|
|
2002-07-22 15:30:24 +00:00
|
|
|
// not found. let's loop round
|
2001-08-19 13:25:15 +00:00
|
|
|
if (cit == form_->bibkeys.end()) {
|
2002-07-22 15:30:24 +00:00
|
|
|
if (dir == biblio::FORWARD) {
|
2001-08-25 20:04:15 +00:00
|
|
|
start = form_->bibkeys.begin();
|
2002-07-22 15:30:24 +00:00
|
|
|
}
|
|
|
|
else start = form_->bibkeys.end() - 1;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
cit = biblio::searchKeys(theMap, form_->bibkeys, str,
|
2002-07-22 15:30:24 +00:00
|
|
|
start, type, dir, caseSensitive);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
if (cit == form_->bibkeys.end())
|
|
|
|
return;
|
2001-08-19 13:25:15 +00:00
|
|
|
}
|
2002-07-22 15:30:24 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
int const found = int(cit - form_->bibkeys.begin());
|
|
|
|
if (found == sel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the display
|
|
|
|
int const top = max(found - 5, 1);
|
|
|
|
bibLB->setTopItem(top);
|
|
|
|
bibLB->setSelected(found, true);
|
2001-08-25 03:00:19 +00:00
|
|
|
slotBibHighlighted(0);
|
2001-08-19 13:25:15 +00:00
|
|
|
}
|