From eef71b84392a58d1515bf6a115539ca00666b44d Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 20 Jun 2002 20:41:00 +0000 Subject: [PATCH] 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 --- src/frontends/controllers/ChangeLog | 5 + src/frontends/controllers/ControlBibtex.C | 14 +++ src/frontends/controllers/ControlBibtex.h | 7 +- src/frontends/controllers/ControlTexinfo.C | 79 +++---------- src/frontends/controllers/ControlTexinfo.h | 10 +- src/frontends/controllers/Makefile.am | 2 + src/frontends/controllers/tex_helpers.C | 125 +++++++++++++++++++++ src/frontends/controllers/tex_helpers.h | 30 +++++ src/frontends/xforms/ChangeLog | 12 ++ src/frontends/xforms/FormBibtex.C | 72 ++++++------ src/frontends/xforms/forms/form_bibtex.fd | 92 +++++++++++---- src/support/ChangeLog | 4 + src/support/lyxalgo.h | 11 +- src/support/lyxfunctional.h | 1 - 14 files changed, 343 insertions(+), 121 deletions(-) create mode 100644 src/frontends/controllers/tex_helpers.C create mode 100644 src/frontends/controllers/tex_helpers.h diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 890addc7d8..927b1d9d99 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2002-06-18 Herbert Voss + + * 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 * ControlGraphics.C: just make the mask *.* diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index 43e7557cb3..43bdfc1362 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -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(); +} diff --git a/src/frontends/controllers/ControlBibtex.h b/src/frontends/controllers/ControlBibtex.h index 2778d6701b..b77d88a27c 100644 --- a/src/frontends/controllers/ControlBibtex.h +++ b/src/frontends/controllers/ControlBibtex.h @@ -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(); diff --git a/src/frontends/controllers/ControlTexinfo.C b/src/frontends/controllers/ControlTexinfo.C index 7637bbdccf..d11d082224 100644 --- a/src/frontends/controllers/ControlTexinfo.C +++ b/src/frontends/controllers/ControlTexinfo.C @@ -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 dbase = getVectorFromString(str_in,"\n"); - std::sort(dbase.begin(), dbase.end()); // sort entries - std::vector::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"); +} diff --git a/src/frontends/controllers/ControlTexinfo.h b/src/frontends/controllers/ControlTexinfo.h index d11df12191..07c9208b35 100644 --- a/src/frontends/controllers/ControlTexinfo.h +++ b/src/frontends/controllers/ControlTexinfo.h @@ -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; diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index efd4130239..0310f37bab 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -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 \ diff --git a/src/frontends/controllers/tex_helpers.C b/src/frontends/controllers/tex_helpers.C new file mode 100644 index 0000000000..2c04a412a7 --- /dev/null +++ b/src/frontends/controllers/tex_helpers.C @@ -0,0 +1,125 @@ +/** + * \file tex_helpers.C + * Copyright 1995-2002 the LyX Team + * Read the file COPYING + * + * \author Herbert Voss + */ + +#include +#include +#include +#include + +#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 listWithoutPath(vector & dbase) +{ + vector::iterator it = dbase.begin(); + vector::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 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; +} diff --git a/src/frontends/controllers/tex_helpers.h b/src/frontends/controllers/tex_helpers.h new file mode 100644 index 0000000000..0294b46601 --- /dev/null +++ b/src/frontends/controllers/tex_helpers.h @@ -0,0 +1,30 @@ +/** + * \file tex_helpers.h + * Copyright 1995-2002 the LyX Team + * Read the file COPYING + * + * \author Herbert Voss + */ + +#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 diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index e15b34ba9c..0e5c1c9c04 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,15 @@ +2002-06-20 John Levon + + * FormBibtex.C: use new lyx::eliminate_duplicates + +2002-06-20 Herbert Voss + + * 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 * XWorkArea.h: diff --git a/src/frontends/xforms/FormBibtex.C b/src/frontends/xforms/FormBibtex.C index 2694e41373..8e968d38d1 100644 --- a/src/frontends/xforms/FormBibtex.C +++ b/src/frontends/xforms/FormBibtex.C @@ -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 -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 dbase = getVectorFromString(str_in); for (vector::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 diff --git a/src/frontends/xforms/forms/form_bibtex.fd b/src/frontends/xforms/forms/form_bibtex.fd index f9d0406f24..f805327101 100644 --- a/src/frontends/xforms/forms/form_bibtex.fd +++ b/src/frontends/xforms/forms/form_bibtex.fd @@ -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 diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 6344f6e3f5..a6694dc862 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,7 @@ +2002-06-19 John Levon + + * lyxalgo.h: add eliminate_duplicates + 2002-06-17 Herbert Voss * filetools.[C]: (readBB_from_PSFile) add a helperfunc diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h index dcbfd6d5d3..60aaff7b2b 100644 --- a/src/support/lyxalgo.h +++ b/src/support/lyxalgo.h @@ -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 +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 diff --git a/src/support/lyxfunctional.h b/src/support/lyxfunctional.h index 2e52337a26..0d129c6c63 100644 --- a/src/support/lyxfunctional.h +++ b/src/support/lyxfunctional.h @@ -14,7 +14,6 @@ namespace lyx { - template class class_fun_t { public: