Angus Leeming wrote: > > The patch looks pretty good to me; you've obviously read the source pretty > closely before diving in. Some small points/questions: > > -string const InsetBibtex::getScreenLabel(Buffer const *) const > -{ > - return _("BibTeX Generated References"); > +string const InsetBibtex::getScreenLabel(Buffer const *) const { > + return "BibTeX Generated References"; > } > > Why this change? Why shouldn't the string be internationalised? (And if it > should but isn't, then the correct fix is probably > return N_("BibTeX Generated References"); uups, I dont know, why this happens, changed it back. was not intended. > +/// Cut the extension of the file > +string const CutFileExtension(string const & name); > + > > Not needed. Use this (from the same file!) > /** Change extension of oldname to extension. > If oldname does not have an extension, it is appended. > If the extension is empty, any extension is removed from the name. > */ > string const > ChangeExtension(string const & oldname, string const & extension); ok > Finally, please adhere to LyX style! That means tabs for spaces. This applies > only to the insetbib files. five tabs and your are right out of your screen ... > I'll shove it in my tree, as is, and test it for you, but won't submit it > just yet. i tested it in any combination with or without bibtotoc and article/book-classes and so on. here is the patch again with the corrections and the file from fdesign. > Something goes wrong with the LaTeX typesetting when including the references > in the TOC. See attached screenshot. is fixed now. you had article class and therefore I had to change from chapter to section. Herbert -- http://www.educat.hu-berlin.de/~voss/lyx/
Index: src/frontends/controllers/ControlBibtex.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlBibtex.C,v retrieving revision 1.7 diff -u -p -r1.7 ControlBibtex.C --- src/frontends/controllers/ControlBibtex.C 2001/08/02 14:55:05 1.7 +++ src/frontends/controllers/ControlBibtex.C 2001/08/20 11:10:52 @@ -10,6 +10,7 @@ * \file ControlBibtex.C * \author John Levon, [EMAIL PROTECTED] * \author Angus Leeming <[EMAIL PROTECTED]> + * \author Herbert Voss <[EMAIL PROTECTED]> */ #include <algorithm> @@ -26,7 +27,12 @@ #include "LyXView.h" #include "buffer.h" #include "BufferView.h" +#include "lyxrc.h" +#include "helper_funcs.h" +#include "gettext.h" +using std::pair; +using std::make_pair; using SigC::slot; ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d) @@ -53,3 +59,11 @@ void ControlBibtex::applyParamsToInset() void ControlBibtex::applyParamsNoInset() {} + +string const ControlBibtex::Browse(string const & in_name, + string const & title, + string const & pattern) { + pair<string, string> dir1(N_("Documents"), string(lyxrc.document_path)); + return browseFile(&lv_, in_name, title, pattern, + dir1,make_pair(string(), string())); +} Index: src/frontends/controllers/ControlBibtex.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlBibtex.h,v retrieving revision 1.6 diff -u -p -r1.6 ControlBibtex.h --- src/frontends/controllers/ControlBibtex.h 2001/03/28 12:59:28 1.6 +++ src/frontends/controllers/ControlBibtex.h 2001/08/20 11:10:52 @@ -29,6 +29,8 @@ class ControlBibtex : public ControlComm public: /// ControlBibtex(LyXView &, Dialogs &); + /// Browse for a file + string const Browse(string const &, string const &, string const &); private: /// Dispatch the changed parameters to the kernel. Index: src/frontends/xforms/FormBibtex.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormBibtex.C,v retrieving revision 1.12 diff -u -p -r1.12 FormBibtex.C --- src/frontends/xforms/FormBibtex.C 2001/07/29 17:39:00 1.12 +++ src/frontends/xforms/FormBibtex.C 2001/08/20 11:10:52 @@ -5,6 +5,7 @@ * * \author Angus Leeming * \author John Levon + * \author Herbert Voss <[EMAIL PROTECTED]> */ #ifdef __GNUG__ @@ -19,7 +20,9 @@ #include "gettext.h" #include "debug.h" #include "support/lstrings.h" +#include "support/filetools.h" + typedef FormCB<ControlBibtex, FormDB<FD_form_bibtex> > base_class; FormBibtex::FormBibtex(ControlBibtex & c) @@ -37,33 +40,77 @@ void FormBibtex::build() // Manage the ok, apply, restore and cancel/close buttons bc().setOK(dialog_->button_ok); bc().setCancel(dialog_->button_cancel); - + + bc().addReadOnly(dialog_->database_browse); bc().addReadOnly(dialog_->database); + bc().addReadOnly(dialog_->style_browse); bc().addReadOnly(dialog_->style); + bc().addReadOnly(dialog_->radio_bibtotoc); } - -ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT *, long) -{ - // minimal validation - if (!compare(fl_get_input(dialog_->database),"")) - return ButtonPolicy::SMI_NOOP; +ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long) { + if (ob == dialog_->database_browse) { + string const in_name = fl_get_input(dialog_->database); + fl_freeze_form(form()); + string out_name = + controller().Browse(in_name, + "Select Database", + "*.bib| BibTeX Databases (*.bib)"); + if (suffixIs(out_name,".bib")) // to prevend names like xxxbib.bib + out_name = ChangeExtension(out_name,""); // latex needs it without +suffix + + fl_set_input(dialog_->database, out_name.c_str()); + fl_unfreeze_form(form()); + } + if (ob == dialog_->style_browse) { + string const in_name = fl_get_input(dialog_->style); + fl_freeze_form(form()); + string out_name = + controller().Browse(in_name, + "Select BibTeX-Style", + "*.bst| BibTeX Styles (*.bst)"); + if (suffixIs(out_name,".bst")) // to prevend names like xxxbib.bib + out_name = OnlyFilename(ChangeExtension(out_name,"")); //only name for +display + fl_set_input(dialog_->style, out_name.c_str()); + fl_unfreeze_form(form()); + } + + if (!compare(fl_get_input(dialog_->database),"")) + return ButtonPolicy::SMI_NOOP; + else return ButtonPolicy::SMI_VALID; } - void FormBibtex::update() { fl_set_input(dialog_->database, controller().params().getContents().c_str()); - fl_set_input(dialog_->style, - controller().params().getOptions().c_str()); + string bibtotoc = "bibtotoc"; + string bibstyle (controller().params().getOptions().c_str()); + if (prefixIs(bibstyle,bibtotoc)) { // bibtotoc exist? + fl_set_button(dialog_->radio_bibtotoc,1); // set button + if (contains(bibstyle,',')) // bibstyle exists? + bibstyle = split(bibstyle,bibtotoc,','); // get bibstyle + else + bibstyle = ""; // no bibstyle + fl_set_input(dialog_->style,bibstyle.c_str()); + } + else { + fl_set_button(dialog_->radio_bibtotoc,0); + fl_set_input(dialog_->style,bibstyle.c_str()); + } } - void FormBibtex::apply() { - controller().params().setContents(fl_get_input(dialog_->database)); - controller().params().setOptions(fl_get_input(dialog_->style)); + controller().params().setContents(fl_get_input(dialog_->database)); + string bibstyle = fl_get_input(dialog_->style); // may be empty! + if ((fl_get_button(dialog_->radio_bibtotoc) > 0) && (!bibstyle.empty())) + controller().params().setOptions("bibtotoc,"+bibstyle); // both + else + if (fl_get_button(dialog_->radio_bibtotoc) > 0) + controller().params().setOptions("bibtotoc"); // bibtotoc and no style + else + controller().params().setOptions(bibstyle); // only style } Index: src/frontends/xforms/form_bibtex.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/form_bibtex.C,v retrieving revision 1.3 diff -u -p -r1.3 form_bibtex.C --- src/frontends/xforms/form_bibtex.C 2001/03/19 16:37:01 1.3 +++ src/frontends/xforms/form_bibtex.C 2001/08/20 11:10:53 @@ -22,9 +22,9 @@ FD_form_bibtex * FormBibtex::build_bibte FL_OBJECT *obj; FD_form_bibtex *fdui = new FD_form_bibtex; - fdui->form = fl_bgn_form(FL_NO_BOX, 220, 130); + fdui->form = fl_bgn_form(FL_NO_BOX, 330, 170); fdui->form->u_vdata = this; - obj = fl_add_box(FL_UP_BOX, 0, 0, 220, 130, ""); + obj = fl_add_box(FL_UP_BOX, 0, 0, 330, 170, ""); { char const * const dummy = N_("Database:|#D"); fdui->database = obj = fl_add_input(FL_NORMAL_INPUT, 80, 10, 130, 30, idex(_(dummy))); @@ -32,12 +32,12 @@ FD_form_bibtex * FormBibtex::build_bibte } fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseInputCB, 0); - fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 20, 90, 90, 30, _("OK")); + fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 20, 130, 90, 30, _("OK")); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseOKCB, 3); { char const * const dummy = N_("Cancel|^["); - fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 120, 90, 90, 30, idex(_(dummy))); + fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 120, 130, 90, 30, +idex(_(dummy))); fl_set_button_shortcut(obj, scex(_(dummy)), 1); } fl_set_object_lsize(obj, FL_NORMAL_SIZE); @@ -49,6 +49,12 @@ FD_form_bibtex * FormBibtex::build_bibte } fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseInputCB, 0); + fdui->database_browse = obj = fl_add_button(FL_PUSH_BUTTON, 230, 10, 80, 30, +_("Browse DB")); + fl_set_button_shortcut(obj, _("B"), 1); + fdui->style_browse = obj = fl_add_button(FL_PUSH_BUTTON, 230, 50, 80, 30, _("Browse +Styles")); + fl_set_button_shortcut(obj, _("l"), 1); + fdui->radio_bibtotoc = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 220, 100, 10, 10, +_("BIB into TOC")); + fl_set_button_shortcut(obj, _("T"), 1); fl_end_form(); fdui->form->fdui = fdui; Index: src/frontends/xforms/form_bibtex.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/form_bibtex.h,v retrieving revision 1.3 diff -u -p -r1.3 form_bibtex.h --- src/frontends/xforms/form_bibtex.h 2001/03/19 16:37:01 1.3 +++ src/frontends/xforms/form_bibtex.h 2001/08/20 11:10:53 @@ -19,6 +19,9 @@ struct FD_form_bibtex { FL_OBJECT *button_ok; FL_OBJECT *button_cancel; FL_OBJECT *style; + FL_OBJECT *database_browse; + FL_OBJECT *style_browse; + FL_OBJECT *radio_bibtotoc; }; #endif /* FD_form_bibtex_h_ */ Index: src/frontends/xforms/forms/form_bibtex.fd =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/forms/form_bibtex.fd,v retrieving revision 1.3 diff -u -p -r1.3 form_bibtex.fd --- src/frontends/xforms/forms/form_bibtex.fd 2001/03/19 16:37:01 1.3 +++ src/frontends/xforms/forms/form_bibtex.fd 2001/08/20 11:10:53 @@ -8,14 +8,14 @@ Unit of measure: FL_COORD_PIXEL =============== FORM =============== Name: form_bibtex -Width: 220 -Height: 130 -Number of Objects: 5 +Width: 330 +Height: 170 +Number of Objects: 8 -------------------- class: FL_BOX type: UP_BOX -box: 0 0 220 130 +box: 0 0 330 170 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -51,7 +51,7 @@ argument: 0 -------------------- class: FL_BUTTON type: RETURN_BUTTON -box: 20 90 90 30 +box: 20 130 90 30 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -69,7 +69,7 @@ argument: 3 -------------------- class: FL_BUTTON type: NORMAL_BUTTON -box: 120 90 90 30 +box: 120 130 90 30 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -101,6 +101,60 @@ gravity: FL_NoGravity FL_NoGravity name: style callback: C_FormBaseInputCB argument: 0 + +-------------------- +class: FL_BUTTON +type: PUSH_BUTTON +box: 230 10 80 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Browse DB +shortcut: B +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: database_browse +callback: +argument: database + +-------------------- +class: FL_BUTTON +type: PUSH_BUTTON +box: 230 50 80 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Browse Styles +shortcut: l +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: style_browse +callback: +argument: + +-------------------- +class: FL_CHECKBUTTON +type: PUSH_BUTTON +box: 220 100 10 10 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: BIB into TOC +shortcut: T +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_bibtotoc +callback: +argument: ============================== create_the_forms Index: src/insets/insetbib.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbib.C,v retrieving revision 1.76 diff -u -p -r1.76 insetbib.C --- src/insets/insetbib.C 2001/08/19 13:13:47 1.76 +++ src/insets/insetbib.C 2001/08/20 11:10:53 @@ -128,42 +128,64 @@ InsetBibtex::~InsetBibtex() } -string const InsetBibtex::getScreenLabel(Buffer const *) const -{ - return _("BibTeX Generated References"); +string const InsetBibtex::getScreenLabel(Buffer const *) const { + return _("BibTeX Generated References"); } - int InsetBibtex::latex(Buffer const * buffer, ostream & os, bool /*fragile*/, bool/*fs*/) const { - // 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 +// +// changing the sequence of the commands +// 1. \bibliographystyle{style} +// 2. \addcontentsline{...} - if option bibtotoc set +// 3. \bibliography{database} +// string adb, db_out; string db_in = getContents(); db_in = split(db_in, adb, ','); +// ---- Style-Options + string style = getOptions(); // maybe empty! and with bibtotoc + string bibtotoc = ""; // maybe no bibtotoc + if (prefixIs(style,"bibtotoc")) { + bibtotoc = "bibtotoc"; + if (contains(style,',')) + style = split(style,bibtotoc,','); + } // endif (prefixIs ... + if (!buffer->niceFile + && IsFileReadable(MakeAbsPath(style, buffer->filepath) + ".bst")) + style = MakeAbsPath(style, buffer->filepath); + if (!style.empty()) // we want no \biblio...{} + os << "\\bibliographystyle{" << style << "}\n"; +// ---- bibtotoc-Option + if (!bibtotoc.empty()) { + if (!contains(textclasslist.NameOfClass(buffer->params.textclass),"art")) { +//maybe a problem when a textclass has no "art" as part of its name, +//because it's than book. for the "official" lyx-layouts it's +//no problem to support all well + if (buffer->params.sides == LyXTextClass::OneSide) + os << "\\clearpage"; // oneside + else + os << "\\cleardoublepage"; // twoside + os << "\\addcontentsline{toc}{chapter}{\\bibname}"; // bookclass + } // endif + else + os << "\\addcontentsline{toc}{section}{\\refname}"; //article class + } // endif +// ---- database +// 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 while(!adb.empty()) { if (!buffer->niceFile && IsFileReadable(MakeAbsPath(adb, buffer->filepath)+".bib")) adb = os::external_path(MakeAbsPath(adb, buffer->filepath)); - db_out += adb; db_out += ','; db_in= split(db_in, adb,','); } db_out = strip(db_out, ','); - // Idem, but simpler - string style; - if (!buffer->niceFile - && IsFileReadable(MakeAbsPath(getOptions(), buffer->filepath) - + ".bst")) - style = MakeAbsPath(getOptions(), buffer->filepath); - else - style = getOptions(); - - os << "\\bibliographystyle{" << style << "}\n" - << "\\bibliography{" << db_out << "}\n"; + os << "\\bibliography{" << db_out << "}\n"; return 2; } @@ -264,7 +286,7 @@ bool InsetBibtex::delDatabase(string con int bibitemMaxWidth(BufferView * bv, LyXFont const & font) { int w = 0; - // Ha, now we are mainly at 1.2.0 and it is still here (Jug) +#warning Ha, now we are mainly at 1.2.0 and it is still here (Jug) // Does look like a hack? It is! (but will change at 0.13) Paragraph * par = bv->buffer()->paragraph;