Lars Gullik Bjønnes wrote:
> John Levon <[EMAIL PROTECTED]> writes:
>
> | On Mon, Jul 21, 2003 at 06:21:17PM +0200, Lars Gullik Bj?nnes wrote:
> |
> | > boost::filesystem.
> |
> | You were against replacing our stuff with that last time I asked about
> | it.
> |
> | Besides, that's an absolutely massive patch (and I am strongly against
> | only using bits of boost::filesystem and bits of our support/ stuff)
>
> boost::filesystem has some facility to hve a "path" and you can draw
> absolute or relative out of this as you need...
>
> And I think you should have a look yourself, not just me.
I will definitely have a look in that case, but I still prefer a
slowly-slowly approach. Attached is the cleaned-up proposal for a FileName
class. I'll try and apply this tomorrow evening unless you _really_ object.
--
Angus
Index: src/frontends/controllers/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ChangeLog,v
retrieving revision 1.352
diff -u -p -r1.352 ChangeLog
--- src/frontends/controllers/ChangeLog 21 Jul 2003 21:51:17 -0000 1.352
+++ src/frontends/controllers/ChangeLog 21 Jul 2003 22:15:45 -0000
@@ -1,5 +1,10 @@
2003-07-21 Angus Leeming <[EMAIL PROTECTED]>
+ * ControlGraphics.C (initialiseParams, dispatchParams): no need
+ to modify the filename for reasons of 'good UI' anymore.
+
+2003-07-21 Angus Leeming <[EMAIL PROTECTED]>
+
* ControlGraphics.C (initialiseParams, dispatchParams): pass a
buffer_path parameter to InsetGraphicsMailer's string2params,
params2string.
Index: src/frontends/controllers/ControlGraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlGraphics.C,v
retrieving revision 1.68
diff -u -p -r1.68 ControlGraphics.C
--- src/frontends/controllers/ControlGraphics.C 21 Jul 2003 21:51:17 -0000 1.68
+++ src/frontends/controllers/ControlGraphics.C 21 Jul 2003 22:15:45 -0000
@@ -54,8 +54,6 @@ bool ControlGraphics::initialiseParams(s
InsetGraphicsParams params;
InsetGraphicsMailer::string2params(data, bufpath, params);
params_.reset(new InsetGraphicsParams(params));
- // make relative for good UI
- params_->filename = MakeRelPath(params_->filename, bufpath);
return true;
}
@@ -70,8 +68,6 @@ 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, buffer_path);
string const lfun =
InsetGraphicsMailer::params2string(tmp_params, buffer_path);
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
Index: src/frontends/qt2/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/ChangeLog,v
retrieving revision 1.549
diff -u -p -r1.549 ChangeLog
--- src/frontends/qt2/ChangeLog 21 Jul 2003 21:30:54 -0000 1.549
+++ src/frontends/qt2/ChangeLog 21 Jul 2003 22:15:49 -0000
@@ -1,5 +1,11 @@
2003-07-21 Angus Leeming <[EMAIL PROTECTED]>
+ * QGraphics.C (apply, update_contents):
+ changes due to the use of the FileName class to store the graphics
+ file name.
+
+2003-07-21 Angus Leeming <[EMAIL PROTECTED]>
+
* QExternal.C (update_contents, apply):
* QGraphics.C (update_contents, apply):
* QLPainter.C (image):
Index: src/frontends/qt2/QGraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QGraphics.C,v
retrieving revision 1.31
diff -u -p -r1.31 QGraphics.C
--- src/frontends/qt2/QGraphics.C 21 Jul 2003 21:30:55 -0000 1.31
+++ src/frontends/qt2/QGraphics.C 21 Jul 2003 22:15:49 -0000
@@ -21,6 +21,7 @@
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "insets/insetgraphicsParams.h"
+#include "buffer.h"
#include "lyxrc.h"
#include "lengthcombo.h"
#include "qt_helpers.h"
@@ -159,11 +160,13 @@ void QGraphics::update_contents()
break;
}
- dialog_->filename->setText(toqstr(igp.filename));
+ string const name =
+ igp.filename.outputFilename(kernel().buffer()->filePath());
+ dialog_->filename->setText(toqstr(name));
// set the bounding box values
if (igp.bb.empty()) {
- string const bb = controller().readBB(igp.filename);
+ string const bb = controller().readBB(igp.filename.absFilename());
// the values from the file always have the bigpoint-unit bp
dialog_->lbX->setText(toqstr(token(bb, ' ', 0)));
dialog_->lbY->setText(toqstr(token(bb, ' ', 1)));
@@ -299,7 +302,8 @@ void QGraphics::apply()
{
InsetGraphicsParams & igp = controller().params();
- igp.filename = fromqstr(dialog_->filename->text());
+ igp.filename.set(fromqstr(dialog_->filename->text()),
+ kernel().buffer()->filePath());
// the bb section
igp.bb.erase();
Index: src/frontends/xforms/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v
retrieving revision 1.782
diff -u -p -r1.782 ChangeLog
--- src/frontends/xforms/ChangeLog 21 Jul 2003 21:30:55 -0000 1.782
+++ src/frontends/xforms/ChangeLog 21 Jul 2003 22:15:56 -0000
@@ -1,5 +1,11 @@
2003-07-21 Angus Leeming <[EMAIL PROTECTED]>
+ * FormGraphics.C (apply, update):
+ changes due to the use of the FileName class to store the graphics
+ file name.
+
+2003-07-21 Angus Leeming <[EMAIL PROTECTED]>
+
* FormExternal.C (update, apply):
* FormGraphics.C (update, apply):
* FormPrefences.C (LnFmisc::update, LnFmisc::apply):
Index: src/frontends/xforms/FormGraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormGraphics.C,v
retrieving revision 1.111
diff -u -p -r1.111 FormGraphics.C
--- src/frontends/xforms/FormGraphics.C 21 Jul 2003 21:30:55 -0000 1.111
+++ src/frontends/xforms/FormGraphics.C 21 Jul 2003 22:15:56 -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,8 @@ void FormGraphics::apply()
InsetGraphicsParams & igp = controller().params();
// the file section
- igp.filename = getString(file_->input_filename);
+ igp.filename.set(getString(file_->input_filename),
+ kernel().buffer()->filePath());
igp.lyxscale = strToInt(getString(file_->input_lyxscale));
if (igp.lyxscale == 0) {
@@ -424,7 +426,9 @@ 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.outputFilename(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 +483,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
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.750
diff -u -p -r1.750 ChangeLog
--- src/insets/ChangeLog 21 Jul 2003 21:51:17 -0000 1.750
+++ src/insets/ChangeLog 21 Jul 2003 22:16:02 -0000
@@ -1,5 +1,13 @@
2003-07-21 Angus Leeming <[EMAIL PROTECTED]>
+ * insetgraphicsParams.[Ch]: store the graphics file name in
+ a FileName member variable rather than a string.
+
+ * insetgraphics.[Ch]:
+ * insetgraphicsParams.[Ch]: Associated changes.
+
+2003-07-21 Angus Leeming <[EMAIL PROTECTED]>
+
* insetgraphics.[Ch] (string2params, params2string): passed a
buffer_path argument.
(view): new method.
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.188
diff -u -p -r1.188 insetgraphics.C
--- src/insets/insetgraphics.C 21 Jul 2003 21:51:17 -0000 1.188
+++ src/insets/insetgraphics.C 21 Jul 2003 22:16:03 -0000
@@ -331,8 +331,8 @@ 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 const rel_file = MakeRelPath(orig_file, buf->filePath());
+ string orig_file = params().filename.absFilename();
+ string const rel_file = params().filename.relFilename(buf->filePath());
if (!IsFileReadable(orig_file)) {
lyxerr[Debug::GRAPHICS]
@@ -466,14 +466,15 @@ 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 =
+ params().filename.relFilename(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
@@ -543,7 +544,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;
}
@@ -575,7 +577,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");
Index: src/insets/insetgraphicsParams.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphicsParams.C,v
retrieving revision 1.61
diff -u -p -r1.61 insetgraphicsParams.C
--- src/insets/insetgraphicsParams.C 21 Jul 2003 21:30:56 -0000 1.61
+++ src/insets/insetgraphicsParams.C 21 Jul 2003 22:16:03 -0000
@@ -144,7 +144,7 @@ void InsetGraphicsParams::Write(ostream
// Do not write the default values
if (!filename.empty()) {
- os << "\tfilename " << MakeRelPath(filename, bufpath) << '\n';
+ os << "\tfilename " << filename.outputFilename(bufpath) << '\n';
}
if (lyxscale != 100)
os << "\tlyxscale " << lyxscale << '\n';
@@ -189,7 +189,7 @@ bool InsetGraphicsParams::Read(LyXLex &
{
if (token == "filename") {
lex.eatLine();
- filename = MakeAbsPath(lex.getString(), bufpath);
+ filename.set(lex.getString(), bufpath);
} else if (token == "lyxscale") {
lex.next();
lyxscale = lex.getInteger();
@@ -259,7 +259,7 @@ bool InsetGraphicsParams::Read(LyXLex &
lyx::graphics::Params InsetGraphicsParams::as_grfxParams() const
{
lyx::graphics::Params pars;
- pars.filename = filename;
+ pars.filename = filename.absFilename();
pars.scale = lyxscale;
pars.angle = rotateAngle;
@@ -267,7 +267,7 @@ lyx::graphics::Params InsetGraphicsParam
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/insetgraphicsParams.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphicsParams.h,v
retrieving revision 1.34
diff -u -p -r1.34 insetgraphicsParams.h
--- src/insets/insetgraphicsParams.h 21 Jul 2003 21:30:56 -0000 1.34
+++ src/insets/insetgraphicsParams.h 21 Jul 2003 22:16:03 -0000
@@ -17,6 +17,7 @@
#include "graphics/GraphicsTypes.h"
#include "LString.h"
#include "lyxlength.h"
+#include "support/filename.h"
class LyXLex;
@@ -31,7 +32,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/support/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/support/Makefile.am,v
retrieving revision 1.57
diff -u -p -r1.57 Makefile.am
--- src/support/Makefile.am 13 May 2003 14:36:24 -0000 1.57
+++ src/support/Makefile.am 21 Jul 2003 22:16:04 -0000
@@ -30,6 +30,8 @@ libsupport_la_SOURCES = \
boost-inst.C \
chdir.C \
copy.C \
+ filename.C \
+ filename.h \
filetools.C \
filetools.h \
forkedcall.C \
Index: src/support/filename.C
===================================================================
RCS file: src/support/filename.C
diff -N src/support/filename.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/support/filename.C 21 Jul 2003 22:16:04 -0000
@@ -0,0 +1,65 @@
+/**
+ * \file filename.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ */
+
+#include <config.h>
+
+#include "filename.h"
+#include "support/filetools.h"
+
+
+namespace lyx {
+namespace support {
+
+
+FileName::FileName()
+ : save_abs_path_(true)
+{}
+
+
+void FileName::set(string const & name, string const & buffer_path)
+{
+ save_abs_path_ = AbsolutePath(name);
+ name_ = save_abs_path_ ? name : MakeAbsPath(name, buffer_path);
+}
+
+
+void FileName::erase()
+{
+ name_.erase();
+}
+
+
+string const FileName::relFilename(string const & path) const
+{
+ return MakeRelPath(name_, path);
+}
+
+
+string const FileName::outputFilename(string const & buffer_path) const
+{
+ return save_abs_path_ ? name_ : MakeRelPath(name_, buffer_path);
+}
+
+
+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/support/filename.h
===================================================================
RCS file: src/support/filename.h
diff -N src/support/filename.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/support/filename.h 21 Jul 2003 22:16:04 -0000
@@ -0,0 +1,54 @@
+// -*- C++-*-
+/**
+ * \file filename.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef FILENAME_H
+#define FILENAME_H
+
+#include "LString.h"
+
+
+namespace lyx {
+namespace support {
+
+
+class FileName {
+public:
+ FileName();
+
+ /** \param filename the file in question. May have either a relative
+ or an absolute path.
+ \param buffer_path if \c filename has a relative path, generate
+ the absolute path using this.
+ */
+ void set(string const & filename, string const & buffer_path);
+
+ void erase();
+ bool empty() const { return name_.empty(); }
+
+ bool saveAbsPath() const { return save_abs_path_; }
+ string const absFilename() const { return name_; }
+ string const relFilename(string const & buffer_path) const;
+ string const outputFilename(string const & buffer_path) const;
+
+private:
+ string name_;
+ bool save_abs_path_;
+};
+
+
+bool operator==(FileName const &, FileName const &);
+bool operator!=(FileName const &, FileName const &);
+
+
+} // namespace support
+} // namespace lyx
+
+#endif