2001-02-12 14:09:09 +00:00
|
|
|
/**
|
|
|
|
* \file FormBibtex.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author John Levon
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "FormBibtex.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "form_bibtex.h"
|
|
|
|
#include "lyxfunc.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
using std::endl;
|
2001-03-16 12:08:14 +00:00
|
|
|
using SigC::slot;
|
2001-02-12 14:09:09 +00:00
|
|
|
|
|
|
|
FormBibtex::FormBibtex(LyXView * lv, Dialogs * d)
|
2001-03-15 13:37:04 +00:00
|
|
|
: FormCommand(lv, d, _("BibTeX Database"))
|
2001-02-12 14:09:09 +00:00
|
|
|
{
|
|
|
|
d->showBibtex.connect(slot(this, &FormBibtex::showInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FL_FORM * FormBibtex::form() const
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
if (dialog_.get())
|
2001-02-12 14:09:09 +00:00
|
|
|
return dialog_->form;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormBibtex::connect()
|
|
|
|
{
|
|
|
|
fl_set_form_maxsize(form(), 2 * minw_, minh_);
|
|
|
|
FormCommand::connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormBibtex::build()
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
dialog_.reset(build_bibtex());
|
2001-02-12 14:09:09 +00:00
|
|
|
|
|
|
|
fl_set_input_return(dialog_->database, FL_RETURN_CHANGED);
|
|
|
|
fl_set_input_return(dialog_->style, FL_RETURN_CHANGED);
|
|
|
|
|
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().setOK(dialog_->button_ok);
|
|
|
|
bc().setCancel(dialog_->button_cancel);
|
|
|
|
bc().refresh();
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2001-03-15 13:37:04 +00:00
|
|
|
bc().addReadOnly(dialog_->database);
|
|
|
|
bc().addReadOnly(dialog_->style);
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FormBibtex::input(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
// minimal validation
|
2001-02-16 09:25:43 +00:00
|
|
|
if (!compare(fl_get_input(dialog_->database),""))
|
2001-02-12 14:09:09 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormBibtex::update()
|
|
|
|
{
|
|
|
|
fl_set_input(dialog_->database, params.getContents().c_str());
|
|
|
|
fl_set_input(dialog_->style, params.getOptions().c_str());
|
|
|
|
// Surely, this should reset the buttons to their original state?
|
|
|
|
// It doesn't. Instead "Restore" becomes a "Close"
|
2001-03-15 13:37:04 +00:00
|
|
|
//bc().refresh();
|
|
|
|
bc().readOnly(lv_->buffer()->isReadonly());
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormBibtex::apply()
|
|
|
|
{
|
|
|
|
if (lv_->buffer()->isReadonly())
|
|
|
|
return;
|
|
|
|
|
|
|
|
params.setContents(fl_get_input(dialog_->database));
|
|
|
|
params.setOptions(fl_get_input(dialog_->style));
|
|
|
|
|
|
|
|
if (inset_ != 0) {
|
|
|
|
// Only update if contents have changed
|
|
|
|
if (params != inset_->params()) {
|
|
|
|
if (params.getContents() != inset_->params().getContents())
|
|
|
|
lv_->view()->ChangeCitationsIfUnique(
|
|
|
|
inset_->params().getContents(), params.getContents());
|
|
|
|
|
|
|
|
inset_->setParams(params);
|
|
|
|
lv_->view()->updateInset(inset_, true);
|
|
|
|
|
|
|
|
// We need to do a redraw because the maximum
|
|
|
|
// InsetBibKey width could have changed
|
|
|
|
lv_->view()->redraw();
|
|
|
|
lv_->view()->fitCursor(lv_->view()->getLyXText());
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
lyxerr[Debug::GUI] << "Editing non-existent bibtex inset !" << endl;
|
|
|
|
}
|