]> git.lyx.org Git - features.git/commitdiff
A new FileName class + use by the graphics inset.
authorAngus Leeming <leeming@lyx.org>
Tue, 22 Jul 2003 20:42:40 +0000 (20:42 +0000)
committerAngus Leeming <leeming@lyx.org>
Tue, 22 Jul 2003 20:42:40 +0000 (20:42 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7348 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlGraphics.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/QGraphics.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormGraphics.C
src/insets/ChangeLog
src/insets/insetgraphics.C
src/insets/insetgraphicsParams.C
src/insets/insetgraphicsParams.h
src/support/Makefile.am
src/support/filename.C [new file with mode: 0644]
src/support/filename.h [new file with mode: 0644]

index 68cf1bb39c7a08bdacc3525ca33fd8496f2959b7..82db2ce37377e33f4bdfff86035a20be49cc8251 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-21  Angus Leeming  <leeming@lyx.org>
+
+       * ControlGraphics.C (initialiseParams, dispatchParams): no need
+       to modify the filename for reasons of 'good UI' anymore.
+
 2003-07-21  Angus Leeming  <leeming@lyx.org>
 
        * ControlGraphics.C (initialiseParams, dispatchParams): pass a
index 05fca1d7716b2d74395a6b2627722db08c726347..1018db795467f67a188115432ff73409f83eacc3 100644 (file)
@@ -54,8 +54,6 @@ bool ControlGraphics::initialiseParams(string const & data)
        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 236ec7543bce23bf996f2c928197dbbb0c1609a3..467838439d70641e987fc3792dd86402cea0739a 100644 (file)
@@ -1,3 +1,9 @@
+2003-07-21  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * QExternal.C (update_contents, apply):
index ea90488b8343a63128cc3f69d2f47d338eedffb1..49d314be0ea143cf4d480108c3e5832d9fe4d48e 100644 (file)
@@ -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 d443ea25095f05926e8176e74c7c48590cc42614..09961a577428d562338f0b949125933339de6f56 100644 (file)
@@ -1,3 +1,9 @@
+2003-07-21  Angus Leeming  <leeming@lyx.org>
+
+       * FormGraphics.C (apply, update):
+       changes due to the use of the FileName class to store the graphics
+       file name.
+
 2003-07-21  Angus Leeming  <leeming@lyx.org>
 
        * FormExternal.C (update, apply):
index cb984e7cf83196e152e1a3aaccaea59796b9b5fb..b8848293019e645198a1d93ed2d8b27022fca49b 100644 (file)
@@ -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 7ae35093456b1795444fec7d36c0a8fc8fb611f1..22407f3e7e96adbad1fdc6cf339c70d13ef50559 100644 (file)
@@ -1,3 +1,11 @@
+2003-07-21  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * insetgraphics.[Ch] (string2params, params2string): passed a
index cf6917c091473d8c1652009b22a5b9f6378fb57d..46f49c08eaaf5a7ece41b1d6d8769e84dab81f26 100644 (file)
@@ -331,8 +331,8 @@ string const InsetGraphics::prepareFile(Buffer const * buf,
 {
        // 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 * buf, ostream & os,
        // 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 *, ostream & os, int) 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(LaTeXFeatures & features) const
        if (params().filename.empty())
                return;
 
-       features.includeFile(graphic_label, RemoveExtension(params().filename));
+       features.includeFile(graphic_label,
+                            RemoveExtension(params().filename.absFilename()));
 
        features.require("graphicx");
 
index f9e7f29ce7f322ccb0c9aac489822c78aa50a992..60aae033ee6462561c2f6446f3ec56820fc0bf9b 100644 (file)
@@ -144,7 +144,7 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
        // 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 & lex, string const & token, string const
 {
        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 & lex, string const & token, string const
 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 InsetGraphicsParams::as_grfxParams() const
                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 c288c65bc23e47030b4cfde0b7c583ba1d559f02..8b626a64ec7d9ffdf946db607a771edb7475adf6 100644 (file)
@@ -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 2431c2f8b575c6dc114c1d7aa81f84c314955ab0..245610485bf51483b042395bf25bae5f8bdbc65f 100644 (file)
@@ -30,6 +30,8 @@ libsupport_la_SOURCES = \
        boost-inst.C \
        chdir.C \
        copy.C \
+       filename.C \
+       filename.h \
        filetools.C \
        filetools.h \
        forkedcall.C \
diff --git a/src/support/filename.C b/src/support/filename.C
new file mode 100644 (file)
index 0000000..cd4d475
--- /dev/null
@@ -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
diff --git a/src/support/filename.h b/src/support/filename.h
new file mode 100644 (file)
index 0000000..8f40675
--- /dev/null
@@ -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