]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetgraphicsParams.C
Enable the external inset to handle unknown templates gracefully.
[lyx.git] / src / insets / insetgraphicsParams.C
index 7ce47109746e7260af1b7fca0c55dafe30fdc613..3f6a1b395ba4595c257dfddfbcce99565e96f5bf 100644 (file)
 #include "lyxrc.h"
 #include "debug.h"
 #include "lyxlex.h"
+#include "frontends/lyx_gui.h"
 
 using std::ostream;
 
+
 InsetGraphicsParams::InsetGraphicsParams()
 {
        init();
 }
 
+
 InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp)
 {
        // I decided to skip the initialization since the copy will overwrite
@@ -40,16 +43,18 @@ InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp)
        copy(igp);
 }
 
+
 InsetGraphicsParams &
 InsetGraphicsParams::operator=(InsetGraphicsParams const & params)
 {
        // Are we assigning the object into itself?
        if (this == &params)
-               return * this;
+               return *this;
        copy(params);
        return *this;
 }
 
+
 void InsetGraphicsParams::init()
 {
        filename.erase();
@@ -72,6 +77,7 @@ void InsetGraphicsParams::init()
        special.erase();                // additional userdefined stuff
 }
 
+
 void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
 {
        filename = igp.filename;
@@ -94,6 +100,7 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
        special = igp.special;
 }
 
+
 bool operator==(InsetGraphicsParams const & left,
                InsetGraphicsParams const & right)
 {
@@ -122,18 +129,20 @@ bool operator==(InsetGraphicsParams const & left,
        return false;
 }
 
+
 bool operator!=(InsetGraphicsParams const & left,
                InsetGraphicsParams const & right)
 {
        return  !(left == right);
 }
 
-void InsetGraphicsParams::Write(ostream & os) const
+
+void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
 {
        // Do not write the default values
 
        if (!filename.empty()) {
-               os << "\tfilename " << filename << '\n';
+               os << "\tfilename " << MakeRelPath(filename, bufpath) << '\n';
        }
        if (lyxscale != 100)
                os << "\tlyxscale " << lyxscale << '\n';
@@ -174,11 +183,11 @@ void InsetGraphicsParams::Write(ostream & os) const
 }
 
 
-bool InsetGraphicsParams::Read(LyXLex & lex, string const & token)
+bool InsetGraphicsParams::Read(LyXLex & lex, string const & token, string const & bufpath)
 {
        if (token == "filename") {
                lex.eatLine();
-               filename = lex.getString();
+               filename = MakeAbsPath(lex.getString(), bufpath);
        } else if (token == "lyxscale") {
                lex.next();
                lyxscale = lex.getInteger();
@@ -245,16 +254,13 @@ bool InsetGraphicsParams::Read(LyXLex & lex, string const & token)
 }
 
 
-grfx::Params InsetGraphicsParams::as_grfxParams(string const & filepath) const
+grfx::Params InsetGraphicsParams::as_grfxParams() const
 {
        grfx::Params pars;
        pars.filename = filename;
        pars.scale = lyxscale;
        pars.angle = rotateAngle;
 
-       if (!filepath.empty())
-               pars.filename = MakeAbsPath(pars.filename, filepath);
-
        if (clip) {
                pars.bb = bb;
 
@@ -306,7 +312,7 @@ grfx::Params InsetGraphicsParams::as_grfxParams(string const & filepath) const
        }
 
        // Override the above if we're not using a gui
-       if (!lyxrc.use_gui) {
+       if (!lyx_gui::use_gui) {
                pars.display = grfx::NoDisplay;
        }