2001-08-19 13:25:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file QCitationDialog.C
|
2002-09-24 13:57:09 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-08-19 13:25:15 +00:00
|
|
|
|
*
|
2002-09-24 13:57:09 +00:00
|
|
|
|
* \author Kalle Dalheimer
|
2004-02-18 14:02:49 +00:00
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>ller
|
2002-09-24 13:57:09 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-08-19 13:25:15 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2004-05-20 09:36:28 +00:00
|
|
|
|
#include "QCitationDialog.h"
|
|
|
|
|
#include "ui/QCitationFindDialogBase.h"
|
|
|
|
|
#include "QCitation.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
|
#include "qt_helpers.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
#include "controllers/ControlCitation.h"
|
2004-05-20 09:36:28 +00:00
|
|
|
|
#include "controllers/ButtonController.h"
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
|
|
#include <qcheckbox.h>
|
|
|
|
|
#include <qlineedit.h>
|
|
|
|
|
#include <qlistbox.h>
|
|
|
|
|
#include <qmultilineedit.h>
|
|
|
|
|
#include <qpushbutton.h>
|
2001-08-25 03:00:19 +00:00
|
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
using std::vector;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2006-02-15 11:13:37 +00:00
|
|
|
|
using std::swap;
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
namespace frontend {
|
2002-10-20 01:48:28 +00:00
|
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
|
QCitationDialog::QCitationDialog(QCitation * form)
|
2004-06-02 20:13:18 +00:00
|
|
|
|
: 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()));
|
2003-04-12 02:23:02 +00:00
|
|
|
|
|
|
|
|
|
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()));
|
2003-04-23 16:59:45 +00:00
|
|
|
|
connect(selectedLB, SIGNAL(returnPressed(QListBoxItem *)), form, SLOT(slotOK()));
|
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()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
void QCitationDialog::setButtons()
|
2001-08-25 03:00:19 +00:00
|
|
|
|
{
|
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
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
int const sel_nr = selectedLB->currentItem();
|
2003-04-12 02:23:02 +00:00
|
|
|
|
int const avail_nr = add_->availableLB->currentItem();
|
2003-04-04 03:19:00 +00:00
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
|
add_->addPB->setEnabled(avail_nr >= 0);
|
|
|
|
|
deletePB->setEnabled(sel_nr >= 0);
|
2003-04-04 03:19:00 +00:00
|
|
|
|
upPB->setEnabled(sel_nr > 0);
|
|
|
|
|
downPB->setEnabled(sel_nr >= 0 && sel_nr < int(selectedLB->count() - 1));
|
2001-08-25 03:00:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2004-02-18 14:02:49 +00:00
|
|
|
|
void QCitationDialog::openFind()
|
|
|
|
|
{
|
|
|
|
|
if (form_->readOnly())
|
|
|
|
|
return;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2005-10-06 08:44:03 +00:00
|
|
|
|
if (isVisible() && selectedLB->count() == 0
|
|
|
|
|
&& add_->availableLB->count() != 0){
|
2004-02-18 14:02:49 +00:00
|
|
|
|
// open the find dialog
|
|
|
|
|
add();
|
|
|
|
|
// and let the user press ok after a selection
|
|
|
|
|
if (selectedLB->count() != 0)
|
|
|
|
|
form_->bc().valid();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
void QCitationDialog::selectedChanged()
|
2001-08-19 13:25:15 +00:00
|
|
|
|
{
|
2003-04-04 03:19:00 +00:00
|
|
|
|
form_->fillStyles();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
|
2003-04-04 03:19:00 +00:00
|
|
|
|
infoML->clear();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
int const sel = selectedLB->currentItem();
|
|
|
|
|
if (sel < 0) {
|
|
|
|
|
setButtons();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-11 14:42:39 +00:00
|
|
|
|
if (!theMap.empty())
|
|
|
|
|
infoML->setText(
|
|
|
|
|
toqstr(biblio::getInfo(theMap, form_->citekeys[sel])));
|
2003-04-12 02:23:02 +00:00
|
|
|
|
setButtons();
|
|
|
|
|
}
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
|
void QCitationDialog::previous()
|
|
|
|
|
{
|
|
|
|
|
find(biblio::BACKWARD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QCitationDialog::next()
|
|
|
|
|
{
|
|
|
|
|
find(biblio::FORWARD);
|
2001-08-19 13:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
void QCitationDialog::availableChanged()
|
2001-08-19 13:25:15 +00:00
|
|
|
|
{
|
|
|
|
|
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
|
2003-04-12 02:23:02 +00:00
|
|
|
|
add_->infoML->clear();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
|
int const sel = add_->availableLB->currentItem();
|
2003-04-04 03:19:00 +00:00
|
|
|
|
if (sel < 0) {
|
|
|
|
|
setButtons();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-11 14:42:39 +00:00
|
|
|
|
if (!theMap.empty())
|
|
|
|
|
add_->infoML->setText(
|
|
|
|
|
toqstr(biblio::getInfo(theMap, form_->bibkeys[sel])));
|
2003-04-04 03:19:00 +00:00
|
|
|
|
setButtons();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
|
void QCitationDialog::addCitation()
|
2001-08-19 13:25:15 +00:00
|
|
|
|
{
|
2003-04-12 02:23:02 +00:00
|
|
|
|
int const sel = add_->availableLB->currentItem();
|
|
|
|
|
|
|
|
|
|
if (sel < 0)
|
|
|
|
|
return;
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2003-07-21 09:08:14 +00:00
|
|
|
|
// 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]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
|
|
int const n = int(form_->citekeys.size());
|
2003-04-04 03:19:00 +00:00
|
|
|
|
selectedLB->setSelected(n - 1, true);
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2001-08-21 01:14:54 +00:00
|
|
|
|
form_->changed();
|
2002-12-18 20:48:26 +00:00
|
|
|
|
form_->fillStyles();
|
2003-04-04 03:19:00 +00:00
|
|
|
|
setButtons();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
void QCitationDialog::del()
|
2001-08-19 13:25:15 +00:00
|
|
|
|
{
|
2003-04-04 03:19:00 +00:00
|
|
|
|
int const sel = selectedLB->currentItem();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
|
|
// Remove the selected key from browser_cite
|
2003-04-04 03:19:00 +00:00
|
|
|
|
selectedLB->removeItem(sel);
|
2001-08-19 13:25:15 +00:00
|
|
|
|
form_->citekeys.erase(form_->citekeys.begin() + sel);
|
|
|
|
|
|
2001-08-21 01:14:54 +00:00
|
|
|
|
form_->changed();
|
2002-12-18 20:48:26 +00:00
|
|
|
|
form_->fillStyles();
|
2003-04-04 03:19:00 +00:00
|
|
|
|
setButtons();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
void QCitationDialog::up()
|
2001-08-19 13:25:15 +00:00
|
|
|
|
{
|
2003-04-04 03:19:00 +00:00
|
|
|
|
int const sel = selectedLB->currentItem();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2006-02-15 14:12:54 +00:00
|
|
|
|
BOOST_ASSERT(sel > 0);
|
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
// Move the selected key up one line
|
2006-02-15 14:12:54 +00:00
|
|
|
|
string const tmp = form_->citekeys[sel];
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
selectedLB->removeItem(sel);
|
2006-02-15 11:13:37 +00:00
|
|
|
|
swap(form_->citekeys[sel - 1], form_->citekeys[sel]);
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
selectedLB->insertItem(toqstr(tmp), sel - 1);
|
|
|
|
|
selectedLB->setSelected(sel - 1, true);
|
|
|
|
|
|
2001-08-21 01:14:54 +00:00
|
|
|
|
form_->changed();
|
2002-12-18 20:48:26 +00:00
|
|
|
|
form_->fillStyles();
|
2003-04-04 03:19:00 +00:00
|
|
|
|
setButtons();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
void QCitationDialog::down()
|
2001-08-19 13:25:15 +00:00
|
|
|
|
{
|
2003-04-04 03:19:00 +00:00
|
|
|
|
int const sel = selectedLB->currentItem();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2006-02-15 14:12:54 +00:00
|
|
|
|
BOOST_ASSERT(sel < (int)form_->citekeys.size());
|
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
|
// Move the selected key down one line
|
2006-02-15 14:12:54 +00:00
|
|
|
|
string const tmp = form_->citekeys[sel];
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
selectedLB->removeItem(sel);
|
2006-02-15 11:13:37 +00:00
|
|
|
|
swap(form_->citekeys[sel + 1], form_->citekeys[sel]);
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
|
selectedLB->insertItem(toqstr(tmp), sel + 1);
|
|
|
|
|
selectedLB->setSelected(sel + 1, true);
|
|
|
|
|
|
2001-08-21 01:14:54 +00:00
|
|
|
|
form_->changed();
|
2002-12-18 20:48:26 +00:00
|
|
|
|
form_->fillStyles();
|
2003-04-04 03:19:00 +00:00
|
|
|
|
setButtons();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
|
void QCitationDialog::add()
|
2001-08-19 13:25:15 +00:00
|
|
|
|
{
|
2003-04-12 02:23:02 +00:00
|
|
|
|
add_->exec();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-24 13:57:09 +00:00
|
|
|
|
void QCitationDialog::changed_adaptor()
|
|
|
|
|
{
|
|
|
|
|
form_->changed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
|
void QCitationDialog::find(biblio::Direction dir)
|
2001-08-19 13:25:15 +00:00
|
|
|
|
{
|
|
|
|
|
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
|
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
|
biblio::Search const type = add_->searchTypeCB->isChecked()
|
2003-10-06 15:43:21 +00:00
|
|
|
|
? biblio::REGEX : biblio::SIMPLE;
|
2001-08-19 13:25:15 +00:00
|
|
|
|
|
|
|
|
|
vector<string>::const_iterator start = form_->bibkeys.begin();
|
2003-04-12 02:23:02 +00:00
|
|
|
|
int const sel = add_->availableLB->currentItem();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
if (sel >= 0 && sel <= int(form_->bibkeys.size()-1))
|
|
|
|
|
start += sel;
|
|
|
|
|
|
|
|
|
|
// Find the NEXT instance...
|
|
|
|
|
if (dir == biblio::FORWARD)
|
|
|
|
|
start += 1;
|
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
|
bool const casesens = add_->searchCaseCB->isChecked();
|
|
|
|
|
string const str = fromqstr(add_->searchED->text());
|
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,
|
2003-04-12 02:23:02 +00:00
|
|
|
|
start, type, dir, casesens);
|
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,
|
2003-04-12 02:23:02 +00:00
|
|
|
|
start, type, dir, casesens);
|
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-09-24 13:57:09 +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
|
2005-05-21 10:36:10 +00:00
|
|
|
|
// note that we have multi selection mode!
|
|
|
|
|
add_->availableLB->setSelected(sel, false);
|
2003-04-12 02:23:02 +00:00
|
|
|
|
add_->availableLB->setSelected(found, true);
|
2005-05-21 10:36:10 +00:00
|
|
|
|
add_->availableLB->setCurrentItem(found);
|
2003-04-12 02:23:02 +00:00
|
|
|
|
add_->availableLB->ensureCurrentVisible();
|
2001-08-19 13:25:15 +00:00
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
|
} // namespace lyx
|