Fix the texinfo dialog and associated cleanup.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7196 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-06-20 14:03:49 +00:00
parent 2d8eb4b9d4
commit 2b1a447714
23 changed files with 181 additions and 182 deletions

View File

@ -1,3 +1,9 @@
2003-06-20 Angus Leeming <leeming@lyx.org>
* scripts/TeXFiles.sh (types): Generalise the sed that tries to
normalise paths /foo//bar ==> /foo/bar to work with arbitrary '///' etc
also.
2003-06-19 Angus Leeming <leeming@lyx.org>
* lib/bind/cua.bind:

View File

@ -72,7 +72,7 @@ for type in $types ; do
rm -f $outfile
touch $outfile
dirs=`kpsewhich --show-path=$kpsetype 2>/dev/null | tr "$SEP" " " | sed -e 's%///%/%' -e 's%//%/%g' -e 's%!!%%g'`
dirs=`kpsewhich --show-path=$kpsetype 2>/dev/null | tr "$SEP" " " | sed -e 's%/\{2,\}%/%g' -e 's%!!%%g'`
for dir in $dirs ; do
find $dir -follow -name "*.$type" >>$outfile 2>/dev/null

View File

@ -6,6 +6,7 @@ src/LaTeX.C
src/MenuBackend.C
src/ParagraphParameters.C
src/buffer.C
src/buffer_funcs.C
src/bufferlist.C
src/bufferparams.C
src/bufferview_funcs.C

View File

@ -1,3 +1,15 @@
2003-06-20 Angus Leeming <leeming@lyx.org>
* tex_helpers.[Ch] (getTexFileList): changed to
void getTexFileList(string const & file, vector<string> & contents);
* ControlBibtex.[Ch] (getBibFiles, getBibStyles): now passed a
vector<string> to fill rather than returning a string.
* ControlTexinfo.[Ch] (rescanStyles, runTexhash): removed. No need
for an extra layer of indirection.
(getContents): moved out of class to getTexFileList.
2003-06-19 Angus Leeming <leeming@lyx.org>
* ControlTexinfo.[Ch]: rewritten to use the Dialog-based scheme.

View File

@ -21,7 +21,10 @@
#include "tex_helpers.h"
#include "gettext.h"
#include "support/filetools.h"
using std::pair;
using std::vector;
ControlBibtex::ControlBibtex(Dialog & d)
@ -40,27 +43,39 @@ string const ControlBibtex::Browse(string const & in_name,
}
string const ControlBibtex::getBibStyles() const
void ControlBibtex::getBibStyles(vector<string> & data) const
{
string list = getTexFileList("bstFiles.lst", false);
data.clear();
getTexFileList("bstFiles.lst", data);
// test, if we have a valid list, otherwise run rescan
if (list.empty()) {
if (data.empty()) {
rescanBibStyles();
list = getTexFileList("bstFiles.lst", false);
getTexFileList("bstFiles.lst", data);
}
vector<string>::iterator it = data.begin();
vector<string>::iterator end = data.end();
for (; it != end; ++it) {
*it = OnlyFilename(*it);
}
return list;
}
string const ControlBibtex::getBibFiles() const
void ControlBibtex::getBibFiles(vector<string> & data) const
{
string list = getTexFileList("bibFiles.lst", false);
data.clear();
getTexFileList("bibFiles.lst", data);
// test, if we have a valid list, otherwise run rescan
if (list.empty()) {
if (data.empty()) {
rescanBibStyles();
list = getTexFileList("bibFiles.lst", false);
getTexFileList("bibFiles.lst", data);
}
vector<string>::iterator it = data.begin();
vector<string>::iterator end = data.end();
for (; it != end; ++it) {
*it = OnlyFilename(*it);
}
return list;
}

View File

@ -15,6 +15,7 @@
#include "ControlCommand.h"
#include <vector>
/** A controller for Bibtex dialogs.
@ -27,9 +28,9 @@ public:
/// Browse for a file
string const Browse(string const &, string const &, string const &);
/// get the list of bst files
string const getBibStyles() const;
void getBibStyles(std::vector<string> & data) const;
/// get the list of bib files
string const getBibFiles() const;
void getBibFiles(std::vector<string> & data) const;
/// build filelists of all availabe bib/bst/cls/sty-files. done through
/// kpsewhich and an external script, saved in *Files.lst
void rescanBibStyles() const;

View File

@ -11,65 +11,41 @@
#include <config.h>
#include "ControlTexinfo.h"
#include "tex_helpers.h"
#include "funcrequest.h"
namespace {
string getFileList(ControlTexinfo::texFileSuffix type, bool withFullPath)
void getTexFileList(ControlTexinfo::texFileSuffix type,
std::vector<string> & list)
{
string filename;
switch (type) {
case ControlTexinfo::bst:
return getTexFileList("bstFiles.lst", withFullPath);
case ControlTexinfo::bst:
filename = "bstFiles.lst";
break;
case ControlTexinfo::cls:
return getTexFileList("clsFiles.lst", withFullPath);
case ControlTexinfo::cls:
filename = "clsFiles.lst";
break;
case ControlTexinfo::sty:
return getTexFileList("styFiles.lst", withFullPath);
case ControlTexinfo::sty:
filename = "styFiles.lst";
break;
}
return string();
getTexFileList(filename, list);
if (list.empty()) {
// build filelists of all availabe bst/cls/sty-files.
// Done through kpsewhich and an external script,
// saved in *Files.lst
rescanTexStyles();
getTexFileList(filename, list);
}
}
} // namespace anon
ControlTexinfo::ControlTexinfo(Dialog & parent)
: Dialog::Controller(parent)
{}
// build filelists of all availabe bst/cls/sty-files. done through
// kpsewhich and an external script, saved in *Files.lst
void ControlTexinfo::rescanStyles() const
{
rescanTexStyles();
}
void ControlTexinfo::runTexhash() const
{
texhash();
}
string const
ControlTexinfo::getContents(texFileSuffix type, bool withFullPath) const
{
string list(getFileList(type, withFullPath));
// initial scan
if (list.empty()) {
rescanStyles();
list = getFileList(type, withFullPath);
}
return list;
}
void ControlTexinfo::viewFile(string const filename) const
void ControlTexinfo::viewFile(string const & filename) const
{
string const arg = "file " + filename;
kernel().dispatch(FuncRequest(LFUN_DIALOG_SHOW, arg));

View File

@ -14,6 +14,7 @@
#include "Dialog.h"
#include "tex_helpers.h"
/** A controller for Texinfo dialogs. */
@ -34,18 +35,19 @@ public:
/// the file extensions
enum texFileSuffix {cls, sty, bst};
/// show contents af a file
void viewFile(string const filename) const;
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;
private:
///
virtual void apply() {}
};
/** Fill \c contents from one of the three texfiles.
* Each entry in the file list is returned as a pair<name_with_path, name_only>
*/
void getTexFileList(ControlTexinfo::texFileSuffix type,
std::vector<string> & contents);
#endif // CONTROLTEXINFO_H

View File

@ -10,7 +10,6 @@
#include <config.h>
#include "tex_helpers.h"
#include "debug.h"
@ -22,6 +21,7 @@
#include "support/path.h"
#include "support/lyxalgo.h"
#include <boost/cregex.hpp>
#include <vector>
#include <fstream>
#include <algorithm>
@ -33,18 +33,6 @@ 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;
}
} // namespace anon
// build filelists of all availabe bst/cls/sty-files. done through
// kpsewhich and an external script, saved in *Files.lst
@ -69,26 +57,24 @@ void texhash()
}
string const getTexFileList(string const & filename, bool withFullPath)
void getTexFileList(string const & filename, std::vector<string> & list)
{
list.clear();
string const file = LibFileSearch("", filename);
if (file.empty())
return string();
return;
vector<string> dbase =
getVectorFromString(GetFileContents(file), "\n");
list = getVectorFromString(GetFileContents(file), "\n");
if (withFullPath) {
lyx::eliminate_duplicates(dbase);
string const str_out =
getStringFromVector(dbase, "\n");
return str_out;
// Normalise paths like /foo//bar ==> /foo/bar
boost::RegEx regex("/{2,}");
std::vector<string>::iterator it = list.begin();
std::vector<string>::iterator end = list.end();
for (; it != end; ++it) {
*it = regex.Merge(*it, "/");
}
vector<string> dbaseWP = listWithoutPath(dbase);
lyx::eliminate_duplicates(dbaseWP);
string const str_out =
getStringFromVector(dbaseWP, "\n");
return str_out;
lyx::eliminate_duplicates(list);
}

View File

@ -13,6 +13,9 @@
#include "LString.h"
#include <utility>
#include <vector>
// build filelists of all availabe bst/cls/sty-files. done through
// kpsewhich and an external script, saved in *Files.lst
@ -21,8 +24,10 @@ void rescanTexStyles();
/// rebuild the textree
void texhash();
/// return one of the three texfiles
string const getTexFileList(string const & filename, bool withFullPath);
/** Fill \c contents from one of the three texfiles.
* Each entry in the file list is returned as a name_with_path
*/
void getTexFileList(string const & filename, std::vector<string> & contents);
/// get the options of stylefile
string const getListOfOptions(string const & classname, string const & type);

View File

@ -1,3 +1,13 @@
2003-06-20 Angus Leeming <leeming@lyx.org>
* QBibtexDialog.C (browsePressed): fix warning of comparison between
signed and unsigned ints.
* QBibtex.C (update_contents): changes due to changed controller
interface.
* QTexinfo.[Ch]:
* QTexinfoDialog.C: clean-up handling of TeX file databases.
2003-06-19 Alfredo Braunstein <abraunst@libero.it>
@ -125,7 +135,6 @@
* QGraphicsDialog.C: use relative file browsing
(bug 1028)
>>>>>>> 1.522
2003-05-24 John Levon <levon@movementarian.org>
* Toolbar_pimpl.C: workaround a Qt bug with combobox

View File

@ -74,8 +74,8 @@ void QBibtex::update_contents()
dialog_->add_->bibLB->clear();
vector<string> const bib_str = getVectorFromString(
controller().getBibFiles(), "\n");
vector<string> bib_str;
controller().getBibFiles(bib_str);
for (vector<string>::const_iterator it = bib_str.begin();
it != bib_str.end(); ++it) {
string bibItem(ChangeExtension(*it, ""));
@ -102,8 +102,8 @@ void QBibtex::update_contents()
int item_nr(-1);
vector<string> const str = getVectorFromString(
controller().getBibStyles(), "\n");
vector<string> str;
controller().getBibStyles(str);
for (vector<string>::const_iterator it = str.begin();
it != str.end(); ++it) {
string item(ChangeExtension(*it, ""));

View File

@ -71,7 +71,7 @@ void QBibtexDialog::browsePressed()
bool present = false;
unsigned int pres = 0;
for (unsigned int i = 0; i != styleCB->count(); i++) {
for (int i = 0; i != styleCB->count(); ++i) {
if (fromqstr(styleCB->text(i)) == filen) {
present = true;
pres = i;

View File

@ -18,6 +18,7 @@
#include "qt_helpers.h"
#include "helper_funcs.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include <qlistbox.h>
@ -48,28 +49,17 @@ void QTexinfo::build_dialog()
void QTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
{
string const fstr = controller().getContents(whichStyle, true);
switch (whichStyle) {
case ControlTexinfo::bst:
bst_ = getVectorFromString(fstr, "\n");
break;
case ControlTexinfo::cls:
cls_ = getVectorFromString(fstr, "\n");
break;
case ControlTexinfo::sty:
sty_ = getVectorFromString(fstr, "\n");
break;
}
dialog_->fileList->clear();
ContentsType & data = texdata_[whichStyle];
getTexFileList(whichStyle, data);
bool const withFullPath = dialog_->path->isChecked();
string const str = controller().getContents(whichStyle, withFullPath);
vector<string> flist = getVectorFromString(str, "\n");
for (vector<string>::const_iterator fitem = flist.begin();
fitem != flist.end(); ++fitem) {
dialog_->fileList->insertItem(toqstr((*fitem)));
dialog_->fileList->clear();
ContentsType::const_iterator it = data.begin();
ContentsType::const_iterator end = data.end();
for (; it != end; ++it) {
string const line = withFullPath ? *it : OnlyFilename(*it);
dialog_->fileList->insertItem(toqstr(line));
}
activeStyle = whichStyle;

View File

@ -16,6 +16,7 @@
#include "QDialogView.h"
#include "ControlTexinfo.h"
#include <map>
#include <vector>
class QTexinfoDialog;
@ -44,11 +45,8 @@ private:
///
ControlTexinfo::texFileSuffix activeStyle;
///
std::vector<string> cls_;
///
std::vector<string> sty_;
///
std::vector<string> bst_;
typedef std::vector<string> ContentsType;
std::map<ControlTexinfo::texFileSuffix, ContentsType> texdata_;
};
#endif // QTEXINFO_H

View File

@ -22,7 +22,7 @@
#include <qpushbutton.h>
#include <qcombobox.h>
#include <vector>
using std::vector;
QTexinfoDialog::QTexinfoDialog(QTexinfo * form)
@ -50,7 +50,7 @@ void QTexinfoDialog::closeEvent(QCloseEvent * e)
void QTexinfoDialog::rescanClicked()
{
// build new *Files.lst
form_->controller().rescanStyles();
rescanTexStyles();
form_->updateStyles();
enableViewPB();
}
@ -58,27 +58,9 @@ void QTexinfoDialog::rescanClicked()
void QTexinfoDialog::viewClicked()
{
int const fitem = fileList->currentItem();
string sel;
switch (whatStyle->currentItem()) {
case 0:
sel = form_->cls_[fitem];
break;
case 1:
sel = form_->sty_[fitem];
break;
case 2:
sel = form_->bst_[fitem];
break;
default:
break;
}
// a valid entry?
if (!sel.empty()) {
form_->controller().viewFile(sel);
}
vector<string>::size_type const fitem = fileList->currentItem();
vector<string> const & data = form_->texdata_[form_->activeStyle];
form_->controller().viewFile(data[fitem]);
}

View File

@ -1,3 +1,10 @@
2003-06-20 Angus Leeming <leeming@lyx.org>
* FormBibtex.C (input, update): changes due to changed controller
interface.
* FormTexinfo.[Ch]: clean-up handling of TeX file databases.
2003-06-19 Alfredo Braunstein <abraunst@libero.it>
* lyx_gui.C (start): call ::loadLyXFile instead

View File

@ -142,9 +142,10 @@ ButtonPolicy::SMInput FormBibtex::input(FL_OBJECT * ob, long ob_value)
} else if (ob == dialog_->button_rescan) {
fl_clear_browser(dialog_->browser_styles);
controller().rescanBibStyles();
string const str =
controller().getBibStyles();
fl_add_browser_line(dialog_->browser_styles, str.c_str());
vector<string> styles;
controller().getBibStyles(styles);
fl_add_browser_line(dialog_->browser_styles,
getStringFromVector(styles, "\n").c_str());
}
// with an empty database nothing makes sense ...
@ -175,9 +176,12 @@ void FormBibtex::update()
}
fl_set_input(dialog_->input_style, bibstyle.c_str());
vector<string> styles;
controller().getBibStyles(styles);
fl_clear_browser(dialog_->browser_styles);
string const str = controller().getBibStyles();
fl_add_browser_line(dialog_->browser_styles, str.c_str());
fl_add_browser_line(dialog_->browser_styles,
getStringFromVector(styles, "\n").c_str());
}
namespace {

View File

@ -10,8 +10,6 @@
*/
#include <config.h>
#include <fstream>
#include "xformsBC.h"
#include "FormTexinfo.h"
@ -21,11 +19,10 @@
#include "xforms_helpers.h"
#include "support/LAssert.h"
#include "support/lstrings.h"
#include "support/filetools.h"
#include "lyx_forms.h"
using std::vector;
typedef FormController<ControlTexinfo, FormView<FD_texinfo> > base_class;
FormTexinfo::FormTexinfo(Dialog & parent)
@ -76,40 +73,26 @@ ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
if (ob == dialog_->button_texhash) {
// makes only sense if the rights are set well for
// users (/var/lib/texmf/ls-R)
controller().runTexhash();
texhash();
// texhash requires a rescan and an update of the styles
controller().rescanStyles();
rescanTexStyles();
updateStyles(activeStyle);
} else if (ob == dialog_->browser && ob_value == 2) {
// double click in browser: view selected file
string selection = getString(dialog_->browser);
if (!fl_get_button(dialog_->check_fullpath)) {
// contents in browser has filenames without path
// reconstruct path from controller getContents
string const files = controller().getContents(activeStyle, true);
vector<string> const vec = getVectorFromString(files, "\n");
ContentsType::size_type const sel = fl_get_browser(ob);
ContentsType const & data = texdata_[activeStyle];
if (sel >= 1 && sel <= data.size())
controller().viewFile(data[sel-1]);
// find line in files vector
vector<string>::const_iterator it = vec.begin();
for (; it != vec.end(); ++it) {
if ((*it).find(selection) != string::npos) {
selection = *it;
break;
}
}
}
if (!selection.empty()) {
controller().viewFile(selection);
}
// reset the browser so that the following single-click callback doesn't do anything
// reset the browser so that the following single-click
// callback doesn't do anything
fl_deselect_browser(dialog_->browser);
} else if (ob == dialog_->button_rescan) {
// build new *Files.lst
controller().rescanStyles();
rescanTexStyles();
updateStyles(activeStyle);
} else if (ob == dialog_->check_fullpath) {
@ -135,13 +118,18 @@ ButtonPolicy::SMInput FormTexinfo::input(FL_OBJECT * ob, long ob_value) {
void FormTexinfo::updateStyles(ControlTexinfo::texFileSuffix whichStyle)
{
fl_clear_browser(dialog_->browser);
ContentsType & data = texdata_[whichStyle];
getTexFileList(whichStyle, data);
bool const withFullPath = fl_get_button(dialog_->check_fullpath);
string const str =
controller().getContents(whichStyle, withFullPath);
fl_add_browser_line(dialog_->browser, str.c_str());
fl_clear_browser(dialog_->browser);
ContentsType::const_iterator it = data.begin();
ContentsType::const_iterator end = data.end();
for (; it != end; ++it) {
string const line = withFullPath ? *it : OnlyFilename(*it);
fl_add_browser_line(dialog_->browser, line.c_str());
}
activeStyle = whichStyle;
}

View File

@ -15,6 +15,7 @@
#include "FormDialogView.h"
#include "ControlTexinfo.h"
#include <map>
struct FD_texinfo;
@ -36,6 +37,10 @@ private:
void updateStyles(ControlTexinfo::texFileSuffix);
///
ControlTexinfo::texFileSuffix activeStyle;
///
typedef std::vector<string> ContentsType;
std::map<ControlTexinfo::texFileSuffix, ContentsType> texdata_;
};
#endif // FORMTEXINFO_H

View File

@ -1,3 +1,7 @@
2003-06-20 Angus Leeming <leeming@lyx.org>
* filetools.[Ch] (NormalizePath): also change /foo//bar ==> /foo/bar.
2003-06-18 Angus Leeming <leeming@lyx.org>
* many files: add the standard blurb, "This file is part of LyX" etc

View File

@ -37,6 +37,7 @@
#include "Lsstream.h"
#include <boost/cregex.hpp>
#include <cctype>
#include <cstdlib>
#include <cstdio>
@ -676,6 +677,7 @@ string const ExpandPath(string const & path)
// Normalize a path
// Constracts path/../path
// Can't handle "../../" or "/../" (Asger)
// Also converts paths like /foo//bar ==> /foo/bar
string const NormalizePath(string const & path)
{
string TempBase;
@ -688,6 +690,10 @@ string const NormalizePath(string const & path)
// Make implicit current directory explicit
RTemp = "./" +path;
// Normalise paths like /foo//bar ==> /foo/bar
boost::RegEx regex("/{2,}");
RTemp = regex.Merge(RTemp, "/");
while (!RTemp.empty()) {
// Split by next /
RTemp = split(RTemp, Temp, '/');

View File

@ -175,7 +175,9 @@ MakeRelPath(string const & abspath, string const & basepath);
/// Strip filename from path name
string const OnlyPath(string const & fname);
/// Normalize a path. Constracts path/../path
/** Normalize a path. Constracts path/../path
* Also converts paths like /foo//bar ==> /foo/bar
*/
string const NormalizePath(string const & path);
/// Strips path from filename