From fb424bae1b693200ba4a506b2775929d25d77be3 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 14 Jan 2002 23:31:23 +0000 Subject: [PATCH] fix starting up which binary is really a symlink; make sure insetinclude file browser returns a relative path when this makes sense; straightforward cleanup of the ways to get filename and filepath for a buffer (in preparation of future work) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3381 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 2 +- src/ChangeLog | 27 +++++++++++ src/LyXSendto.C | 2 +- src/buffer.C | 18 +++---- src/buffer.h | 23 ++++++--- src/converter.C | 4 +- src/exporter.C | 4 +- src/frontends/ChangeLog | 4 ++ src/frontends/Liason.C | 2 +- src/frontends/controllers/ChangeLog | 7 +++ src/frontends/controllers/ControlExternal.C | 13 +++-- src/frontends/controllers/ControlGraphics.C | 2 +- src/frontends/controllers/ControlInclude.C | 9 ++-- src/frontends/controllers/helper_funcs.C | 18 +++++++ src/frontends/controllers/helper_funcs.h | 14 ++++++ src/insets/ChangeLog | 17 +++++++ src/insets/insetbib.C | 15 ++++-- src/insets/insetexternal.C | 14 ++---- src/insets/insetgraphics.C | 30 +++++++----- src/insets/insetgraphicsParams.C | 4 +- src/insets/insetparent.C | 2 +- src/lyx_cb.C | 8 ++-- src/lyx_main.C | 53 ++++++++++++++------- src/lyxfunc.C | 8 ++-- src/vc-backend.C | 20 ++++---- 25 files changed, 224 insertions(+), 96 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index cf671b5216..11506b505e 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1445,7 +1445,7 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filen) 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; diff --git a/src/ChangeLog b/src/ChangeLog index 05111ce2ff..fd700b29b4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,32 @@ 2002-01-14 Jean-Marc Lasgouttes + * 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 for isprint 2002-01-14 Angus Leeming diff --git a/src/LyXSendto.C b/src/LyXSendto.C index 5f672ac07b..d457dc7fa1 100644 --- a/src/LyXSendto.C +++ b/src/LyXSendto.C @@ -80,7 +80,7 @@ void SendtoApplyCB(FL_OBJECT *, long) 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; } diff --git a/src/buffer.C b/src/buffer.C index 19a4e42294..c396b1ebad 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -151,11 +151,11 @@ extern int tex_code_break_column; 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; @@ -200,7 +200,7 @@ Buffer::~Buffer() 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 @@ -273,9 +273,9 @@ void Buffer::resetAutosaveTimers() const 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(); } @@ -1702,7 +1702,7 @@ bool Buffer::writeFile(string const & fname, bool flag) const // 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) @@ -3449,7 +3449,7 @@ int Buffer::runChktex() // 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)) { @@ -3466,7 +3466,7 @@ int Buffer::runChktex() 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) { diff --git a/src/buffer.h b/src/buffer.h index a85e04a4c1..d46e715ef9 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -212,9 +212,13 @@ public: /// 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. */ @@ -312,9 +316,6 @@ public: /// 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 */ @@ -339,7 +340,10 @@ private: 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; @@ -529,7 +533,14 @@ void Buffer::markDirty() inline string const & Buffer::fileName() const { - return filename; + return filename_; +} + + +inline +string const & Buffer::filePath() const +{ + return filepath_; } diff --git a/src/converter.C b/src/converter.C index 0250142766..d9f0f72cf7 100644 --- a/src/converter.C +++ b/src/converter.C @@ -649,7 +649,7 @@ bool Converters::convert(Buffer const * buffer, 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); @@ -851,7 +851,7 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & 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); diff --git a/src/exporter.C b/src/exporter.C index 68922a87fd..4a779ca0e3 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -71,12 +71,12 @@ bool Exporter::Export(Buffer * buffer, string const & format, // 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); diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 416ebdcd0b..faf995cad8 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,7 @@ +2002-01-14 Jean-Marc Lasgouttes + + * Liason.C (printBuffer): use Buffer::filePath + 2001-12-19 Jean-Marc Lasgouttes * Timeout.h: diff --git a/src/frontends/Liason.C b/src/frontends/Liason.C index e54e8a9813..f1fe2c8dcb 100644 --- a/src/frontends/Liason.C +++ b/src/frontends/Liason.C @@ -106,7 +106,7 @@ bool printBuffer(Buffer * buffer, PrinterParams const & pp) return false; // Push directory path. - string path = OnlyPath(buffer->fileName()); + string path = buffer->filePath(); if (lyxrc.use_tempdir || !IsDirWriteable(path)) { path = buffer->tmppath; } diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 7d1567eb56..c37de776d4 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,10 @@ +2002-01-14 Jean-Marc Lasgouttes + + * ControlExternal.C (Browse): use Buffer::filePath; simplify (more + can be done) + + * ControlGraphics.C (Browse): remove overzealous shortcut + 2002-01-14 Angus Leeming * FormMinipage.C (apply, update): MinipageParams::width renamed diff --git a/src/frontends/controllers/ControlExternal.C b/src/frontends/controllers/ControlExternal.C index 16ab959398..a38d8ade1c 100644 --- a/src/frontends/controllers/ControlExternal.C +++ b/src/frontends/controllers/ControlExternal.C @@ -148,14 +148,17 @@ ExternalTemplate ControlExternal::getTemplate(int i) const 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_, @@ -185,7 +188,7 @@ string const ControlExternal::Browse(string const & input) const string p = result.second; - buf = MakeRelPath(p, buf2); + buf = MakeRelPath(p, bufpath); current_path = OnlyPath(p); once = 1; diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index 6c13079749..b48630766c 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -77,7 +77,7 @@ extern string user_lyxdir; 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)|"; diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C index b9775ab4a9..a4796621b7 100644 --- a/src/frontends/controllers/ControlInclude.C +++ b/src/frontends/controllers/ControlInclude.C @@ -24,9 +24,9 @@ #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; @@ -50,9 +50,8 @@ string const ControlInclude::Browse(string const & in_name, Type in_type) { 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)"); @@ -70,7 +69,9 @@ string const ControlInclude::Browse(string const & in_name, Type in_type) pair 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); } diff --git a/src/frontends/controllers/helper_funcs.C b/src/frontends/controllers/helper_funcs.C index d3fdf4435e..ec3ef27b5e 100644 --- a/src/frontends/controllers/helper_funcs.C +++ b/src/frontends/controllers/helper_funcs.C @@ -108,6 +108,24 @@ string const browseFile(LyXView * lv, string const & filename, } +string const browseRelFile(LyXView * lv, string const & filename, + string const & refpath, + string const & title, + string const & pattern, + pair const & dir1, + pair 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); diff --git a/src/frontends/controllers/helper_funcs.h b/src/frontends/controllers/helper_funcs.h index 095f8bb91a..3631b692b0 100644 --- a/src/frontends/controllers/helper_funcs.h +++ b/src/frontends/controllers/helper_funcs.h @@ -46,6 +46,20 @@ string const browseFile(LyXView *lv, string const & filename, std::pair 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 const & dir1 = std::make_pair(string(), string()), + std::pair const & dir2 = std::make_pair(string(), string())); + + /// Returns a vector of units that can be used to create a valid LaTeX length. std::vector const getLatexUnits(); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index af64bcd229..3ecc8d6425 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,20 @@ +2002-01-14 Jean-Marc Lasgouttes + + * 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 * inset.[Ch]: diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index c82d404800..933b3ddf91 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -160,8 +160,8 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, } 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...{} @@ -198,8 +198,8 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, // 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,','); @@ -213,7 +213,12 @@ int InsetBibtex::latex(Buffer const * buffer, ostream & os, vector 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 vec; diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 735480991c..0349abad2b 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -214,13 +214,11 @@ string const InsetExternal::getScreenLabel(Buffer const *) const 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); } @@ -231,9 +229,9 @@ string const InsetExternal::doSubstitution(Buffer const * buffer, { 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); @@ -252,9 +250,7 @@ string const InsetExternal::doSubstitution(Buffer const * buffer, 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); diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 9b081b1fa3..b2b1e46e9f 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -28,7 +28,15 @@ Known BUGS: 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. @@ -69,15 +77,15 @@ TODO Extended features: 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: @@ -301,8 +309,8 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, // 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(); @@ -433,7 +441,7 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) } 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") { @@ -668,7 +676,7 @@ InsetGraphics::prepareFile(Buffer const *buf) const //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); } @@ -764,7 +772,7 @@ int InsetGraphics::linuxdoc(Buffer const *, ostream &) const 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)); diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index 846f28d84e..b99b52e070 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -233,7 +233,7 @@ void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const // If there is no filename, write nothing for it. if (! filename.empty()) { os << "filename " - << MakeRelPath(filename, OnlyPath(buf->fileName())) + << MakeRelPath(filename, buf->filePath()) << '\n'; } @@ -291,7 +291,7 @@ bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex, 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(); diff --git a/src/insets/insetparent.C b/src/insets/insetparent.C index 56dcb26b51..7d79793ada 100644 --- a/src/insets/insetparent.C +++ b/src/insets/insetparent.C @@ -34,7 +34,7 @@ InsetParent::InsetParent(InsetCommandParams const & p, Buffer const & bf, bool) : InsetCommand(p) { string const fn = p.getContents(); - setContents(MakeAbsPath(fn, OnlyPath(bf.fileName()))); + setContents(MakeAbsPath(fn, bf.filePath())); } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 43cfb02da6..accc20cf9a 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -143,10 +143,8 @@ bool MenuWrite(BufferView * bv, Buffer * buffer) 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); } @@ -325,7 +323,7 @@ void AutoSave(BufferView * bv) 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 += "#"; @@ -420,7 +418,7 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) 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; diff --git a/src/lyx_main.C b/src/lyx_main.C index dae6699254..3b6e3a7ba6 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -245,14 +245,15 @@ void LyX::init(bool gui) 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; // @@ -286,30 +287,34 @@ void LyX::init(bool gui) searchpath += lyxdir + ';'; } - // /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; @@ -321,6 +326,20 @@ void LyX::init(bool gui) } } while (followlink); + // /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; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index cdccd0689f..b65a5e6472 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1508,7 +1508,7 @@ string const LyXFunc::dispatch(kb_action action, string argument) { string const filename = MakeAbsPath(argument, - OnlyPath(owner->buffer()->fileName())); + owner->buffer()->filePath()); setMessage(N_("Opening child document ") + MakeDisplayPath(filename) + "..."); owner->view()->savePosition(0); @@ -1647,7 +1647,7 @@ void LyXFunc::menuNew(bool fromTemplate) 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; @@ -1773,7 +1773,7 @@ void LyXFunc::open(string const & fname) 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; @@ -1850,7 +1850,7 @@ void LyXFunc::doImport(string const & argument) 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; diff --git a/src/vc-backend.C b/src/vc-backend.C index 794c81fc4a..c2d022344e 100644 --- a/src/vc-backend.C +++ b/src/vc-backend.C @@ -149,7 +149,7 @@ void RCS::registrer(string const & msg) cmd += "\" \""; cmd += OnlyFilename(owner_->fileName()); cmd += "\""; - doVCCommand(cmd, owner_->filepath); + doVCCommand(cmd, owner_->filePath()); owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD); } @@ -157,7 +157,7 @@ void RCS::registrer(string const & msg) 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); } @@ -166,7 +166,7 @@ void RCS::checkOut() { owner_->markLyxClean(); doVCCommand("co -q -l \"" - + OnlyFilename(owner_->fileName()) + "\"", owner_->filepath); + + OnlyFilename(owner_->fileName()) + "\"", owner_->filePath()); owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD); } @@ -174,7 +174,7 @@ void RCS::checkOut() 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() @@ -187,14 +187,14 @@ void RCS::undoLast() 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()); } @@ -279,7 +279,7 @@ void CVS::scanMaster() 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); } @@ -288,7 +288,7 @@ void CVS::checkIn(string const & msg) { doVCCommand("cvs -q commit -m \"" + msg + "\" \"" + OnlyFilename(owner_->fileName()) + "\"", - owner_->filepath); + owner_->filePath()); owner_->getUser()->owner()->getLyXFunc()->dispatch(LFUN_MENURELOAD); } @@ -307,7 +307,7 @@ void CVS::revert() 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); @@ -327,5 +327,5 @@ void CVS::getLog(string const & tmpf) { doVCCommand("cvs log \"" + OnlyFilename(owner_->fileName()) + "\" > " + tmpf, - owner_->filepath); + owner_->filePath()); } -- 2.39.2