Merge Herbert's bibtex patch; it doesn't introduce any new bugs and

it's nice ...

Herbert please look at the bugs I reported concerning when there is no cls etc. list please.
For this and FormTexinfo


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4442 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-06-20 20:41:00 +00:00
parent 60b905b885
commit eef71b8439
14 changed files with 343 additions and 121 deletions

View File

@ -1,3 +1,8 @@
2002-06-18 Herbert Voss <voss@perce.de>
* tex_helpers.[Ch]: move functions from ControlTexinfo into this
helperstuff. Now the bibtex gui can use some of these functions
2002-06-18 John Levon <moz@compsoc.man.ac.uk>
* ControlGraphics.C: just make the mask *.*

View File

@ -23,6 +23,7 @@
#include "BufferView.h"
#include "lyxrc.h"
#include "helper_funcs.h"
#include "tex_helpers.h"
#include "gettext.h"
#include "frontends/LyXView.h"
@ -35,6 +36,7 @@ ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d)
{}
void ControlBibtex::applyParamsToInset()
{
if (params().getContents() != inset()->params().getContents())
@ -63,3 +65,15 @@ string const ControlBibtex::Browse(string const & in_name,
return browseRelFile(&lv_, in_name, lv_.buffer()->filePath(),
title, pattern, dir1);
}
string const ControlBibtex::getBibStyles() const
{
return getTexFileList("bstFiles.lst", false);
}
void ControlBibtex::rescanBibStyles() const
{
rescanTexStyles();
}

View File

@ -31,7 +31,12 @@ public:
ControlBibtex(LyXView &, Dialogs &);
/// Browse for a file
string const Browse(string const &, string const &, string const &);
/// get the list of bst files
string const getBibStyles() const;
/// build filelists of all availabe bst/cls/sty-files. done through
/// kpsewhich and an external script, saved in *Files.lst
void rescanBibStyles() const;
private:
/// Dispatch the changed parameters to the kernel.
virtual void applyParamsToInset();

View File

@ -22,11 +22,11 @@
#include "BufferView.h"
#include "gettext.h"
#include "helper_funcs.h"
#include "tex_helpers.h"
#include "frontends/LyXView.h"
#include "support/filetools.h" // FileSearch
#include "support/systemcall.h"
#include "support/path.h"
#include "support/lstrings.h"
@ -42,86 +42,41 @@ ControlTexinfo::ControlTexinfo(LyXView & lv, Dialogs & d)
// kpsewhich and an external script, saved in *Files.lst
void ControlTexinfo::rescanStyles() const
{
// Run rescan in user lyx directory
Path p(user_lyxdir);
Systemcall one;
one.startscript(Systemcall::Wait,
LibFileSearch("scripts", "TeXFiles.sh"));
p.pop();
rescanTexStyles();
}
void ControlTexinfo::runTexhash() const
{
// Run texhash in user lyx directory
Path p(user_lyxdir);
//path to texhash through system
Systemcall one;
one.startscript(Systemcall::Wait, "texhash");
p.pop();
// Alert::alert(_("texhash run!"),
// _("rebuilding of the TeX-tree could only be successfull"),
// _("if you have had user-write-permissions to the tex-dir."));
texhash();
}
namespace {
string const sortEntries(string & str_in)
{
std::vector<string> dbase = getVectorFromString(str_in,"\n");
std::sort(dbase.begin(), dbase.end()); // sort entries
std::vector<string>::iterator p =
std::unique(dbase.begin(), dbase.end()); // compact
dbase.erase(p, dbase.end()); // shrink
return getStringFromVector(dbase,"\n");
}
} //namespace anon
string const
ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
{
static string const bstFilename("bstFiles.lst");
static string const clsFilename("clsFiles.lst");
static string const styFilename("styFiles.lst");
string filename;
switch (type) {
case bst:
filename = bstFilename;
case bst:
return getTexFileList("bstFiles.lst", withFullPath);
break;
case cls:
filename = clsFilename;
case cls:
return getTexFileList("clsFiles.lst", withFullPath);
break;
case sty:
filename = styFilename;
case sty:
return getTexFileList("styFiles.lst", withFullPath);
break;
}
string fileContents = GetFileContents(LibFileSearch(string(),filename));
// everything ok?
if (!fileContents.empty()) {
if (withFullPath)
return(sortEntries(fileContents));
else {
int Entries = 1;
string dummy = OnlyFilename(token(fileContents,'\n',1));
string contents = dummy;
do {
dummy = OnlyFilename(token(fileContents,'\n',++Entries));
contents += ("\n"+dummy);
} while (!dummy.empty());
return(sortEntries(contents));
}
} else
return _("Missing filelist. try Rescan");
return string();
}
void ControlTexinfo::viewFile(string const filename) const
{
lv_.getDialogs()->showFile(filename);
}
string const ControlTexinfo::getClassOptions(string const & filename) const
{
return getListOfOptions(filename, "cls");
}

View File

@ -30,13 +30,15 @@ public:
enum texFileSuffix {cls, sty, bst};
///
ControlTexinfo(LyXView &, Dialogs &);
///
/// show contents af a file
void viewFile(string const filename) const;
///
/// show all classoptions
string const getClassOptions(string const & filename) const;
/// build new cls bst sty - lists
void rescanStyles() const;
///
/// build new bst sty cls lists
void runTexhash() const;
///
/// read filecontents
string const getContents(texFileSuffix type, bool withPath) const;

View File

@ -15,6 +15,8 @@ libcontrollers_la_SOURCES= \
character.h \
frnt_lang.C \
frnt_lang.h \
tex_helpers.C \
tex_helpers.h \
ButtonController.h \
ButtonControllerBase.C \
ButtonControllerBase.h \

View File

@ -0,0 +1,125 @@
/**
* \file tex_helpers.C
* Copyright 1995-2002 the LyX Team
* Read the file COPYING
*
* \author Herbert Voss <voss@lyx.org>
*/
#include <config.h>
#include <vector.h>
#include <fstream>
#include <algorithm>
#include "gettext.h"
#include "tex_helpers.h"
#include "support/filetools.h"
#include "debug.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
#include "support/path.h"
#include "support/lyxalgo.h"
using std::vector;
using std::sort;
using std::unique;
extern string user_lyxdir; // home of *Files.lst
namespace {
vector<string> listWithoutPath(vector<string> & dbase)
{
vector<string>::iterator it = dbase.begin();
vector<string>::iterator end = dbase.end();
for (; it != end; ++it)
*it = OnlyFilename(*it);
return dbase;
}
}
// build filelists of all availabe bst/cls/sty-files. done through
// kpsewhich and an external script, saved in *Files.lst
void rescanTexStyles()
{
// Run rescan in user lyx directory
Path p(user_lyxdir);
Systemcall one;
one.startscript(Systemcall::Wait,
LibFileSearch("scripts", "TeXFiles.sh"));
p.pop();
}
void texhash()
{
// Run texhash in user lyx directory
Path p(user_lyxdir);
//path to texhash through system
Systemcall one;
one.startscript(Systemcall::Wait,"texhash");
p.pop();
}
string const getTexFileList(string const & filename, bool withFullPath)
{
vector<string> dbase = getVectorFromString(
GetFileContents(LibFileSearch(string(),filename)), "\n");
lyx::eliminate_duplicates(dbase);
string const str_out = withFullPath ?
getStringFromVector(dbase, "\n") :
getStringFromVector(listWithoutPath(dbase), "\n");
// everything ok?
if (str_out.empty())
return _("Missing filelist. try Rescan");
return str_out;
}
string const getListOfOptions(string const & classname,
string const & type)
{
string const filename = getTexFileFromList(classname,type);
string optionList = string();
std::ifstream is(filename.c_str());
while (is) {
string s;
is >> s;
if (contains(s,"DeclareOption")) {
s = s.substr(s.find("DeclareOption"));
s = split(s,'{'); // cut front
s = token(s,'}',0); // cut end
// FIXME: why is this commented out ?
// s = s.substr(0, s.find('}')+1); // format entry
optionList += (s + '\n');
}
}
return optionList;
}
string const getTexFileFromList(string const & file,
string const & type)
{
string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
lyxerr << "Search for classfile " << file_ << endl;
string const lstfile = (type == "cls") ? "clsFiles.lst" : "styFiles.lst";
string const allClasses = GetFileContents(LibFileSearch(string(), lstfile));
int entries = 0;
string classfile = token(allClasses, '\n', entries);
int count = 0;
while ((!contains(classfile, file) ||
(OnlyFilename(classfile) != file)) &&
(++count < 1000)) {
classfile = token(allClasses, '\n', ++entries);
}
// now we have filename with full path
lyxerr << "with full path: " << classfile << endl;
return classfile;
}

View File

@ -0,0 +1,30 @@
/**
* \file tex_helpers.h
* Copyright 1995-2002 the LyX Team
* Read the file COPYING
*
* \author Herbert Voss <voss@lyx.org>
*/
#ifndef TEX_HELPERS_H
#define TEX_HELPERS_H
// build filelists of all availabe bst/cls/sty-files. done through
// kpsewhich and an external script, saved in *Files.lst
void rescanTexStyles();
/// rebuild the textree
void texhash();
/// return one of the three texfiles
string const getTexFileList(string const & filename, bool withFullPath);
/// get the options of stylefile
string const getListOfOptions(string const & classname,
string const & type);
/// get a class with full path from the list
string const getTexFileFromList(string const & classname,
string const & type);
#endif // TEX_HELPERS_H

View File

@ -1,3 +1,15 @@
2002-06-20 John Levon <moz@compsoc.man.ac.uk>
* FormBibtex.C: use new lyx::eliminate_duplicates
2002-06-20 Herbert Voss <voss@perce.de>
* FormBibtex.C:
* forms/form_bibtex.fd: give better support for choosing the
bibstyle (new browserfield with the available bibstyles).
move some code of ControlTexinfo into a helper
file support/tex-helpers to use some of the functions
2002-06-20 John Levon <moz@compsoc.man.ac.uk>
* XWorkArea.h:

View File

@ -27,6 +27,7 @@
#include "support/LAssert.h"
#include "support/lstrings.h"
#include "support/filetools.h"
#include "support/lyxalgo.h"
using std::vector;
@ -57,6 +58,8 @@ void FormBibtex::build()
bc().addReadOnly(dialog_->button_database_browse);
bc().addReadOnly(dialog_->input_database);
bc().addReadOnly(dialog_->button_style_browse);
bc().addReadOnly(dialog_->button_style_choose);
bc().addReadOnly(dialog_->button_rescan);
bc().addReadOnly(dialog_->input_style);
bc().addReadOnly(dialog_->check_bibtotoc);
@ -64,14 +67,21 @@ void FormBibtex::build()
string str = _("The database you want to cite from. Insert it without the default extension \".bib\". If you insert it with the browser, LyX strips the extension. Several databases must be separated by a comma: \"natbib, books\".");
tooltips().init(dialog_->button_database_browse, str);
str = _("Browse your directory for BibTeX stylefiles.");
str = _("Browse your directory for BibTeX stylefiles");
tooltips().init(dialog_->button_style_browse, str);
str = _("The BibTeX style to use (only one allowed). Insert it without the default extension \".bst\" and without path. Most of the bibstyles are stored in $TEXMF/bibtex/bst. $TEXMF is the root dir of the local TeX tree. In \"View->TeX Information\" you can list all installed styles.");
str = _("The BibTeX style to use (only one allowed). Insert it without the default extension \".bst\" and without path or choose one from the browsers list. Most of the bibstyles are stored in $TEXMF/bibtex/bst. $TEXMF is the root dir of the local TeX tree.");
tooltips().init(dialog_->input_style, str);
str = _("Activate this option if you want the bibliography to appear in the Table of Contents (which doesn't happen by default).");
str = _("Activate this option if you want the bibliography to appear in the Table of Contents (which doesn't happen by default)");
tooltips().init(dialog_->check_bibtotoc, str);
str = _("Choose a BibTeX style from the browsers list");
tooltips().init(dialog_->button_style_choose, str);
str = _("Updates your TeX system for a new bibstyle list. Only the styles which are in directories where TeX finds them are listed!");
tooltips().init(dialog_->button_rescan, str);
}
@ -82,8 +92,8 @@ ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long)
string const in_name = fl_get_input(dialog_->input_database);
string out_name =
controller().Browse("",
_("Select Database"),
_("*.bib| BibTeX Databases (*.bib)"));
_("Select Database"),
_("*.bib| BibTeX Databases (*.bib)"));
if (!out_name.empty()) {
// add the database to any existing ones
if (!in_name.empty())
@ -93,22 +103,28 @@ ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long)
fl_set_input(dialog_->input_database, out_name.c_str());
fl_unfreeze_form(form());
}
}
if (ob == dialog_->button_style_browse) {
} else if (ob == dialog_->button_style_browse) {
string const in_name = fl_get_input(dialog_->input_style);
string out_name =
controller().Browse(in_name,
_("Select BibTeX-Style"),
_("*.bst| BibTeX Styles (*.bst)"));
_("Select BibTeX-Style"),
_("*.bst| BibTeX Styles (*.bst)"));
if (!out_name.empty()) {
fl_freeze_form(form());
fl_set_input(dialog_->input_style, out_name.c_str());
fl_unfreeze_form(form());
}
}
} else if (ob == dialog_->button_style_choose) {
unsigned int selection = fl_get_browser(dialog_->browser_styles);
string const out_name =
fl_get_browser_line(dialog_->browser_styles, selection);
fl_set_input(dialog_->input_style,
ChangeExtension(out_name, string()).c_str());
} else if (ob == dialog_->button_rescan)
controller().rescanBibStyles();
if (!compare(fl_get_input(dialog_->input_database),"")) {
// with an empty database nothing makes sense ...
if (!compare(fl_get_input(dialog_->input_database), "")) {
return ButtonPolicy::SMI_NOOP;
}
@ -122,43 +138,35 @@ void FormBibtex::update()
controller().params().getContents().c_str());
string bibtotoc = "bibtotoc";
string bibstyle (controller().params().getOptions().c_str());
if (prefixIs(bibstyle,bibtotoc)) { // bibtotoc exists?
if (prefixIs(bibstyle, bibtotoc)) { // bibtotoc exists?
fl_set_button(dialog_->check_bibtotoc,1);
if (contains(bibstyle,',')) { // bibstyle exists?
bibstyle = split(bibstyle,bibtotoc,',');
if (contains(bibstyle, ',')) { // bibstyle exists?
bibstyle = split(bibstyle, bibtotoc, ',');
} else {
bibstyle = "";
bibstyle = string();
}
fl_set_input(dialog_->input_style,bibstyle.c_str());
fl_set_input(dialog_->input_style, bibstyle.c_str());
} else {
fl_set_button(dialog_->check_bibtotoc,0);
fl_set_input(dialog_->input_style,bibstyle.c_str());
fl_set_input(dialog_->input_style, bibstyle.c_str());
}
string const str =
controller().getBibStyles();
fl_add_browser_line(dialog_->browser_styles, str.c_str());
}
namespace {
// Remove all duplicate entries in c.
// Taken stright out of Stroustrup
template<class C>
void eliminate_duplicates(C & c)
{
sort(c.begin(), c.end());
typename C::iterator p = std::unique(c.begin(), c.end());
c.erase(p, c.end());
}
string const unique_and_no_extensions(string const & str_in)
{
vector<string> dbase = getVectorFromString(str_in);
for (vector<string>::iterator it = dbase.begin();
it != dbase.end(); ++it) {
*it = ChangeExtension(*it, "");
*it = ChangeExtension(*it, string());
}
eliminate_duplicates(dbase);
lyx::eliminate_duplicates(dbase);
return getStringFromVector(dbase);
}
@ -188,7 +196,7 @@ void FormBibtex::apply()
if (bibtotoc && (!bibstyle.empty())) {
// both bibtotoc and style
controller().params().setOptions("bibtotoc,"+bibstyle);
controller().params().setOptions("bibtotoc," + bibstyle);
} else if (bibtotoc) {
// bibtotoc and no style

View File

@ -9,14 +9,14 @@ SnapGrid: 1
=============== FORM ===============
Name: form_bibtex
Width: 450
Height: 160
Number of Objects: 8
Width: 312
Height: 358
Number of Objects: 11
--------------------
class: FL_BOX
type: UP_BOX
box: 0 0 450 160
box: 0 0 312 358
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -34,10 +34,10 @@ argument:
--------------------
class: FL_INPUT
type: NORMAL_INPUT
box: 90 10 245 30
box: 15 29 164 28
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_LEFT
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
@ -52,7 +52,7 @@ argument: 0
--------------------
class: FL_BUTTON
type: RETURN_BUTTON
box: 250 120 90 30
box: 12 316 90 30
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -70,7 +70,7 @@ argument: 3
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 350 120 90 30
box: 112 316 90 30
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -88,10 +88,10 @@ argument: 2
--------------------
class: FL_INPUT
type: NORMAL_INPUT
box: 90 45 245 30
box: 14 80 166 26
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_LEFT
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
@ -106,7 +106,7 @@ argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 340 10 100 29
box: 192 29 100 29
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -124,7 +124,61 @@ argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 340 45 100 30
box: 195 167 100 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: Choose|#C
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: button_style_choose
callback: C_FormBaseInputCB
argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 12 258 30 30
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: Add bibliography to TOC|#A
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: check_bibtotoc
callback: C_FormBaseInputCB
argument: 0
--------------------
class: FL_BROWSER
type: HOLD_BROWSER
box: 14 129 168 111
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Available Styles|#v
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: browser_styles
callback: C_FormBaseInputCB
argument: 0
--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 192 79 100 30
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
@ -140,20 +194,20 @@ callback: C_FormBaseInputCB
argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 90 80 30 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
class: FL_BUTTON
type: NORMAL_BUTTON
box: 196 208 100 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: Add bibliography to TOC|#A
label: Update List|#U
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: check_bibtotoc
name: button_rescan
callback: C_FormBaseInputCB
argument: 0

View File

@ -1,3 +1,7 @@
2002-06-19 John Levon <moz@compsoc.man.ac.uk>
* lyxalgo.h: add eliminate_duplicates
2002-06-17 Herbert Voss <voss@perce.de>
* filetools.[C]: (readBB_from_PSFile) add a helperfunc

View File

@ -9,8 +9,6 @@
* \author unknown
*/
#ifndef LYX_ALGO_H
#define LYX_ALGO_H
@ -87,6 +85,15 @@ count (Iterator first, Iterator last, T const & value)
#endif
}
/// Remove all duplicate entries in c.
template<class C>
void eliminate_duplicates(C & c)
{
std::sort(c.begin(), c.end());
typename C::iterator p = std::unique(c.begin(), c.end());
c.erase(p, c.end());
}
} // namespace lyx
#endif // LYX_ALGO_H

View File

@ -14,7 +14,6 @@
namespace lyx {
template<class R, class C, class A>
class class_fun_t {
public: