Angus Leeming wrote:
> Comments please.
Might help if you had the patch...
--
Angus
Index: src/support/filetools.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.h,v
retrieving revision 1.47
diff -u -p -r1.47 filetools.h
--- src/support/filetools.h 30 Jun 2003 23:56:22 -0000 1.47
+++ src/support/filetools.h 21 Jul 2003 10:40:26 -0000
@@ -223,6 +223,32 @@ typedef std::pair<int, string> cmd_ret;
cmd_ret const RunCommand(string const & cmd);
+class FileName {
+public:
+ FileName();
+ /** \param abs_filename the name of the path with full path.
+ \param save_abs_path should the file name be stored in the
+ LyX file as an absolute path or relative to the buffer?
+ */
+ FileName(string const & abs_filename, bool save_abs_path = true);
+
+ bool empty() const { return name_.empty(); }
+
+ string const absFilename() const { return name_; }
+ void absFilename(string const abs_filename);
+
+ bool saveAbsPath() const { return save_abs_path_; }
+ void saveAbsPath(bool);
+private:
+ string name_;
+ bool save_abs_path_;
+};
+
+
+bool operator==(FileName const &, FileName const &);
+bool operator!=(FileName const &, FileName const &);
+
+
} // namespace support
} // namespace lyx
Index: src/support/filetools.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/filetools.C,v
retrieving revision 1.159
diff -u -p -r1.159 filetools.C
--- src/support/filetools.C 30 Jun 2003 23:56:22 -0000 1.159
+++ src/support/filetools.C 21 Jul 2003 10:40:26 -0000
@@ -1374,5 +1374,45 @@ string const copyFileToDir(string const
return success ? file_out : string();
}
+
+FileName::FileName()
+ : save_abs_path_(true)
+{}
+
+
+FileName::FileName(string const & abs_filename, bool save_abs_path)
+ : name_(abs_filename), save_abs_path_(save_abs_path)
+{
+ if (!abs_filename.empty())
+ Assert(AbsolutePath(abs_filename));
+}
+
+
+void FileName::absFilename(string const abs_filename)
+{
+ if (!abs_filename.empty())
+ Assert(AbsolutePath(abs_filename));
+ name_ = abs_filename;
+}
+
+
+void FileName::saveAbsPath(bool sap)
+{
+ save_abs_path_ = sap;
+}
+
+
+bool operator==(FileName const & lhs, FileName const & rhs)
+{
+ return lhs.absFilename() == rhs.absFilename() &&
+ lhs.saveAbsPath() == rhs.saveAbsPath();
+}
+
+
+bool operator!=(FileName const & lhs, FileName const & rhs)
+{
+ return !(lhs == rhs);
+}
+
} //namespace support
} // namespace lyx
Index: src/insets/insetgraphicsParams.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphicsParams.h,v
retrieving revision 1.33
diff -u -p -r1.33 insetgraphicsParams.h
--- src/insets/insetgraphicsParams.h 4 Jul 2003 08:23:21 -0000 1.33
+++ src/insets/insetgraphicsParams.h 21 Jul 2003 10:40:24 -0000
@@ -17,6 +17,7 @@
#include "graphics/GraphicsTypes.h"
#include "LString.h"
#include "lyxlength.h"
+#include "support/filetools.h"
namespace grfx = lyx::graphics;
@@ -33,7 +34,7 @@ namespace graphics {
struct InsetGraphicsParams
{
/// Image filename.
- string filename;
+ lyx::support::FileName filename;
/// Scaling the Screen inside Lyx
unsigned int lyxscale;
/// How to display the image inside LyX
Index: src/insets/insetgraphicsParams.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphicsParams.C,v
retrieving revision 1.60
diff -u -p -r1.60 insetgraphicsParams.C
--- src/insets/insetgraphicsParams.C 30 Jun 2003 23:56:18 -0000 1.60
+++ src/insets/insetgraphicsParams.C 21 Jul 2003 10:40:24 -0000
@@ -59,7 +59,7 @@ InsetGraphicsParams::operator=(InsetGrap
void InsetGraphicsParams::init()
{
- filename.erase();
+ filename.absFilename(string());
lyxscale = 100; // lyx scaling in percentage
display = grfx::DefaultDisplay; // display mode; see preferences
scale = 100.0; // output scaling in percentage
@@ -144,7 +144,10 @@ void InsetGraphicsParams::Write(ostream
// Do not write the default values
if (!filename.empty()) {
- os << "\tfilename " << MakeRelPath(filename, bufpath) << '\n';
+ string const name = filename.saveAbsPath() ?
+ filename.absFilename() :
+ MakeRelPath(filename.absFilename(), bufpath);
+ os << "\tfilename " << name << '\n';
}
if (lyxscale != 100)
os << "\tlyxscale " << lyxscale << '\n';
@@ -189,7 +192,11 @@ bool InsetGraphicsParams::Read(LyXLex &
{
if (token == "filename") {
lex.eatLine();
- filename = MakeAbsPath(lex.getString(), bufpath);
+ string name = lex.getString();
+ filename.saveAbsPath(AbsolutePath(name));
+ if (!filename.saveAbsPath())
+ name = MakeAbsPath(name, bufpath);
+ filename.absFilename(name);
} else if (token == "lyxscale") {
lex.next();
lyxscale = lex.getInteger();
@@ -259,7 +266,7 @@ bool InsetGraphicsParams::Read(LyXLex &
grfx::Params InsetGraphicsParams::as_grfxParams() const
{
grfx::Params pars;
- pars.filename = filename;
+ pars.filename = filename.absFilename();
pars.scale = lyxscale;
pars.angle = rotateAngle;
@@ -267,7 +274,7 @@ grfx::Params InsetGraphicsParams::as_grf
pars.bb = bb;
// Get the original Bounding Box from the file
- string const tmp = readBB_from_PSFile(filename);
+ string const tmp = readBB_from_PSFile(filename.absFilename());
lyxerr[Debug::GRAPHICS] << "BB_from_File: " << tmp << std::endl;
if (!tmp.empty()) {
unsigned int const bb_orig_xl = strToInt(token(tmp, ' ', 0));
Index: src/insets/insetgraphics.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.h,v
retrieving revision 1.74
diff -u -p -r1.74 insetgraphics.h
--- src/insets/insetgraphics.h 16 Jun 2003 11:49:31 -0000 1.74
+++ src/insets/insetgraphics.h 21 Jul 2003 10:40:24 -0000
@@ -78,6 +78,7 @@ public:
/// Get the inset parameters, used by the GUIndependent dialog.
InsetGraphicsParams const & params() const;
+ virtual BufferView * view() const;
private:
///
friend class InsetGraphicsMailer;
@@ -121,9 +122,11 @@ public:
///
virtual string const inset2string() const;
///
- static void string2params(string const &, InsetGraphicsParams &);
+ static void string2params(string const &, string const & buffer_path,
+ InsetGraphicsParams &);
///
- static string const params2string(InsetGraphicsParams const &);
+ static string const params2string(InsetGraphicsParams const &,
+ string const & buffer_path);
private:
///
static string const name_;
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.187
diff -u -p -r1.187 insetgraphics.C
--- src/insets/insetgraphics.C 18 Jul 2003 07:47:05 -0000 1.187
+++ src/insets/insetgraphics.C 21 Jul 2003 10:40:24 -0000
@@ -177,8 +177,9 @@ dispatch_result InsetGraphics::localDisp
{
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
+ string const bufpath = cmd.view()->buffer()->filePath();
InsetGraphicsParams p;
- InsetGraphicsMailer::string2params(cmd.argument, p);
+ InsetGraphicsMailer::string2params(cmd.argument, bufpath, p);
if (!p.filename.empty()) {
setParams(p);
cmd.view()->updateInset(this);
@@ -330,7 +331,7 @@ string const InsetGraphics::prepareFile(
{
// LaTeX can cope if the graphics file doesn't exist, so just return the
// filename.
- string orig_file = params().filename;
+ string orig_file = params().filename.absFilename();
string const rel_file = MakeRelPath(orig_file, buf->filePath());
if (!IsFileReadable(orig_file)) {
@@ -465,14 +466,16 @@ int InsetGraphics::latex(Buffer const *
// just output a message about it in the latex output.
lyxerr[Debug::GRAPHICS]
<< "insetgraphics::latex: Filename = "
- << params().filename << endl;
+ << params().filename.absFilename() << endl;
- string const relative_file = MakeRelPath(params().filename, buf->filePath());
+ string const relative_file =
+ MakeRelPath(params().filename.absFilename(),
+ buf->filePath());
// A missing (e)ps-extension is no problem for LaTeX, so
// we have to test three different cases
#warning uh, but can our cache handle it ? no.
- string const file_ = params().filename;
+ string const file_ = params().filename.absFilename();
bool const file_exists =
!file_.empty() &&
(IsFileReadable(file_) || // original
@@ -542,7 +545,8 @@ int InsetGraphics::ascii(Buffer const *,
// 1. Convert file to ascii using gifscii
// 2. Read ascii output file and add it to the output stream.
// at least we send the filename
- os << '<' << bformat(_("Graphics file: %1$s"), params().filename) << ">\n";
+ os << '<' << bformat(_("Graphics file: %1$s"),
+ params().filename.absFilename()) << ">\n";
return 0;
}
@@ -574,7 +578,8 @@ void InsetGraphics::validate(LaTeXFeatur
if (params().filename.empty())
return;
- features.includeFile(graphic_label, RemoveExtension(params().filename));
+ features.includeFile(graphic_label,
+ RemoveExtension(params().filename.absFilename()));
features.require("graphicx");
@@ -606,6 +611,12 @@ InsetGraphicsParams const & InsetGraphic
}
+BufferView * InsetGraphics::view() const
+{
+ return graphic_->view();
+}
+
+
string const InsetGraphicsMailer::name_("graphics");
InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
@@ -615,11 +626,15 @@ InsetGraphicsMailer::InsetGraphicsMailer
string const InsetGraphicsMailer::inset2string() const
{
- return params2string(inset_.params());
+ BufferView * bv = inset_.view();
+ if (bv)
+ return params2string(inset_.params(), bv->buffer()->filePath());
+ return string();
}
void InsetGraphicsMailer::string2params(string const & in,
+ string const & buffer_path,
InsetGraphicsParams & params)
{
params = InsetGraphicsParams();
@@ -640,20 +655,19 @@ void InsetGraphicsMailer::string2params(
if (lex.isOK()) {
InsetGraphics inset;
-#warning FIXME not setting bufpath is dubious
- inset.readInsetGraphics(lex, string());
+ inset.readInsetGraphics(lex, buffer_path);
params = inset.params();
}
}
string const
-InsetGraphicsMailer::params2string(InsetGraphicsParams const & params)
+InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
+ string const & buffer_path)
{
ostringstream data;
data << name_ << ' ';
-#warning FIXME not setting bufpath is dubious
- params.Write(data, string());
+ params.Write(data, buffer_path);
data << "\\end_inset\n";
return STRCONV(data.str());
}
Index: src/factory.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/factory.C,v
retrieving revision 1.35
diff -u -p -r1.35 factory.C
--- src/factory.C 8 Jul 2003 14:19:24 -0000 1.35
+++ src/factory.C 21 Jul 2003 10:40:21 -0000
@@ -206,8 +206,10 @@ Inset * createInset(FuncRequest const &
return inset;
} else if (name == "graphics") {
+ string const fpath = cmd.view()->buffer()->filePath();
InsetGraphicsParams igp;
- InsetGraphicsMailer::string2params(cmd.argument, igp);
+ InsetGraphicsMailer::string2params(cmd.argument, fpath,
+ igp);
InsetGraphics * inset = new InsetGraphics;
inset->setParams(igp);
return inset;
Index: src/frontends/controllers/ControlGraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlGraphics.C,v
retrieving revision 1.66
diff -u -p -r1.66 ControlGraphics.C
--- src/frontends/controllers/ControlGraphics.C 18 Jul 2003 08:45:59 -0000 1.66
+++ src/frontends/controllers/ControlGraphics.C 21 Jul 2003 10:40:21 -0000
@@ -50,12 +50,10 @@ ControlGraphics::ControlGraphics(Dialog
bool ControlGraphics::initialiseParams(string const & data)
{
+ string const bufpath = kernel().buffer()->filePath();
InsetGraphicsParams params;
- InsetGraphicsMailer::string2params(data, params);
+ InsetGraphicsMailer::string2params(data, bufpath, params);
params_.reset(new InsetGraphicsParams(params));
- // make relative for good UI
- params_->filename = MakeRelPath(params_->filename,
- kernel().buffer()->filePath());
return true;
}
@@ -68,11 +66,10 @@ void ControlGraphics::clearParams()
void ControlGraphics::dispatchParams()
{
+ string const buffer_path = kernel().buffer()->filePath();
InsetGraphicsParams tmp_params(params());
- // core requires absolute path during runtime
- tmp_params.filename = MakeAbsPath(tmp_params.filename,
- kernel().buffer()->filePath());
- string const lfun = InsetGraphicsMailer::params2string(tmp_params);
+ string const lfun =
+ InsetGraphicsMailer::params2string(tmp_params, buffer_path);
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
}
Index: src/frontends/xforms/FormGraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormGraphics.C,v
retrieving revision 1.110
diff -u -p -r1.110 FormGraphics.C
--- src/frontends/xforms/FormGraphics.C 30 Jun 2003 23:56:13 -0000 1.110
+++ src/frontends/xforms/FormGraphics.C 21 Jul 2003 10:40:23 -0000
@@ -22,6 +22,7 @@
#include "Tooltips.h"
#include "xforms_helpers.h"
+#include "buffer.h"
#include "debug.h" // for lyxerr
#include "lyxrc.h" // for lyxrc.display_graphics
@@ -292,7 +293,14 @@ void FormGraphics::apply()
InsetGraphicsParams & igp = controller().params();
// the file section
- igp.filename = getString(file_->input_filename);
+ string name = getString(file_->input_filename);
+ igp.filename.saveAbsPath(AbsolutePath(name));
+ if (igp.filename.saveAbsPath())
+ igp.filename.absFilename(name);
+ else {
+ name = MakeAbsPath(name, kernel().buffer()->filePath());
+ igp.filename.absFilename(name);
+ }
igp.lyxscale = strToInt(getString(file_->input_lyxscale));
if (igp.lyxscale == 0) {
@@ -424,7 +432,11 @@ void FormGraphics::update() {
InsetGraphicsParams & igp = controller().params();
// the file section
- fl_set_input(file_->input_filename, igp.filename.c_str());
+ string const name = igp.filename.saveAbsPath() ?
+ igp.filename.absFilename() :
+ MakeRelPath(igp.filename.absFilename(),
+ kernel().buffer()->filePath());
+ fl_set_input(file_->input_filename, name.c_str());
fl_set_input(file_->input_lyxscale, tostr(igp.lyxscale).c_str());
switch (igp.display) {
@@ -479,7 +491,7 @@ void FormGraphics::update() {
// the bb section
// set the bounding box values, if exists. First we need the whole
// path, because the controller knows nothing about the doc-dir
- updateBB(igp.filename, igp.bb);
+ updateBB(igp.filename.absFilename(), igp.bb);
fl_set_button(bbox_->check_clip, igp.clip);
// the extra section