]> git.lyx.org Git - features.git/commitdiff
Enable the graphics inset to work correctly with relative file names.
authorAngus Leeming <leeming@lyx.org>
Fri, 22 Mar 2002 16:37:52 +0000 (16:37 +0000)
committerAngus Leeming <leeming@lyx.org>
Fri, 22 Mar 2002 16:37:52 +0000 (16:37 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3816 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlGraphics.C
src/graphics/ChangeLog
src/graphics/GraphicsCache.C
src/graphics/GraphicsCache.h
src/graphics/GraphicsParams.C
src/graphics/GraphicsParams.h
src/insets/ChangeLog
src/insets/insetgraphics.C
src/insets/insetgraphics.h
src/insets/insetgraphicsParams.C
src/insets/insetgraphicsParams.h

index 8cb33a37b03f88fb432033dd9955e2b9e1d0aa26..14130ed3a1ffa976bcc2961e0e2b7501397a493a 100644 (file)
@@ -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  <larsbj@birdstep.com>
 
        * most files: ws cleanup
index b1de9231ad39bbedf71bc4f6dfd806e4603419c1..e5df87deb3806f495bfeb5e2c5e1e5fd4f7b27e1 100644 (file)
@@ -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);
index 0c63f7fcd980b37ba86651ab1f2ba37c0a7b9d52..39529bd9b546481856b4792b2bdfdc0e468d09cd 100644 (file)
@@ -1,3 +1,10 @@
+2002-03-22  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * 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  <larsbj@birdstep.com>
 
        * most files: ws cleanup
index 59b27d4dd11b87b3968a6aef31b491c0ce81c356..9e37111ec99d72084ceb80357c8c3985693dc8b7 100644 (file)
@@ -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
index 05d5320dd3b4383015276a819d7fc1c289dc7df6..dadec6c150d8ee54815dedf3ffab5d249e8e5a03 100644 (file)
@@ -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.
index 6353f7b51c0aaf736387b634f782dab2104e58a9..eeea38affce9bd114be31e587c4a3b304959a633 100644 (file)
 #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;
 
index 29761c7d5a04d09cca695d3c4e4040b94dc0ad36..1e949d52347efa86c98ede926c7312164293ee09 100644 (file)
@@ -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 {
index 0df2aa9414533f933b297c043a378454c6de1624..9a69b5a57e3563981520f882e80c8beb32dba95a 100644 (file)
@@ -1,5 +1,14 @@
 2002-03-22  Angus Leeming  <a.leeming@ic.ac.uk>
 
+       * 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.
 
index cbcbe2f0fcda1156c499bca7c5b9aeb2a6ae819d..a76c90baa6bc083d73eb2925212ba5226bec8ed5 100644 (file)
@@ -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<string> 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);
 }
index a45c9cbc6afe055661186360b7e68821668cafaa..78f6a73fa74391a65a6bca8a73768c654f251e60 100644 (file)
@@ -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.
index b398fbee8d7cb1fed3a8605a32e0e22f1f2df73a..da8f0b1d4d2bb2f11592d78400f177449b1c4ffc 100644 (file)
@@ -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();
index 021ed527e4c4b22b7cce9690e2e24b6f473f927f..8361eab369d739923ae8a23ccc9bc6e8755e74b9 100644 (file)
@@ -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.