2001-03-29 18:58:47 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* \author Angus Leeming <a.leeming@ic.ac.uk>
|
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
|
|
|
|
|
|
|
#include "FormCitationDialogImpl.h"
|
|
|
|
#include "FormCitation.h"
|
|
|
|
|
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>
|
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
#undef emit
|
|
|
|
#include "qt2BC.h"
|
|
|
|
#include "ControlCitation.h"
|
|
|
|
#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-03-29 18:58:47 +00:00
|
|
|
typedef Qt2CB<ControlCitation, Qt2DB<FormCitationDialogImpl> > base_class;
|
2001-03-26 19:34:45 +00:00
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
FormCitation::FormCitation(ControlCitation & c)
|
|
|
|
: base_class(c, _("Citation"))
|
|
|
|
{}
|
2001-03-16 17:20:06 +00:00
|
|
|
|
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
void FormCitation::apply()
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2001-03-29 18:58:47 +00:00
|
|
|
controller().params().setCmdName("cite");
|
|
|
|
controller().params().setContents(getStringFromVector(citekeys));
|
|
|
|
|
|
|
|
string const after = dialog_->textAfterED->text().latin1();
|
|
|
|
controller().params().setOptions(after);
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormCitation::hide()
|
|
|
|
{
|
2001-03-29 18:58:47 +00:00
|
|
|
citekeys.clear();
|
|
|
|
bibkeys.clear();
|
|
|
|
|
|
|
|
Qt2Base::hide();
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
void FormCitation::build()
|
2001-03-16 17:20:06 +00:00
|
|
|
{
|
2001-03-29 18:58:47 +00:00
|
|
|
// PENDING(kalle) Parent?
|
|
|
|
dialog_.reset( new FormCitationDialogImpl( this ));
|
|
|
|
|
2001-03-31 08:39:24 +00:00
|
|
|
dialog_->searchTypeCB->setChecked( false );
|
|
|
|
dialog_->searchCaseCB->setChecked( false );
|
2001-03-29 18:58:47 +00:00
|
|
|
|
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
|
|
|
bc().setOK(dialog_->okPB);
|
|
|
|
bc().setApply(dialog_->applyPB);
|
|
|
|
bc().setCancel(dialog_->cancelPB);
|
2001-04-03 14:30:58 +00:00
|
|
|
bc().setRestore(dialog_->restorePB);
|
2001-03-29 18:58:47 +00:00
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->addPB);
|
|
|
|
bc().addReadOnly(dialog_->delPB);
|
|
|
|
bc().addReadOnly(dialog_->upPB);
|
|
|
|
bc().addReadOnly(dialog_->downPB);
|
|
|
|
bc().addReadOnly(dialog_->citationStyleCO);
|
|
|
|
bc().addReadOnly(dialog_->textBeforeED);
|
|
|
|
bc().addReadOnly(dialog_->textAfterED);
|
|
|
|
|
|
|
|
bc().refresh();
|
|
|
|
}
|
|
|
|
|
2001-03-16 17:20:06 +00:00
|
|
|
|
|
|
|
void FormCitation::update()
|
|
|
|
{
|
2001-03-29 18:58:47 +00:00
|
|
|
// Make the list of all available bibliography keys
|
|
|
|
bibkeys = biblio::getKeys(controller().bibkeysInfo());
|
|
|
|
updateBrowser(dialog_->bibLB, bibkeys);
|
|
|
|
|
2001-03-16 17:20:06 +00:00
|
|
|
// Ditto for the keys cited in this inset
|
2001-03-29 18:58:47 +00:00
|
|
|
citekeys = getVectorFromString(controller().params().getContents());
|
|
|
|
updateBrowser(dialog_->citeLB, citekeys);
|
2001-03-16 17:20:06 +00:00
|
|
|
|
|
|
|
// No keys have been selected yet, so...
|
|
|
|
dialog_->infoML->clear();
|
|
|
|
setBibButtons(OFF);
|
|
|
|
setCiteButtons(OFF);
|
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
int noKeys = int(max(bibkeys.size(), citekeys.size()));
|
|
|
|
|
|
|
|
// Place bounds, so that 4 <= noKeys <= 10
|
|
|
|
noKeys = max(4, min(10, noKeys));
|
|
|
|
|
|
|
|
dialog_->textAfterED->setText( controller().params().getOptions().c_str());
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
void FormCitation::updateBrowser( QListBox* browser,
|
2001-03-16 17:20:06 +00:00
|
|
|
vector<string> const & keys) const
|
|
|
|
{
|
2001-03-29 18:58:47 +00:00
|
|
|
browser->clear();
|
2001-03-16 17:20:06 +00:00
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
for (vector<string>::const_iterator it = keys.begin();
|
|
|
|
it < keys.end(); ++it) {
|
|
|
|
string key = frontStrip(strip(*it));
|
2001-03-31 08:39:24 +00:00
|
|
|
if( !key.empty() )
|
|
|
|
browser->insertItem( key.c_str() );
|
2001-03-29 18:58:47 +00:00
|
|
|
}
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormCitation::setBibButtons(State status) const
|
|
|
|
{
|
2001-03-29 18:58:47 +00:00
|
|
|
dialog_->addPB->setEnabled( (status == ON) );
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormCitation::setCiteButtons(State status) const
|
|
|
|
{
|
2001-03-29 18:58:47 +00:00
|
|
|
int const sel = dialog_->citeLB->currentItem();
|
|
|
|
int const maxline = dialog_->citeLB->count()-1;
|
2001-03-16 17:20:06 +00:00
|
|
|
bool const activate = (status == ON);
|
2001-03-29 18:58:47 +00:00
|
|
|
bool const activate_up = (activate && sel != 0);
|
2001-03-16 17:20:06 +00:00
|
|
|
bool const activate_down = (activate && sel != maxline);
|
2001-03-26 19:34:45 +00:00
|
|
|
|
2001-03-29 18:58:47 +00:00
|
|
|
dialog_->delPB->setEnabled( activate );
|
|
|
|
dialog_->upPB->setEnabled( activate_up );
|
|
|
|
dialog_->downPB->setEnabled( activate_down );
|
2001-03-16 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|