2001-08-19 13:25:15 +00:00
|
|
|
/**
|
|
|
|
* \file QCitation.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
2001-03-29 18:58:47 +00:00
|
|
|
*
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
2001-08-19 13:25:15 +00:00
|
|
|
* \author Kalle Dalheimer <kalle@klaralvdalens-datakonsult.se>
|
2001-03-16 17:20:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
2001-03-16 17:20:06 +00:00
|
|
|
|
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>
|
|
|
|
|
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"
|
2001-03-29 18:58:47 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
#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
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
typedef Qt2CB<ControlCitation, Qt2DB<QCitationDialog> > base_class;
|
2001-03-26 19:34:45 +00:00
|
|
|
|
2002-07-11 01:01:38 +00:00
|
|
|
QCitation::QCitation(ControlCitation & c, Dialogs &)
|
2001-06-05 17:05:51 +00:00
|
|
|
: base_class(c, _("Citation"))
|
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
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
string const after = dialog_->textAfterED->text().latin1();
|
|
|
|
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
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
Qt2Base::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
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
dialog_->searchTypeCB->setChecked(false);
|
|
|
|
dialog_->searchCaseCB->setChecked(false);
|
2001-08-26 00:29:39 +00:00
|
|
|
|
2001-06-05 17:05:51 +00:00
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setApply(dialog_->applyPB);
|
2001-08-25 03:00:19 +00:00
|
|
|
bc().setCancel(dialog_->closePB);
|
2001-06-05 17:05:51 +00:00
|
|
|
bc().setRestore(dialog_->restorePB);
|
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->addPB);
|
|
|
|
bc().addReadOnly(dialog_->delPB);
|
|
|
|
bc().addReadOnly(dialog_->upPB);
|
|
|
|
bc().addReadOnly(dialog_->downPB);
|
|
|
|
bc().addReadOnly(dialog_->citationStyleCO);
|
2002-01-20 17:02:09 +00:00
|
|
|
bc().addReadOnly(dialog_->forceuppercaseCB);
|
|
|
|
bc().addReadOnly(dialog_->fulllistCB);
|
2002-03-21 21:21:28 +00:00
|
|
|
// add when enabled !
|
2001-08-25 03:00:19 +00:00
|
|
|
//bc().addReadOnly(dialog_->textBeforeED);
|
2001-06-05 17:05:51 +00:00
|
|
|
bc().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()
|
|
|
|
{
|
|
|
|
// style
|
|
|
|
string key;
|
|
|
|
|
|
|
|
if (!citekeys.empty())
|
|
|
|
key = citekeys[0];
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
dialog_->citationStyleCO->clear();
|
|
|
|
vector<string> const & sty = controller().getCiteStrings(key);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
for (vector<string>::const_iterator it = sty.begin();
|
|
|
|
it != sty.end(); ++it) {
|
|
|
|
dialog_->citationStyleCO->insertItem(it->c_str());
|
|
|
|
}
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
|
|
|
|
void QCitation::updateStyle()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
bool const natbib = controller().usingNatbib();
|
2002-03-21 21:21:28 +00:00
|
|
|
dialog_->citationStyleCO->setEnabled(natbib);
|
|
|
|
dialog_->fulllistCB->setEnabled(natbib);
|
|
|
|
dialog_->forceuppercaseCB->setEnabled(natbib);
|
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());
|
|
|
|
updateBrowser(dialog_->bibLB, 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());
|
|
|
|
updateBrowser(dialog_->citeLB, 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();
|
|
|
|
setBibButtons(OFF);
|
|
|
|
setCiteButtons(OFF);
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2001-08-25 03:00:19 +00:00
|
|
|
dialog_->textAfterED->setText(controller().params().getOptions().c_str());
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
fillStyles();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-01-20 17:02:09 +00:00
|
|
|
updateStyle();
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QCitation::updateBrowser(QListBox* browser,
|
2001-03-16 17:20:06 +00:00
|
|
|
vector<string> const & keys) const
|
|
|
|
{
|
2001-06-05 17:05:51 +00:00
|
|
|
browser->clear();
|
|
|
|
|
|
|
|
for (vector<string>::const_iterator it = keys.begin();
|
|
|
|
it < keys.end(); ++it) {
|
2001-08-19 13:25:15 +00:00
|
|
|
string const key = frontStrip(strip(*it));
|
|
|
|
// FIXME: why the .empty() test ?
|
2002-07-11 01:01:38 +00:00
|
|
|
if (!key.empty())
|
2001-08-19 13:25:15 +00:00
|
|
|
browser->insertItem(key.c_str());
|
2001-06-05 17:05:51 +00:00
|
|
|
}
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QCitation::setBibButtons(State status) const
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2001-08-19 13:25:15 +00:00
|
|
|
dialog_->addPB->setEnabled((status == ON));
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
void QCitation::setCiteButtons(State status) const
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2001-06-05 17:05:51 +00:00
|
|
|
int const sel = dialog_->citeLB->currentItem();
|
2001-08-19 13:25:15 +00:00
|
|
|
int const maxline = dialog_->citeLB->count() - 1;
|
2001-06-05 17:05:51 +00:00
|
|
|
bool const activate = (status == ON);
|
|
|
|
bool const activate_up = (activate && sel != 0);
|
|
|
|
bool const activate_down = (activate && sel != maxline);
|
|
|
|
|
2001-08-19 13:25:15 +00:00
|
|
|
dialog_->delPB->setEnabled(activate);
|
|
|
|
dialog_->upPB->setEnabled(activate_up);
|
|
|
|
dialog_->downPB->setEnabled(activate_down);
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|