string initpath = lyxrc.document_path;
if (available()) {
- string const trypath = owner_->buffer()->filepath;
+ string const trypath = owner_->buffer()->filePath();
// If directory is writeable, use this as default.
if (IsDirWriteable(trypath))
initpath = trypath;
2002-01-14 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
+ * lyx_cb.C (MenuWrite): buffer->fileName is guaranteed to be
+ absolute
+
+ * vc-backend.C (most methods):
+ * exporter.C (Export):
+ * converter.C (convert):
+ (runLaTeX):
+ * LyXSendto.C (SendtoApplyCB):
+ * lyxfunc.C (dispatch):
+ (menuNew):
+ (open):
+ (doImport):
+ * lyx_cb.C (AutoSave):
+ (InsertAsciiFile):
+ * BufferView_pimpl.C (MenuInsertLyXFile):
+ * buffer.C (runChktex): use Buffer::filePath().
+
+ * buffer.h: rename filename to filename_; rename filepath to
+ filepath_ and make it private
+ (filePath): new method
+
+ * buffer.C (writeFile): use fileName()
+ (getLatexName):
+
+ * lyx_main.C (init): fix starting of LyX when the binary is a
+ link from so,ewhere else.
+
* minibuffer.C: include <cctype> for isprint
2002-01-14 Angus Leeming <a.leeming@ic.ac.uk>
command = subst(command, "$$FName", fname);
command += " &"; // execute in background
// push directorypath, if necessary
- string path = OnlyPath(buffer->fileName());
+ string path = buffer->filePath();
if (lyxrc.use_tempdir || !IsDirWriteable(path)){
path = buffer->tmppath;
}
Buffer::Buffer(string const & file, bool ronly)
: paragraph(0), lyx_clean(true), bak_clean(true),
unnamed(false), dep_clean(0), read_only(ronly),
- filename(file), users(0)
+ filename_(file), users(0)
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
// filename = file;
- filepath = OnlyPath(file);
+ filepath_ = OnlyPath(file);
// paragraph = 0;
// lyx_clean = true;
// bak_clean = true;
string const Buffer::getLatexName(bool no_path) const
{
- string const name = ChangeExtension(MakeLatexName(filename), ".tex");
+ string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
if (no_path)
return OnlyFilename(name);
else
void Buffer::setFileName(string const & newfile)
{
- filename = MakeAbsPath(newfile);
- filepath = OnlyPath(filename);
- setReadonly(IsFileWriteable(filename) == 0);
+ filename_ = MakeAbsPath(newfile);
+ filepath_ = OnlyPath(filename_);
+ setReadonly(IsFileWriteable(filename_) == 0);
updateTitles();
}
// warnings, only cerr.
// Needed for autosave in background or panic save (Matthias 120496)
- if (read_only && (fname == filename)) {
+ if (read_only && (fname == fileName())) {
// Here we should come with a question if we should
// perform the write anyway.
if (flag)
// get LaTeX-Filename
string const name = getLatexName();
- string path = OnlyPath(filename);
+ string path = filePath();
string const org_path = path;
if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
makeLaTeXFile(name, org_path, false);
TeXErrors terr;
- Chktex chktex(lyxrc.chktex_command, name, filepath);
+ Chktex chktex(lyxrc.chktex_command, name, filePath());
int res = chktex.run(terr); // run chktex
if (res == -1) {
/// Mark this buffer as dirty.
void markDirty();
- /// Returns the buffers filename.
+ /// Returns the buffer's filename. It is always an absolute path.
string const & fileName() const;
+ /// Returns the the path where the buffer lives.
+ /// It is always an absolute path.
+ string const & filePath() const;
+
/** A transformed version of the file name, adequate for LaTeX.
\param no_path optional if \c true then the path is stripped.
*/
/// Where to put temporary files.
string tmppath;
- /// The path to the document file.
- string filepath;
-
/** If we are writing a nice LaTeX file or not.
While writing as LaTeX, tells whether we are
doing a 'nice' LaTeX file */
bool read_only;
/// name of the file the buffer is associated with.
- string filename;
+ string filename_;
+
+ /// The path to the document file.
+ string filepath_;
/// Format number of buffer
int file_format;
inline
string const & Buffer::fileName() const
{
- return filename;
+ return filename_;
+}
+
+
+inline
+string const & Buffer::filePath() const
+{
+ return filepath_;
}
Systemcalls one;
int res;
if (conv.original_dir && buffer) {
- Path p(buffer->filepath);
+ Path p(buffer->filePath());
res = one.startscript(type, command);
} else
res = one.startscript(type, command);
// do the LaTex run(s)
TeXErrors terr;
- LaTeX latex(command, name, buffer->filepath);
+ LaTeX latex(command, name, buffer->filePath());
int result = latex.run(terr,
bv ? bv->owner()->getLyXFunc() : 0);
// LaTeX backend
else if (backend_format == format)
buffer->makeLaTeXFile(filename, string(), true);
- else if (contains(buffer->filepath, ' ')) {
+ else if (contains(buffer->filePath(), ' ')) {
Alert::alert(_("Cannot run latex."),
_("The path to the lyx file cannot contain spaces."));
return false;
} else
- buffer->makeLaTeXFile(filename, buffer->filepath, false);
+ buffer->makeLaTeXFile(filename, buffer->filePath(), false);
string outfile_base = (put_in_tempdir)
? filename : buffer->getLatexName(false);
+2002-01-14 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
+
+ * Liason.C (printBuffer): use Buffer::filePath
+
2001-12-19 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
* Timeout.h:
return false;
// Push directory path.
- string path = OnlyPath(buffer->fileName());
+ string path = buffer->filePath();
if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
path = buffer->tmppath;
}
+2002-01-14 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
+
+ * ControlExternal.C (Browse): use Buffer::filePath; simplify (more
+ can be done)
+
+ * ControlGraphics.C (Browse): remove overzealous shortcut
+
2002-01-14 Angus Leeming <a.leeming@ic.ac.uk>
* FormMinipage.C (apply, update): MinipageParams::width renamed
string const ControlExternal::Browse(string const & input) const
{
- string buf = MakeAbsPath(lv_.buffer()->fileName());
- string buf2 = OnlyPath(buf);
+#ifdef WITH_WARNINGS
+#warning Candidate for using browseRelFile
+#endif
+ string buf;
+ string const bufpath = lv_.buffer()->filePath();
if (!input.empty()) {
- buf = MakeAbsPath(input, buf2);
+ buf = MakeAbsPath(input, bufpath);
buf = OnlyPath(buf);
} else {
- buf = OnlyPath(lv_.buffer()->fileName());
+ buf = bufpath;
}
FileDialog fileDlg(&lv_,
string p = result.second;
- buf = MakeRelPath(p, buf2);
+ buf = MakeRelPath(p, bufpath);
current_path = OnlyPath(p);
once = 1;
string const ControlGraphics::Browse(string const & in_name)
{
- string const title = N_("Graphics|#G#g");
+ string const title = N_("Graphics");
// FIXME: currently we need the second '|' to prevent mis-interpretation
string const pattern = "*.(eps|png|jpeg|jpg|gif)|";
#include "LyXView.h"
#include "lyxfunc.h"
#include "gettext.h"
-
#include "helper_funcs.h"
#include "lyxrc.h"
+#include "support/filetools.h"
using std::pair;
using std::make_pair;
{
string const title = N_("Select document to include");
- string pattern;
-
// input TeX, verbatim, or LyX file ?
+ string pattern;
switch (in_type) {
case INPUT:
pattern = _("*.tex| LaTeX Documents (*.tex)");
pair<string, string> dir1(N_("Documents|#o#O"),
string(lyxrc.document_path));
- return browseFile(&lv_, in_name, title, pattern, dir1);
+ string const docpath = OnlyPath(params().masterFilename_);
+
+ return browseRelFile(&lv_, in_name, docpath, title, pattern, dir1);
}
}
+string const browseRelFile(LyXView * lv, string const & filename,
+ string const & refpath,
+ string const & title,
+ string const & pattern,
+ pair<string,string> const & dir1,
+ pair<string,string> const & dir2)
+{
+ string const fname = MakeAbsPath(filename, refpath);
+
+ string const outname = browseFile(lv, fname, title, pattern, dir1);
+ string const reloutname = MakeRelPath(outname, refpath);
+ if(prefixIs(reloutname, "../"))
+ return outname;
+ else
+ return reloutname;
+}
+
+
// sorry this is just a temporary hack we should include vspace.h! (Jug)
extern const char * stringFromUnit(int);
std::pair<string,string> const & dir2 = std::make_pair(string(), string()));
+/* Wrapper around browseFile which tries to provide a filename
+ relative to relpath. If the relative path is of the form "foo.txt"
+ or "bar/foo.txt", then it is returned as relative. OTOH, if it is
+ of the form "../baz/foo.txt", an absolute path is returned. This is
+ intended to be useful for insets which encapsulate files/
+*/
+string const browseRelFile(LyXView *lv, string const & filename,
+ string const & refpath,
+ string const & title,
+ string const & pattern,
+ std::pair<string,string> const & dir1 = std::make_pair(string(), string()),
+ std::pair<string,string> const & dir2 = std::make_pair(string(), string()));
+
+
/// Returns a vector of units that can be used to create a valid LaTeX length.
std::vector<string> const getLatexUnits();
+2002-01-14 Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
+
+ * insetparent.C (InsetParent):
+ * insetgraphicsParams.C (Write):
+ (Read):
+ * insetgraphics.C (prepareFile):
+ (readFigInset):
+ (docbook):
+ * insetexternal.C (executeCommand):
+ (doSubstitution): use Buffer::filePath
+
+ * insetbib.C (getFiles): add a #warning for Angus
+
+ * insetgraphics.C: Add a remark about how filenames should be
+ considered to be relative to buffer (but absolute is still allowed)
+ (draw): do not try to get status if lyxrc.use_gui is false
+
2002-01-14 Angus Leeming <a.leeming@ic.ac.uk>
* inset.[Ch]:
}
if (!buffer->niceFile
- && IsFileReadable(MakeAbsPath(style, buffer->filepath) + ".bst")) {
- style = MakeAbsPath(style, buffer->filepath);
+ && IsFileReadable(MakeAbsPath(style, buffer->filePath()) + ".bst")) {
+ style = MakeAbsPath(style, buffer->filePath());
}
if (!style.empty()) { // we want no \biblio...{}
// 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));
+ 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,',');
vector<string> const InsetBibtex::getFiles(Buffer const &) const
{
// Doesn't appear to be used (Angus, 31 July 2001)
- // Path p(buffer->filepath);
+ // Path p(buffer->filePath());
+#ifdef WITH_WARNINGS
+#warning Angus, do you now that this is not supposed to be used but to change path?
+// I would say this is needed to find bib files which are in the
+// document directory (JMarc 14/01/2002)
+#endif
vector<string> vec;
void InsetExternal::executeCommand(string const & s,
Buffer const * buffer) const
{
- string buf = MakeAbsPath(buffer->fileName());
- string path = OnlyPath(buf);
- Path p(path);
+ Path p(buffer->filePath());
Systemcalls one;
if (lyxerr.debugging()) {
lyxerr << "Executing '" << s << "' in '"
- << path << "'" << endl;
+ << buffer->filePath() << "'" << endl;
}
one.startscript(Systemcalls::Wait, s);
}
{
string result;
string const basename = ChangeExtension(params_.filename, string());
- string filepath = "";
+ string filepath;
if (buffer && (!buffer->niceFile)) {
- filepath = OnlyPath(MakeAbsPath(buffer->fileName()));
+ filepath = buffer->filePath();
}
result = subst(s, "$$FName", params_.filename);
result = subst(result, "$$Basename", basename);
string contents;
if (buffer) {
// Make sure we are in the directory of the buffer
- string const buf = MakeAbsPath(buffer->fileName());
- string const path = OnlyPath(buf);
- Path p(path);
+ Path p(buffer->filePath());
contents = GetFileContents(file);
} else {
contents = GetFileContents(file);
We should probably use what the user asks to use... but when he chooses
by the file dialog we normally get an absolute path and this may not be
what the user meant.
-
+ [Note that browseRelFile in helper_funcs.* provides a file name
+ which is relative if it is at reference path (here puffer path)
+ level or below, and an absolute path if the file name is not a
+ `natural' relative file name. In any case,
+ MakeAbsPath(filename, buf->filePath())
+ is guaranteed to provide the correct absolute path. This is what is
+ done know for include insets. Feel free to ask me -- JMarc
+ 14/01/2002]
+
* If we are trying to create a file in a read-only directory and there
are graphics that need converting, the converting will fail because
it is done in-place, into the same directory as the original image.
to find it in the clipart, or in the same directory with the image.
* Keep a tab on the image file, if it changes, update the lyx view.
* The image choosing dialog could show thumbnails of the image formats
- it knows of, thus selection based on the image instead of based on
- filename.
+ it knows of, thus selection based on the image instead of based on
+ filename.
* Add support for the 'picins' package.
* Add support for the 'picinpar' package.
* Improve support for 'subfigure' - Allow to set the various options
that are possible.
- * Add resizing by percentage of image size (50%, 150%) - usefull for two
- images of different size to be resized where they both should have
- the same scale compared to each other.
+ * Add resizing by percentage of image size (50%, 150%) -
+ usefull for two images of different size to be resized where
+ they both should have the same scale compared to each other.
*/
/* NOTES:
// Get the image status, default to unknown error.
GraphicsCacheItem::ImageStatus status = GraphicsCacheItem::UnknownError;
- if (lyxrc.display_graphics != "no" &&
- params.display != InsetGraphicsParams::NONE &&
+ if (lyxrc.display_graphics != "no" && lyxrc.use_gui
+ && params.display != InsetGraphicsParams::NONE &&
cacheHandle.get())
status = cacheHandle->getImageStatus();
} else if (token == "file") {
if (lex.next()) {
string const name = lex.getString();
- string const path = OnlyPath(buf->fileName());
+ string const path = buf->filePath();
params.filename = MakeAbsPath(name, path);
}
} else if (token == "extra") {
//lyxerr << "temp = " << temp << "\n";
//lyxerr << "outfile = " << outfile << endl;
} else {
- string const path = OnlyPath(buf->fileName());
+ string const path = buf->filePath();
string const relname = MakeRelPath(params.filename, path);
outfile = RemoveExtension(relname);
}
int InsetGraphics::docbook(Buffer const * buf, ostream & os) const
{
// Change the path to be relative to the main file.
- string const buffer_dir = OnlyPath(buf->fileName());
+ string const buffer_dir = buf->filePath();
string const filename = RemoveExtension(
MakeRelPath(params.filename, buffer_dir));
// If there is no filename, write nothing for it.
if (! filename.empty()) {
os << "filename "
- << MakeRelPath(filename, OnlyPath(buf->fileName()))
+ << MakeRelPath(filename, buf->filePath())
<< '\n';
}
if (!filename.empty()) {
// Make the filename with absolute directory.
- filename = MakeAbsPath(filename, OnlyPath(buf->fileName()));
+ filename = MakeAbsPath(filename, buf->filePath());
}
} else if (token == "display") {
lex.next();
: InsetCommand(p)
{
string const fn = p.getContents();
- setContents(MakeAbsPath(fn, OnlyPath(bf.fileName())));
+ setContents(MakeAbsPath(fn, bf.filePath()));
}
XFlush(GUIRunTime::x11Display());
if (!buffer->save()) {
- string const fname = buffer->fileName();
- string const s = MakeAbsPath(fname);
if (Alert::askQuestion(_("Save failed. Rename and try again?"),
- MakeDisplayPath(s, 50),
+ MakeDisplayPath(buffer->fileName(), 50),
_("(If not, document is not saved.)"))) {
return WriteAs(bv, buffer);
}
bv->owner()->message(_("Autosaving current document..."));
// create autosave filename
- string fname = OnlyPath(bv->buffer()->fileName());
+ string fname = bv->buffer()->filePath();
fname += "#";
fname += OnlyFilename(bv->buffer()->fileName());
fname += "#";
FileDialog fileDlg(bv->owner(), _("Select file to insert"),
(asParagraph) ? LFUN_FILE_INSERT_ASCII_PARA : LFUN_FILE_INSERT_ASCII);
- FileDialog::Result result = fileDlg.Select(bv->owner()->buffer()->filepath);
+ FileDialog::Result result = fileDlg.Select(bv->owner()->buffer()->filePath());
if (result.first == FileDialog::Later)
return;
string binpath = os::binpath();
string binname = os::binname();
- string fullbinpath = binpath;
-
+ string fullbinname = MakeAbsPath(binname, binpath);
+
if (binpath.empty()) {
lyxerr << _("Warning: could not determine path of binary.")
<< "\n"
<< _("If you have problems, try starting LyX with an absolute path.")
<< endl;
}
+ lyxerr[Debug::INIT] << "Name of binary: " << binname << endl;
lyxerr[Debug::INIT] << "Path of binary: " << binpath << endl;
//
searchpath += lyxdir + ';';
}
- // <path of binary>/TOP_SRCDIR/lib
- build_lyxdir = MakeAbsPath("../lib", binpath);
- if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
- searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
- binpath) + ';';
- lyxerr[Debug::INIT] << "Checking whether LyX is run in "
- "place... yes" << endl;
- } else {
- lyxerr[Debug::INIT]
- << "Checking whether LyX is run in place... no"
- << endl;
- build_lyxdir.erase();
+ string fullbinpath = binpath;
+ FileInfo file(fullbinname, true);
+ if (file.isLink()) {
+ lyxerr[Debug::INIT] << "binary is a link" << endl;
+ string link;
+ if (LyXReadLink(fullbinname, link)) {
+ // Path of binary/../share/name of binary/
+ searchpath += NormalizePath(AddPath(binpath,
+ "../share/")
+ + OnlyFilename(binname));
+ searchpath += ';';
+ fullbinpath = link;
+ binpath = MakeAbsPath(OnlyPath(fullbinpath));
+ }
}
-
+
bool followlink;
do {
- // Path of binary/../share/name of binary/
+ // Path of binary/../share/name of binary/
searchpath += NormalizePath(AddPath(binpath, "../share/") +
OnlyFilename(binname)) + ';';
- // Follow Symlinks
+ // Follow Symlinks
FileInfo file(fullbinpath, true);
followlink = file.isLink();
if (followlink) {
+ lyxerr << " directory " << fullbinpath
+ << " is a link" << endl;
string link;
if (LyXReadLink(fullbinpath, link)) {
fullbinpath = link;
}
} while (followlink);
+ // <path of binary>/TOP_SRCDIR/lib
+ build_lyxdir = MakeAbsPath("../lib", binpath);
+ if (!FileSearch(build_lyxdir, "lyxrc.defaults").empty()) {
+ searchpath += MakeAbsPath(AddPath(TOP_SRCDIR, "lib"),
+ binpath) + ';';
+ lyxerr[Debug::INIT] << "Checking whether LyX is run in "
+ "place... yes" << endl;
+ } else {
+ lyxerr[Debug::INIT]
+ << "Checking whether LyX is run in place... no"
+ << endl;
+ build_lyxdir.erase();
+ }
+
// Hardcoded dir
searchpath += LYX_DIR;
{
string const filename =
MakeAbsPath(argument,
- OnlyPath(owner->buffer()->fileName()));
+ owner->buffer()->filePath());
setMessage(N_("Opening child document ") +
MakeDisplayPath(filename) + "...");
owner->view()->savePosition(0);
string initpath = lyxrc.document_path;
if (owner->view()->available()) {
- string const trypath = owner->buffer()->filepath;
+ string const trypath = owner->buffer()->filePath();
// If directory is writeable, use this as default.
if (IsDirWriteable(trypath))
initpath = trypath;
string initpath = lyxrc.document_path;
if (owner->view()->available()) {
- string const trypath = owner->buffer()->filepath;
+ string const trypath = owner->buffer()->filePath();
// If directory is writeable, use this as default.
if (IsDirWriteable(trypath))
initpath = trypath;
string initpath = lyxrc.document_path;
if (owner->view()->available()) {
- string const trypath = owner->buffer()->filepath;
+ string const trypath = owner->buffer()->filePath();
// If directory is writeable, use this as default.
if (IsDirWriteable(trypath))
initpath = trypath;
cmd += "\" \"";
cmd += OnlyFilename(owner_->fileName());
cmd += "\"";
- doVCCommand(cmd, owner_->filepath);
+ doVCCommand(cmd, owner_->filePath());
owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
}
void RCS::checkIn(string const & msg)
{
doVCCommand("ci -q -u -m\"" + msg + "\" \""
- + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
+ + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
}
{
owner_->markLyxClean();
doVCCommand("co -q -l \""
- + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
+ + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
}
void RCS::revert()
{
doVCCommand("co -f -u" + version() + " \""
- + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
+ + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
// We ignore changes and just reload!
owner_->markLyxClean();
owner_->getUser()->owner()
lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
doVCCommand("rcs -o" + version() + " \""
+ OnlyFilename(owner_->fileName()) + "\"",
- owner_->filepath);
+ owner_->filePath());
}
void RCS::getLog(string const & tmpf)
{
doVCCommand("rlog \""
- + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filepath);
+ + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, owner_->filePath());
}
void CVS::registrer(string const & msg)
{
doVCCommand("cvs -q add -m \"" + msg + "\" \""
- + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath);
+ + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath());
owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
}
{
doVCCommand("cvs -q commit -m \"" + msg + "\" \""
+ OnlyFilename(owner_->fileName()) + "\"",
- owner_->filepath);
+ owner_->filePath());
owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD);
}
string const fil = OnlyFilename(owner_->fileName());
doVCCommand("rm -f \"" + fil + "\"; cvs update \"" + fil + "\"",
- owner_->filepath);
+ owner_->filePath());
owner_->markLyxClean();
owner_->getUser()->owner()
->getLyXFunc()->dispatch(LFUN_MENURELOAD);
{
doVCCommand("cvs log \""
+ OnlyFilename(owner_->fileName()) + "\" > " + tmpf,
- owner_->filepath);
+ owner_->filePath());
}