2001-08-19 13:25:15 +00:00
|
|
|
/**
|
|
|
|
* \file QCitation.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-03-29 18:58:47 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Kalle Dalheimer
|
2002-09-24 13:57:09 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-03-16 17:20:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2003-04-12 02:23:02 +00:00
|
|
|
#include "ui/QCitationFindDialogBase.h"
|
2001-08-19 13:25:15 +00:00
|
|
|
#include "QCitationDialog.h"
|
|
|
|
#include "QCitation.h"
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-31 08:39:24 +00:00
|
|
|
#include <qcheckbox.h>
|
2001-03-29 18:58:47 +00:00
|
|
|
#include <qcombobox.h>
|
2001-03-16 17:20:06 +00:00
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qlistbox.h>
|
|
|
|
#include <qmultilineedit.h>
|
|
|
|
#include <qpushbutton.h>
|
2003-04-04 03:19:00 +00:00
|
|
|
#include <qlabel.h>
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
#include "QtLyXView.h"
|
2001-08-23 21:21:50 +00:00
|
|
|
#include "Qt2BC.h"
|
2001-03-29 18:58:47 +00:00
|
|
|
#include "ControlCitation.h"
|
2001-08-25 03:00:19 +00:00
|
|
|
#include "debug.h"
|
2002-12-17 20:37:13 +00:00
|
|
|
#include "qt_helpers.h"
|
2001-03-29 18:58:47 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
#include "helper_funcs.h"
|
2001-03-16 17:20:06 +00:00
|
|
|
|
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
using std::find;
|
|
|
|
using std::max;
|
|
|
|
using std::min;
|
|
|
|
using std::pair;
|
|
|
|
using std::sort;
|
|
|
|
using std::vector;
|
2001-03-26 19:34:45 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
typedef QController<ControlCitation, QView<QCitationDialog> > base_class;
|
2001-03-26 19:34:45 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
QCitation::QCitation(Dialog & parent)
|
2003-04-30 02:09:06 +00:00
|
|
|
: base_class(parent, qt_("LyX: Citation Reference"))
|
2001-03-29 18:58:47 +00:00
|
|
|
{}
|
2001-03-16 17:20:06 +00:00
|
|
|
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QCitation::apply()
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2002-01-20 17:02:09 +00:00
|
|
|
vector<biblio::CiteStyle> const & styles =
|
|
|
|
ControlCitation::getCiteStyles();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
int const choice = dialog_->citationStyleCO->currentItem();
|
|
|
|
bool const full = dialog_->fulllistCB->isChecked();
|
|
|
|
bool const force = dialog_->forceuppercaseCB->isChecked();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
string const command =
|
|
|
|
biblio::getCiteCommand(styles[choice], full, force);
|
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
controller().params().setCmdName(command);
|
2001-06-05 17:05:51 +00:00
|
|
|
controller().params().setContents(getStringFromVector(citekeys));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
string const after = fromqstr(dialog_->textAfterED->text());
|
2001-06-05 17:05:51 +00:00
|
|
|
controller().params().setOptions(after);
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QCitation::hide()
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2001-06-05 17:05:51 +00:00
|
|
|
citekeys.clear();
|
|
|
|
bibkeys.clear();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2003-02-25 14:51:38 +00:00
|
|
|
QDialogView::hide();
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-26 00:29:39 +00:00
|
|
|
void QCitation::build_dialog()
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2001-08-19 13:25:15 +00:00
|
|
|
dialog_.reset(new QCitationDialog(this));
|
2001-06-05 17:05:51 +00:00
|
|
|
|
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setOK(dialog_->okPB);
|
|
|
|
bcview().setApply(dialog_->applyPB);
|
|
|
|
bcview().setCancel(dialog_->closePB);
|
|
|
|
bcview().setRestore(dialog_->restorePB);
|
|
|
|
|
|
|
|
bcview().addReadOnly(dialog_->addPB);
|
2003-04-12 02:23:02 +00:00
|
|
|
bcview().addReadOnly(dialog_->deletePB);
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().addReadOnly(dialog_->upPB);
|
|
|
|
bcview().addReadOnly(dialog_->downPB);
|
|
|
|
bcview().addReadOnly(dialog_->citationStyleCO);
|
|
|
|
bcview().addReadOnly(dialog_->forceuppercaseCB);
|
|
|
|
bcview().addReadOnly(dialog_->fulllistCB);
|
2002-03-21 21:21:28 +00:00
|
|
|
// add when enabled !
|
2003-03-10 03:13:28 +00:00
|
|
|
//bcview().addReadOnly(dialog_->textBeforeED);
|
|
|
|
bcview().addReadOnly(dialog_->textAfterED);
|
2001-08-19 13:25:15 +00:00
|
|
|
}
|
2001-03-29 18:58:47 +00:00
|
|
|
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
void QCitation::fillStyles()
|
|
|
|
{
|
2003-04-04 03:19:00 +00:00
|
|
|
if (citekeys.empty()) {
|
|
|
|
dialog_->citationStyleCO->setEnabled(false);
|
|
|
|
dialog_->citationStyleLA->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
2002-01-20 17:02:09 +00:00
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
int const orig = dialog_->citationStyleCO->currentItem();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
dialog_->citationStyleCO->clear();
|
2003-04-04 03:19:00 +00:00
|
|
|
|
|
|
|
int curr = dialog_->selectedLB->currentItem();
|
|
|
|
if (curr < 0)
|
|
|
|
curr = 0;
|
|
|
|
|
|
|
|
string key = citekeys[curr];
|
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
vector<string> const & sty = controller().getCiteStrings(key);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2003-04-04 03:19:00 +00:00
|
|
|
bool const natbib = controller().usingNatbib();
|
|
|
|
dialog_->citationStyleCO->setEnabled(!sty.empty() && natbib);
|
|
|
|
dialog_->citationStyleLA->setEnabled(!sty.empty() && natbib);
|
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
for (vector<string>::const_iterator it = sty.begin();
|
|
|
|
it != sty.end(); ++it) {
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->citationStyleCO->insertItem(toqstr(*it));
|
2002-01-20 17:02:09 +00:00
|
|
|
}
|
2003-04-04 03:19:00 +00:00
|
|
|
|
|
|
|
if (orig != -1 && orig < dialog_->citationStyleCO->count())
|
|
|
|
dialog_->citationStyleCO->setCurrentItem(orig);
|
2002-01-20 17:02:09 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
|
|
|
|
void QCitation::updateStyle()
|
|
|
|
{
|
2003-04-04 03:19:00 +00:00
|
|
|
bool const natbib = controller().usingNatbib();
|
|
|
|
|
|
|
|
dialog_->fulllistCB->setEnabled(natbib);
|
|
|
|
dialog_->forceuppercaseCB->setEnabled(natbib);
|
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
string const & command = controller().params().getCmdName();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
// Find the style of the citekeys
|
|
|
|
vector<biblio::CiteStyle> const & styles =
|
|
|
|
ControlCitation::getCiteStyles();
|
2002-03-21 21:21:28 +00:00
|
|
|
biblio::CitationStyle cs = biblio::getCitationStyle(command);
|
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
vector<biblio::CiteStyle>::const_iterator cit =
|
|
|
|
find(styles.begin(), styles.end(), cs.style);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
dialog_->citationStyleCO->setCurrentItem(0);
|
2002-03-21 21:21:28 +00:00
|
|
|
dialog_->fulllistCB->setChecked(false);
|
|
|
|
dialog_->forceuppercaseCB->setChecked(false);
|
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
if (cit != styles.end()) {
|
|
|
|
int const i = int(cit - styles.begin());
|
|
|
|
dialog_->citationStyleCO->setCurrentItem(i);
|
|
|
|
dialog_->fulllistCB->setChecked(cs.full);
|
|
|
|
dialog_->forceuppercaseCB->setChecked(cs.forceUCase);
|
2002-03-21 21:21:28 +00:00
|
|
|
}
|
2002-01-20 17:02:09 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
|
2001-08-25 20:04:15 +00:00
|
|
|
void QCitation::update_contents()
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2001-06-05 17:05:51 +00:00
|
|
|
// Make the list of all available bibliography keys
|
|
|
|
bibkeys = biblio::getKeys(controller().bibkeysInfo());
|
2003-04-12 02:23:02 +00:00
|
|
|
updateBrowser(dialog_->add_->availableLB, bibkeys);
|
2002-01-20 17:02:09 +00:00
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
// Ditto for the keys cited in this inset
|
|
|
|
citekeys = getVectorFromString(controller().params().getContents());
|
2003-04-04 03:19:00 +00:00
|
|
|
updateBrowser(dialog_->selectedLB, citekeys);
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
// No keys have been selected yet, so...
|
|
|
|
dialog_->infoML->clear();
|
2003-04-04 03:19:00 +00:00
|
|
|
dialog_->setButtons();
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2002-12-17 20:37:13 +00:00
|
|
|
dialog_->textAfterED->setText(toqstr(controller().params().getOptions()));
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
fillStyles();
|
|
|
|
updateStyle();
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2002-10-20 01:48:28 +00:00
|
|
|
void QCitation::updateBrowser(QListBox * browser,
|
2003-04-04 03:19:00 +00:00
|
|
|
vector<string> const & keys) const
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2001-06-05 17:05:51 +00:00
|
|
|
browser->clear();
|
|
|
|
|
|
|
|
for (vector<string>::const_iterator it = keys.begin();
|
|
|
|
it < keys.end(); ++it) {
|
2002-07-28 22:50:13 +00:00
|
|
|
string const key = trim(*it);
|
2001-08-19 13:25:15 +00:00
|
|
|
// FIXME: why the .empty() test ?
|
2002-07-11 01:01:38 +00:00
|
|
|
if (!key.empty())
|
2002-12-17 20:37:13 +00:00
|
|
|
browser->insertItem(toqstr(key));
|
2001-06-05 17:05:51 +00:00
|
|
|
}
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|