1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
#include <fstream>
|
1999-11-25 13:15:52 +00:00
|
|
|
using std::ifstream;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <cstdlib>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
#include "insetbib.h"
|
|
|
|
#include "combox.h"
|
|
|
|
#include "buffer.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_gui_misc.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "bibforms.h"
|
|
|
|
#include "lyxtext.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
extern BufferView * current_view;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
FD_citation_form * citation_form = 0;
|
|
|
|
FD_bibitem_form * bibitem_form = 0;
|
|
|
|
static Combox * bibcombox = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
void BibitemUpdate(Combox *);
|
|
|
|
FD_citation_form * create_form_citation_form(void);
|
|
|
|
FD_bibitem_form * create_form_bibitem_form(void);
|
|
|
|
|
|
|
|
|
1999-10-19 15:06:30 +00:00
|
|
|
extern "C" void bibitem_cb(FL_OBJECT *, long data)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
switch (data) {
|
|
|
|
case 1: // OK, citation
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
InsetCitation::Holder * holder =
|
|
|
|
static_cast<InsetCitation::Holder*>
|
|
|
|
(citation_form->citation_form->u_vdata);
|
|
|
|
if(!holder->view->buffer()->isReadonly()) {
|
|
|
|
|
|
|
|
InsetCitation * inset = holder->inset;
|
1999-09-27 18:44:28 +00:00
|
|
|
inset->setContents(bibcombox->getline());
|
|
|
|
inset->setOptions(fl_get_input(citation_form->label));
|
|
|
|
fl_hide_form(citation_form->citation_form);
|
|
|
|
// shouldn't mark the buffer dirty unless something
|
|
|
|
// was actually altered
|
2000-02-23 16:39:03 +00:00
|
|
|
holder->view->updateInset(inset, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall through to Cancel on RO-mode
|
|
|
|
}
|
|
|
|
case 0: fl_hide_form(citation_form->citation_form);
|
|
|
|
break;
|
|
|
|
case 3: // OK, bibitem
|
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
InsetBibKey::Holder * holder =
|
|
|
|
static_cast<InsetBibKey::Holder*>
|
|
|
|
(bibitem_form->bibitem_form->u_vdata);
|
|
|
|
|
|
|
|
if(!holder->view->buffer()->isReadonly()) {
|
|
|
|
InsetBibKey * inset = holder->inset;
|
1999-09-27 18:44:28 +00:00
|
|
|
inset->setContents(fl_get_input(bibitem_form->key));
|
|
|
|
inset->setOptions(fl_get_input(bibitem_form->label));
|
|
|
|
fl_hide_form(bibitem_form->bibitem_form);
|
|
|
|
// Does look like a hack? It is! (but will change at 0.13)
|
2000-02-22 00:36:17 +00:00
|
|
|
holder->view->text->RedoParagraph();
|
|
|
|
holder->view->update(1);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
} // fall through to Cancel on RO-mode
|
|
|
|
}
|
|
|
|
case 2: // Cancel, bibitem
|
|
|
|
fl_hide_form(bibitem_form->bibitem_form); // Cancel, bibitem
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
FD_citation_form * create_form_citation_form(void)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
FL_OBJECT * obj;
|
1999-12-16 06:43:25 +00:00
|
|
|
FD_citation_form * fdui = (FD_citation_form *) fl_calloc(1, sizeof(FD_citation_form));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
fdui->citation_form = fl_bgn_form(FL_NO_BOX, 220, 130);
|
1999-11-15 10:58:38 +00:00
|
|
|
obj = fl_add_box(FL_UP_BOX, 0, 0, 220, 130, "");
|
|
|
|
fdui->key = obj = fl_add_text(FL_NORMAL_TEXT, 20, 10, 60, 30, _("Key:"));
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
|
|
|
fl_set_object_lalign(obj, FL_ALIGN_RIGHT);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
bibcombox = new Combox(FL_COMBOX_INPUT);
|
2000-02-08 15:13:01 +00:00
|
|
|
bibcombox->add(80, 10, 130, 30, 300);
|
1999-11-15 10:58:38 +00:00
|
|
|
|
|
|
|
obj = fl_add_button(FL_RETURN_BUTTON, 20, 90, 90, 30, _("OK"));
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
|
|
|
fl_set_object_callback(obj, bibitem_cb, 1);
|
1999-11-15 10:58:38 +00:00
|
|
|
obj = fl_add_button(FL_NORMAL_BUTTON, 120, 90, 90, 30, idex(_("Cancel|^[")));
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_set_button_shortcut(obj, scex(_("Cancel|^[")), 1);
|
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
|
|
|
fl_set_object_callback(obj, bibitem_cb, 0);
|
1999-11-15 10:58:38 +00:00
|
|
|
fdui->label = obj = fl_add_input(FL_NORMAL_INPUT, 80, 50, 130, 30, idex(_("Remark:|#R")));
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_set_input_shortcut(obj, scex(_("Remark:|#R")), 1);
|
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_end_form();
|
|
|
|
|
|
|
|
//fdui->citation_form->fdui = fdui;
|
|
|
|
|
|
|
|
return fdui;
|
|
|
|
}
|
|
|
|
/*---------------------------------------*/
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
FD_bibitem_form * create_form_bibitem_form(void)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
FL_OBJECT * obj;
|
1999-12-16 06:43:25 +00:00
|
|
|
FD_bibitem_form * fdui = (FD_bibitem_form *) fl_calloc(1, sizeof(FD_bibitem_form));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
fdui->bibitem_form = fl_bgn_form(FL_NO_BOX, 220, 130);
|
1999-11-15 10:58:38 +00:00
|
|
|
obj = fl_add_box(FL_UP_BOX, 0, 0, 220, 130, "");
|
|
|
|
fdui->key = obj = fl_add_input(FL_NORMAL_INPUT, 80, 10, 130, 30, idex(_("Key:|#K")));
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_set_input_shortcut(obj, scex(_("Key:|#K")), 1);
|
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
1999-11-15 10:58:38 +00:00
|
|
|
obj = fl_add_button(FL_RETURN_BUTTON, 20, 90, 90, 30, _("OK"));
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
|
|
|
fl_set_object_callback(obj, bibitem_cb, 3);
|
1999-11-15 10:58:38 +00:00
|
|
|
obj = fl_add_button(FL_NORMAL_BUTTON, 120, 90, 90, 30, idex(_("Cancel|^[")));
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_set_button_shortcut(obj, scex(_("Cancel|^[")), 1);
|
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
|
|
|
fl_set_object_callback(obj, bibitem_cb, 2);
|
1999-11-15 10:58:38 +00:00
|
|
|
fdui->label = obj = fl_add_input(FL_NORMAL_INPUT, 80, 50, 130, 30, idex(_("Label:|#L")));
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_set_input_shortcut(obj, scex(_("Label:|#L")), 1);
|
|
|
|
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_end_form();
|
|
|
|
|
|
|
|
//fdui->bibitem_form->fdui = fdui;
|
|
|
|
|
|
|
|
return fdui;
|
|
|
|
}
|
|
|
|
/*---------------------------------------*/
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
InsetCitation::InsetCitation(string const & key, string const & note)
|
|
|
|
: InsetCommand("cite", key, note)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
InsetCitation::~InsetCitation()
|
|
|
|
{
|
|
|
|
if(citation_form && citation_form->citation_form
|
|
|
|
&& citation_form->citation_form->visible
|
2000-02-22 00:36:17 +00:00
|
|
|
&& citation_form->citation_form->u_vdata == &holder)
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_hide_form(citation_form->citation_form);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetCitation::Edit(BufferView * bv, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
if(bv->buffer()->isReadonly())
|
|
|
|
WarnReadonly(bv->buffer()->fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!citation_form) {
|
|
|
|
citation_form = create_form_citation_form();
|
|
|
|
fl_set_form_atclose(citation_form->citation_form,
|
1999-10-02 16:21:10 +00:00
|
|
|
CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-02-22 00:36:17 +00:00
|
|
|
|
|
|
|
holder.inset = this;
|
|
|
|
holder.view = bv;
|
|
|
|
|
|
|
|
citation_form->citation_form->u_vdata = &holder;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
BibitemUpdate(bibcombox);
|
|
|
|
if (!bibcombox->select_text(getContents().c_str()))
|
|
|
|
bibcombox->addline(getContents().c_str());
|
|
|
|
|
|
|
|
fl_set_input(citation_form->label, getOptions().c_str());
|
|
|
|
if (citation_form->citation_form->visible) {
|
|
|
|
fl_raise_form(citation_form->citation_form);
|
|
|
|
} else {
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_show_form(citation_form->citation_form,
|
|
|
|
FL_PLACE_MOUSE, FL_FULLBORDER,
|
1999-09-27 18:44:28 +00:00
|
|
|
_("Citation"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string InsetCitation::getScreenLabel() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string temp("[");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
temp += contents;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!options.empty()) {
|
1999-11-15 10:58:38 +00:00
|
|
|
temp += ", " + options;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
return temp + ']';
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
InsetBibKey::InsetBibKey(string const & key, string const & label):
|
1999-09-27 18:44:28 +00:00
|
|
|
InsetCommand("bibitem", key, label)
|
|
|
|
{
|
|
|
|
counter = 1;
|
|
|
|
if (key.empty())
|
|
|
|
contents = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
InsetBibKey::InsetBibKey(InsetBibKey const * b):
|
1999-09-27 18:44:28 +00:00
|
|
|
InsetCommand("bibitem", b->contents, b->options)
|
|
|
|
{
|
|
|
|
counter = b->counter;
|
|
|
|
}
|
|
|
|
|
1999-11-22 16:19:48 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
InsetBibKey::~InsetBibKey()
|
|
|
|
{
|
|
|
|
if(bibitem_form && bibitem_form->bibitem_form
|
|
|
|
&& bibitem_form->bibitem_form->visible)
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_hide_form(bibitem_form->bibitem_form);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InsetBibKey::setCounter(int c)
|
|
|
|
{
|
|
|
|
counter = c;
|
|
|
|
|
|
|
|
if (contents.empty())
|
1999-10-19 16:48:35 +00:00
|
|
|
contents += tostr(counter);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// I'm sorry but this is still necessary because \bibitem is used also
|
|
|
|
// as a LyX 2.x command, and lyxlex is not enough smart to understand
|
|
|
|
// real LaTeX commands. Yes, that could be fixed, but would be a waste
|
|
|
|
// of time cause LyX3 won't use lyxlex anyway. (ale)
|
2000-02-18 22:22:42 +00:00
|
|
|
void InsetBibKey::Write(ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string s;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!options.empty()) {
|
|
|
|
s += '[';
|
|
|
|
s += options + ']';
|
|
|
|
}
|
|
|
|
s += '{';
|
|
|
|
s += contents + '}';
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "\\bibitem " << s << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string InsetBibKey::getScreenLabel() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (!options.empty())
|
|
|
|
return options;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
return tostr(counter);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
The value in "Key:" isn't allways set right after a few bibkey insets have
|
1999-11-22 16:19:48 +00:00
|
|
|
been added/removed. Perhaps the wrong object is deleted/used somewhere
|
|
|
|
upwards?
|
1999-09-27 18:44:28 +00:00
|
|
|
(Joacim 1998-03-04)
|
|
|
|
*/
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetBibKey::Edit(BufferView * bv, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-02-22 00:36:17 +00:00
|
|
|
if(bv->buffer()->isReadonly())
|
|
|
|
WarnReadonly(bv->buffer()->fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!bibitem_form) {
|
|
|
|
bibitem_form = create_form_bibitem_form();
|
|
|
|
fl_set_form_atclose(bibitem_form->bibitem_form,
|
1999-10-02 16:21:10 +00:00
|
|
|
CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-02-22 00:36:17 +00:00
|
|
|
|
|
|
|
holder.inset = this;
|
|
|
|
holder.view = bv;
|
|
|
|
|
|
|
|
bibitem_form->bibitem_form->u_vdata = &holder;
|
1999-09-27 18:44:28 +00:00
|
|
|
// InsetBibtex uses the same form, with different labels
|
|
|
|
fl_set_object_label(bibitem_form->key, idex(_("Key:|#K")));
|
1999-11-15 10:58:38 +00:00
|
|
|
fl_set_button_shortcut(bibitem_form->key, scex(_("Key:|#K")), 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_label(bibitem_form->label, idex(_("Label:|#L")));
|
1999-11-15 10:58:38 +00:00
|
|
|
fl_set_button_shortcut(bibitem_form->label, scex(_("Label:|#L")), 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_input(bibitem_form->key, getContents().c_str());
|
|
|
|
fl_set_input(bibitem_form->label, getOptions().c_str());
|
|
|
|
if (bibitem_form->bibitem_form->visible) {
|
|
|
|
fl_raise_form(bibitem_form->bibitem_form);
|
|
|
|
} else {
|
1999-11-15 10:58:38 +00:00
|
|
|
fl_show_form(bibitem_form->bibitem_form, FL_PLACE_MOUSE,
|
1999-09-27 18:44:28 +00:00
|
|
|
FL_FULLBORDER,
|
|
|
|
_("Bibliography item"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
InsetBibtex::InsetBibtex(string const & dbase, string const & style,
|
1999-12-07 00:44:53 +00:00
|
|
|
Buffer * o)
|
|
|
|
: InsetCommand("BibTeX", dbase, style), owner(o)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string InsetBibtex::getScreenLabel() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return _("BibTeX Generated References");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-18 22:22:42 +00:00
|
|
|
int InsetBibtex::Latex(ostream & os, signed char /*fragile*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-02 02:19:43 +00:00
|
|
|
#ifdef USE_OSTREAM_ONLY
|
|
|
|
// this looks like an horrible hack and it is :) The problem
|
|
|
|
// is that owner is not initialized correctly when the bib
|
|
|
|
// inset is cut and pasted. Such hacks will not be needed
|
|
|
|
// later (JMarc)
|
|
|
|
if (!owner) {
|
|
|
|
owner = current_view->buffer();
|
|
|
|
}
|
|
|
|
// If we generate in a temp dir, we might need to give an
|
|
|
|
// absolute path there. This is a bit complicated since we can
|
|
|
|
// have a comma-separated list of bibliographies
|
|
|
|
string adb, db_out;
|
|
|
|
string db_in = getContents();
|
|
|
|
db_in = split(db_in, adb, ',');
|
|
|
|
while(!adb.empty()) {
|
|
|
|
if (!owner->niceFile &&
|
|
|
|
IsFileReadable(MakeAbsPath(adb, owner->filepath)+".bib"))
|
|
|
|
adb = MakeAbsPath(adb, owner->filepath);
|
|
|
|
db_out += adb;
|
|
|
|
db_out += ',';
|
|
|
|
db_in= split(db_in, adb,',');
|
|
|
|
}
|
|
|
|
db_out = strip(db_out, ',');
|
|
|
|
// Idem, but simpler
|
|
|
|
string style;
|
|
|
|
if (!owner->niceFile
|
|
|
|
&& IsFileReadable(MakeAbsPath(getOptions(), owner->filepath)
|
|
|
|
+ ".bst"))
|
|
|
|
style = MakeAbsPath(getOptions(), owner->filepath);
|
|
|
|
else
|
|
|
|
style = getOptions();
|
|
|
|
|
|
|
|
os << "\\bibliographystyle{" << style << "}\n"
|
|
|
|
<< "\\bibliography{" << db_out << "}\n";
|
|
|
|
return 2;
|
|
|
|
#else
|
1999-10-02 16:21:10 +00:00
|
|
|
string bib;
|
1999-09-27 18:44:28 +00:00
|
|
|
signed char dummy = 0;
|
|
|
|
int result = Latex(bib, dummy);
|
1999-12-07 00:44:53 +00:00
|
|
|
os << bib;
|
1999-09-27 18:44:28 +00:00
|
|
|
return result;
|
2000-03-02 02:19:43 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
#ifndef USE_OSTREAM_ONLY
|
2000-02-18 22:22:42 +00:00
|
|
|
int InsetBibtex::Latex(string & file, signed char /*fragile*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// this looks like an horrible hack and it is :) The problem
|
|
|
|
// is that owner is not initialized correctly when the bib
|
|
|
|
// inset is cut and pasted. Such hacks will not be needed
|
|
|
|
// later (JMarc)
|
|
|
|
if (!owner) {
|
1999-11-09 22:53:41 +00:00
|
|
|
owner = current_view->buffer();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
// If we generate in a temp dir, we might need to give an
|
|
|
|
// absolute path there. This is a bit complicated since we can
|
|
|
|
// have a comma-separated list of bibliographies
|
1999-12-07 00:44:53 +00:00
|
|
|
string adb, db_out;
|
|
|
|
string db_in = getContents();
|
|
|
|
db_in = split(db_in, adb, ',');
|
1999-09-27 18:44:28 +00:00
|
|
|
while(!adb.empty()) {
|
|
|
|
if (!owner->niceFile &&
|
1999-11-15 10:58:38 +00:00
|
|
|
IsFileReadable(MakeAbsPath(adb, owner->filepath)+".bib"))
|
|
|
|
adb = MakeAbsPath(adb, owner->filepath);
|
1999-09-27 18:44:28 +00:00
|
|
|
db_out += adb;
|
|
|
|
db_out += ',';
|
1999-11-15 10:58:38 +00:00
|
|
|
db_in= split(db_in, adb,',');
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
db_out = strip(db_out, ',');
|
1999-09-27 18:44:28 +00:00
|
|
|
// Idem, but simpler
|
1999-10-02 16:21:10 +00:00
|
|
|
string style;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!owner->niceFile
|
|
|
|
&& IsFileReadable(MakeAbsPath(getOptions(), owner->filepath)
|
|
|
|
+ ".bst"))
|
|
|
|
style = MakeAbsPath(getOptions(), owner->filepath);
|
|
|
|
else
|
|
|
|
style = getOptions();
|
|
|
|
|
|
|
|
file += "\\bibliographystyle{";
|
|
|
|
file += style;
|
|
|
|
file += "}\n";
|
|
|
|
file += "\\bibliography{";
|
|
|
|
file += db_out;
|
|
|
|
file += "}\n";
|
|
|
|
return 2;
|
|
|
|
}
|
2000-03-02 02:19:43 +00:00
|
|
|
#endif
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// This method returns a comma separated list of Bibtex entries
|
1999-12-22 14:35:05 +00:00
|
|
|
string InsetBibtex::getKeys(char delim)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// This hack is copied from InsetBibtex::Latex.
|
|
|
|
// Is it still needed? Probably yes.
|
2000-02-22 00:36:17 +00:00
|
|
|
// Why is this needed here when it already is in Latex?
|
|
|
|
// Anyway we need a different way to get to the
|
|
|
|
// buffer the inset is in. (Lgb)
|
|
|
|
|
|
|
|
//if (!owner) {
|
|
|
|
// owner = current_view->buffer();
|
|
|
|
//}
|
1999-11-24 22:14:46 +00:00
|
|
|
|
|
|
|
string tmp, keys;
|
|
|
|
string bibfiles = getContents();
|
|
|
|
bibfiles = split(bibfiles, tmp, ',');
|
1999-09-27 18:44:28 +00:00
|
|
|
while(!tmp.empty()) {
|
1999-11-24 22:14:46 +00:00
|
|
|
string fil = findtexfile(ChangeExtension(tmp, "bib", false),
|
|
|
|
"bib");
|
1999-12-22 14:35:05 +00:00
|
|
|
lyxerr[Debug::LATEX] << "Bibfile: " << fil << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
// If we didn't find a matching file name just fail silently
|
1999-11-24 22:14:46 +00:00
|
|
|
if (!fil.empty()) {
|
|
|
|
// This is a _very_ simple parser for Bibtex database
|
|
|
|
// files. All it does is to look for lines starting
|
|
|
|
// in @ and not being @preamble and @string entries.
|
1999-09-27 18:44:28 +00:00
|
|
|
// It does NOT do any syntax checking!
|
1999-11-24 22:14:46 +00:00
|
|
|
ifstream ifs(fil.c_str());
|
|
|
|
string linebuf;
|
|
|
|
while (getline(ifs, linebuf)) {
|
1999-12-22 14:35:05 +00:00
|
|
|
linebuf = frontStrip(linebuf);
|
1999-11-24 22:14:46 +00:00
|
|
|
if (prefixIs(linebuf, "@")) {
|
|
|
|
linebuf = subst(linebuf, '{', '(');
|
|
|
|
linebuf = split(linebuf, tmp, '(');
|
|
|
|
tmp = lowercase(tmp);
|
|
|
|
if (!prefixIs(tmp, "@string")
|
|
|
|
&& !prefixIs(tmp, "@preamble")) {
|
1999-10-26 23:33:30 +00:00
|
|
|
linebuf = split(linebuf,
|
1999-11-24 22:14:46 +00:00
|
|
|
tmp, ',');
|
1999-12-22 14:35:05 +00:00
|
|
|
tmp = frontStrip(strip(tmp));
|
1999-11-24 22:14:46 +00:00
|
|
|
if (!tmp.empty()) {
|
1999-12-22 14:35:05 +00:00
|
|
|
keys += tmp;
|
|
|
|
keys += delim;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Get next file name
|
1999-11-24 22:14:46 +00:00
|
|
|
bibfiles = split(bibfiles, tmp, ',');
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// BibTeX should have its own dialog. This is provisional.
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetBibtex::Edit(BufferView *, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (!bibitem_form) {
|
|
|
|
bibitem_form = create_form_bibitem_form();
|
|
|
|
fl_set_form_atclose(bibitem_form->bibitem_form,
|
1999-10-02 16:21:10 +00:00
|
|
|
CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
bibitem_form->bibitem_form->u_vdata = this;
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_label(bibitem_form->key, _("Database:"));
|
|
|
|
fl_set_object_label(bibitem_form->label, _("Style: "));
|
|
|
|
fl_set_input(bibitem_form->key, getContents().c_str());
|
|
|
|
fl_set_input(bibitem_form->label, getOptions().c_str());
|
|
|
|
if (bibitem_form->bibitem_form->visible) {
|
|
|
|
fl_raise_form(bibitem_form->bibitem_form);
|
|
|
|
} else {
|
1999-11-04 01:40:20 +00:00
|
|
|
fl_show_form(bibitem_form->bibitem_form,
|
|
|
|
FL_PLACE_MOUSE, FL_FULLBORDER,
|
1999-09-27 18:44:28 +00:00
|
|
|
_("BibTeX"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
bool InsetBibtex::addDatabase(string const & db)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
if (!contains(contents, db.c_str())) {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!contents.empty())
|
|
|
|
contents += ',';
|
|
|
|
contents += db;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
bool InsetBibtex::delDatabase(string const & db)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
if (contains(contents, db.c_str())) {
|
|
|
|
string bd = db;
|
|
|
|
int n = tokenPos(contents, ',', bd);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (n > 0) {
|
1999-10-26 23:33:30 +00:00
|
|
|
// Weird code, would someone care to explain this?(Lgb)
|
1999-11-15 10:58:38 +00:00
|
|
|
string tmp(", ");
|
1999-09-27 18:44:28 +00:00
|
|
|
tmp += bd;
|
1999-11-15 10:58:38 +00:00
|
|
|
contents = subst(contents, tmp.c_str(), ", ");
|
|
|
|
} else if (n == 0)
|
1999-10-02 16:21:10 +00:00
|
|
|
contents = split(contents, bd, ',');
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This function should be in LyXView when multiframe works ale970302
|
1999-11-04 01:40:20 +00:00
|
|
|
void BibitemUpdate(Combox * combox)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
combox->clear();
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
if (!current_view->available()) return;
|
|
|
|
|
1999-11-09 22:53:41 +00:00
|
|
|
string tmp, bibkeys = current_view->buffer()->getBibkeyList(',');
|
|
|
|
bibkeys = split(bibkeys, tmp,',');
|
1999-09-27 18:44:28 +00:00
|
|
|
while (!tmp.empty()) {
|
1999-12-07 00:44:53 +00:00
|
|
|
combox->addto(tmp.c_str());
|
|
|
|
bibkeys = split(bibkeys, tmp,',');
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ale070405 This function maybe shouldn't be here. We'll fix this at 0.13.
|
2000-02-10 17:53:36 +00:00
|
|
|
int bibitemMaxWidth(Painter & pain, LyXFont const & font)
|
|
|
|
{
|
|
|
|
int w = 0;
|
|
|
|
// Does look like a hack? It is! (but will change at 0.13)
|
|
|
|
LyXParagraph * par = current_view->buffer()->paragraph;
|
|
|
|
|
|
|
|
while (par) {
|
|
|
|
if (par->bibkey) {
|
|
|
|
int wx = par->bibkey->width(pain, font);
|
|
|
|
if (wx > w) w = wx;
|
|
|
|
}
|
|
|
|
par = par->next;
|
|
|
|
}
|
|
|
|
return w;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
// ale070405
|
|
|
|
string bibitemWidthest(Painter & pain)
|
|
|
|
{
|
|
|
|
int w = 0;
|
|
|
|
// Does look like a hack? It is! (but will change at 0.13)
|
|
|
|
LyXParagraph * par = current_view->buffer()->paragraph;
|
|
|
|
InsetBibKey * bkey = 0;
|
|
|
|
LyXFont font;
|
|
|
|
|
|
|
|
while (par) {
|
|
|
|
if (par->bibkey) {
|
|
|
|
int wx = par->bibkey->width(pain, font);
|
|
|
|
if (wx > w) {
|
|
|
|
w = wx;
|
|
|
|
bkey = par->bibkey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
par = par->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bkey && !bkey->getScreenLabel().empty())
|
|
|
|
return bkey->getScreenLabel();
|
|
|
|
|
|
|
|
return "99";
|
|
|
|
}
|