From 4f9bed10185055d7aadaf4230c53a3f2f2d25442 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Fri, 22 Mar 2002 16:37:52 +0000 Subject: [PATCH] Enable the graphics inset to work correctly with relative file names. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3816 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 3 ++ src/frontends/controllers/ControlGraphics.C | 2 +- src/graphics/ChangeLog | 7 +++++ src/graphics/GraphicsCache.C | 4 +-- src/graphics/GraphicsCache.h | 2 +- src/graphics/GraphicsParams.C | 12 +++++-- src/graphics/GraphicsParams.h | 2 +- src/insets/ChangeLog | 9 ++++++ src/insets/insetgraphics.C | 35 +++++++++++---------- src/insets/insetgraphics.h | 12 ++++--- src/insets/insetgraphicsParams.C | 7 +---- src/insets/insetgraphicsParams.h | 2 +- 12 files changed, 60 insertions(+), 37 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 8cb33a37b0..14130ed3a1 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -6,6 +6,9 @@ * ControlGraphics.[Ch]: replace checkFilename with isFilenameValid. + * ControlGraphics.C (applyParamsToInset): pass filepath to + InsetGraphics::updateInset. + 2002-03-21 Lars Gullik Bjønnes * most files: ws cleanup diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index b1de9231ad..e5df87deb3 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -66,7 +66,7 @@ void ControlGraphics::applyParamsToInset() { // Set the parameters in the inset, it also returns true if the new // parameters are different from what was in the inset already. - bool changed = inset()->setParams(params()); + bool changed = inset()->setParams(params(), lv_.buffer()->filePath()); // Tell LyX we've got a change, and mark the document dirty, // if it changed. lv_.view()->updateInset(inset(), changed); diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 0c63f7fcd9..39529bd9b5 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,10 @@ +2002-03-22 Angus Leeming + + * GraphicsCache.[Ch] (update): now passed filepath to determine absolute + path to graphics file. + + * GraphicsParams.[Ch] (c-tor): now passed filepath. + 2002-03-21 Lars Gullik Bjønnes * most files: ws cleanup diff --git a/src/graphics/GraphicsCache.C b/src/graphics/GraphicsCache.C index 59b27d4dd1..9e37111ec9 100644 --- a/src/graphics/GraphicsCache.C +++ b/src/graphics/GraphicsCache.C @@ -50,12 +50,12 @@ GCache::~GCache() } -void GCache::update(InsetGraphics const & inset) +void GCache::update(InsetGraphics const & inset, string const & filepath) { // A subset only of InsetGraphicsParams is needed for display purposes. // The GraphicsParams c-tor also interrogates lyxrc to ascertain whether // to display or not. - GParams params(inset.params()); + GParams params(inset.params(), filepath); // Each inset can reference only one file, so check the cache for any // graphics files referenced by inset. If the name of this file is diff --git a/src/graphics/GraphicsCache.h b/src/graphics/GraphicsCache.h index 05d5320dd3..dadec6c150 100644 --- a/src/graphics/GraphicsCache.h +++ b/src/graphics/GraphicsCache.h @@ -42,7 +42,7 @@ public: ~GCache(); /// Add a file to the cache (or modify an existing image). - void update(InsetGraphics const &); + void update(InsetGraphics const &, string const & filepath); /** Remove the data associated with this inset. * Called from the InsetGraphics d-tor. diff --git a/src/graphics/GraphicsParams.C b/src/graphics/GraphicsParams.C index 6353f7b51c..eeea38affc 100644 --- a/src/graphics/GraphicsParams.C +++ b/src/graphics/GraphicsParams.C @@ -15,17 +15,23 @@ #include "GraphicsParams.h" #include "insets/insetgraphicsParams.h" #include "lyxrc.h" +#include "support/filetools.h" #include "support/lstrings.h" +#include "support/LAssert.h" namespace grfx { -GParams::GParams(InsetGraphicsParams const & iparams) - : filename(iparams.filename), - width(0), +GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath) + : width(0), height(0), scale(0), angle(0) { + filename = iparams.filename; + if (!filepath.empty()) { + filename = MakeAbsPath(filename, filepath); + } + if (iparams.clip) bb = iparams.bb; diff --git a/src/graphics/GraphicsParams.h b/src/graphics/GraphicsParams.h index 29761c7d5a..1e949d5234 100644 --- a/src/graphics/GraphicsParams.h +++ b/src/graphics/GraphicsParams.h @@ -49,7 +49,7 @@ bool operator!=(BoundingBox const &, BoundingBox const &); struct GParams { - GParams(InsetGraphicsParams const &); + GParams(InsetGraphicsParams const &, string const & = string()); /// How is the image to be displayed on the LyX screen? enum DisplayType { diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 0df2aa9414..9a69b5a57e 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,5 +1,14 @@ 2002-03-22 Angus Leeming + * insetgraphics.[Ch] (c-tor, setParams, updateInset): passed filepath. + Used to determine the absolute path to the graphics file in the + graphics cache and only in the graphics cache. + (readInsetGraphics, readFigInset) : no longer passed buffer. Do not + make graphics file name absolute if it is stored as a relative path. + + * insetgraphicsParams.[Ch] (Read): no longer passed buffer. Do not + make graphics file name absolute if it is stored as a relative path. + * insettext.C (edit): emit an updateParagraph signal on entering a text inset. Needs to be emitted when leaving the inset also. diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index cbcbe2f0fc..a76c90baa6 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -147,13 +147,15 @@ InsetGraphics::InsetGraphics() {} -InsetGraphics::InsetGraphics(InsetGraphics const & ig, bool same_id) +InsetGraphics::InsetGraphics(InsetGraphics const & ig, + string const & filepath, + bool same_id) : Inset(ig, same_id), SigC::Object(), graphic_label(unique_id()), cached_status_(grfx::ErrorUnknown), cache_filled_(false), old_asc(0) { - setParams(ig.params()); + setParams(ig.params(), filepath); } @@ -355,10 +357,10 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, // Update the inset after parameters changed (read from file or changed in // dialog. The grfx::GCache makes the decisions about whether or not to draw // (interogates lyxrc, ascertains whether file exists etc) -void InsetGraphics::updateInset() const +void InsetGraphics::updateInset(string const & filepath) const { grfx::GCache & gc = grfx::GCache::get(); - gc.update(*this); + gc.update(*this, filepath); } @@ -392,16 +394,16 @@ void InsetGraphics::read(Buffer const * buf, LyXLex & lex) string const token = lex.getString(); if (token == "Graphics") - readInsetGraphics(buf, lex); + readInsetGraphics(lex); else if (token == "Figure") // Compatibility reading of FigInset figures. - readFigInset(buf, lex); + readFigInset(lex); else lyxerr[Debug::GRAPHICS] << "Not a Graphics or Figure inset!\n"; - updateInset(); + updateInset(buf->filePath()); } -void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) +void InsetGraphics::readInsetGraphics(LyXLex & lex) { bool finished = false; @@ -428,7 +430,7 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) // TODO: Possibly open up a dialog? } else { - if (! params_.Read(buf, lex, token)) + if (! params_.Read(lex, token)) lyxerr << "Unknown token, " << token << ", skipping." << std::endl; } @@ -436,7 +438,7 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) } // FormatVersion < 1.0 (LyX < 1.2) -void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) +void InsetGraphics::readFigInset(LyXLex & lex) { std::vector const oldUnits = getVectorFromString("pt,cm,in,p%,c%"); @@ -462,9 +464,7 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) finished = true; } else if (token == "file") { if (lex.next()) { - string const name = lex.getString(); - string const path = buf->filePath(); - params_.filename = MakeAbsPath(name, path); + params_.filename = lex.getString(); } } else if (token == "extra") { if (lex.next()); @@ -730,7 +730,8 @@ void InsetGraphics::validate(LaTeXFeatures & features) const } -bool InsetGraphics::setParams(InsetGraphicsParams const & p) +bool InsetGraphics::setParams(InsetGraphicsParams const & p, + string const & filepath) { // If nothing is changed, just return and say so. if (params() == p && !p.filename.empty()) { @@ -741,7 +742,7 @@ bool InsetGraphics::setParams(InsetGraphicsParams const & p) params_ = p; // Update the inset with the new parameters. - updateInset(); + updateInset(filepath); // We have changed data, report it. return true; @@ -754,7 +755,7 @@ InsetGraphicsParams const & InsetGraphics::params() const } -Inset * InsetGraphics::clone(Buffer const &, bool same_id) const +Inset * InsetGraphics::clone(Buffer const & buffer, bool same_id) const { - return new InsetGraphics(*this, same_id); + return new InsetGraphics(*this, buffer.filePath(), same_id); } diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index a45c9cbc6a..78f6a73fa7 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -34,7 +34,8 @@ public: /// InsetGraphics(); /// - InsetGraphics(InsetGraphics const &, bool same_id = false); + InsetGraphics(InsetGraphics const &, string const & filepath, + bool same_id = false); /// ~InsetGraphics(); /// @@ -83,7 +84,8 @@ public: /** Set the inset parameters, used by the GUIndependent dialog. Return true of new params are different from what was so far. */ - bool setParams(InsetGraphicsParams const & params); + bool setParams(InsetGraphicsParams const & params, + string const & filepath); /// Get the inset parameters, used by the GUIndependent dialog. InsetGraphicsParams const & params() const; @@ -100,12 +102,12 @@ private: bool drawImage() const; /// Read the inset native format - void readInsetGraphics(Buffer const * buf, LyXLex & lex); + void readInsetGraphics(LyXLex & lex); /// Read the FigInset file format - void readFigInset(Buffer const * buf, LyXLex & lex); + void readFigInset(LyXLex & lex); /// Update the inset after parameter change. - void updateInset() const; + void updateInset(string const & filepath) const; /// Get the status message, depends on the image loading status. string const statusMessage() const; /// Create the options for the latex command. diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index b398fbee8d..da8f0b1d4d 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -237,16 +237,11 @@ void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const } -bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex, - string const& token) +bool InsetGraphicsParams::Read(LyXLex & lex, string const& token) { if (token == "filename") { lex.next(); filename = lex.getString(); - if (!filename.empty()) { - // Make the filename with absolute directory. - filename = MakeAbsPath(filename, buf->filePath()); - } } else if (token == "BoundingBox") { for (int i=0; i<4 ;i++) { lex.next(); diff --git a/src/insets/insetgraphicsParams.h b/src/insets/insetgraphicsParams.h index 021ed527e4..8361eab369 100644 --- a/src/insets/insetgraphicsParams.h +++ b/src/insets/insetgraphicsParams.h @@ -90,7 +90,7 @@ struct InsetGraphicsParams /// Save the parameters in the LyX format stream. void Write(Buffer const * buf, std::ostream & os) const; /// If the token belongs to our parameters, read it. - bool Read(Buffer const * buf, LyXLex & lex, string const & token); + bool Read(LyXLex & lex, string const & token); private: /// Initialize the object to a default status.