]> git.lyx.org Git - lyx.git/commitdiff
Use a FileName variable in the external inset too.
authorAngus Leeming <leeming@lyx.org>
Wed, 23 Jul 2003 09:17:04 +0000 (09:17 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 23 Jul 2003 09:17:04 +0000 (09:17 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7350 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/factory.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/QExternal.C
src/frontends/qt2/QGraphics.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormExternal.C
src/frontends/xforms/FormGraphics.C
src/insets/ChangeLog
src/insets/insetexternal.C
src/insets/insetexternal.h

index b01306b81bf954bb51e3282561a8a3b167e2acdc..0845afc92e0f2e7390c583c583abc1eed3ce467b 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-23  Angus Leeming  <leeming@lyx.org>
+
+       * factory.C (createInset): pass a
+       Buffer const * parameter to InsetExternalMailer's string2params.
+
 2003-07-22  John Levon  <levon@movementarian.org>
 
        * Thesaurus.h: include the right aiksaurus header
index e9a22511a99e5d773a7fe92e32c3ff07c2738fbc..fa2fef5543685b64a81d0c9bc9ad8844c95d66d4 100644 (file)
@@ -198,11 +198,12 @@ Inset * createInset(FuncRequest const & cmd)
                        return inset;
 
                } else if (name == "external") {
+                       Buffer const * buffer = cmd.view()->buffer();
                        InsetExternal::Params iep;
-                       InsetExternalMailer::string2params(cmd.argument, iep);
+                       InsetExternalMailer::string2params(cmd.argument,
+                                                          buffer, iep);
                        InsetExternal * inset = new InsetExternal;
-                       string const fpath = cmd.view()->buffer()->filePath();
-                       inset->setParams(iep, fpath);
+                       inset->setParams(iep);
                        return inset;
 
                } else if (name == "graphics") {
index 467838439d70641e987fc3792dd86402cea0739a..d0a687d2e0c524ccfaf314e5cf7d7de731a0058b 100644 (file)
@@ -1,3 +1,12 @@
+2003-07-23  Angus Leeming  <leeming@lyx.org>
+
+       * QExternal.C (apply, update_contents):
+       changes due to the use of the FileName class to store the external
+       file name.
+
+       * QGraphics.C (apply, update_contents): use Kernel::bufferFilepath()
+       wrapper.
+
 2003-07-21  Angus Leeming  <leeming@lyx.org>
 
        * QGraphics.C (apply, update_contents):
index db265b3c4b50a52a7432fa94c01bc7a7e74a521a..5e34a4100bbd606f0a597f02a00dabd278ca3263 100644 (file)
@@ -67,7 +67,9 @@ void QExternal::update_contents()
 {
        InsetExternal::Params const & params = controller().params();
 
-       dialog_->fileED->setText(toqstr(params.filename));
+       string const name =
+               params.filename.outputFilename(kernel().bufferFilepath());
+       dialog_->fileED->setText(toqstr(name));
 
        dialog_->externalCO->setCurrentItem(controller().getTemplateNumber(params.templatename));
        dialog_->externalTV->setText(toqstr(helpText()));
@@ -104,7 +106,8 @@ void QExternal::apply()
 {
        InsetExternal::Params params = controller().params();
 
-       params.filename = fromqstr(dialog_->fileED->text());
+       params.filename.set(fromqstr(dialog_->fileED->text()),
+                           kernel().bufferFilepath());
 
        params.templatename =
                controller().getTemplate(dialog_->externalCO->currentItem()).lyxName;
index 49d314be0ea143cf4d480108c3e5832d9fe4d48e..2528fc6a8071e68cabd7a7a0b06ac7c34882bd8f 100644 (file)
@@ -21,7 +21,7 @@
 #include "support/filetools.h"
 #include "support/lyxlib.h"
 #include "insets/insetgraphicsParams.h"
-#include "buffer.h"
+#include "bufferparams.h"
 #include "lyxrc.h"
 #include "lengthcombo.h"
 #include "qt_helpers.h"
@@ -161,7 +161,7 @@ void QGraphics::update_contents()
        }
 
        string const name =
-               igp.filename.outputFilename(kernel().buffer()->filePath());
+               igp.filename.outputFilename(kernel().bufferFilepath());
        dialog_->filename->setText(toqstr(name));
 
        // set the bounding box values
@@ -303,7 +303,7 @@ void QGraphics::apply()
        InsetGraphicsParams & igp = controller().params();
 
        igp.filename.set(fromqstr(dialog_->filename->text()),
-                        kernel().buffer()->filePath());
+                        kernel().bufferFilepath());
 
        // the bb section
        igp.bb.erase();
index 09961a577428d562338f0b949125933339de6f56..b7dbd42fa5f3ea6839da5a7197808e256802a5a7 100644 (file)
@@ -1,3 +1,12 @@
+2003-07-23  Angus Leeming  <leeming@lyx.org>
+
+       * FormExternal.C (apply, update):
+       changes due to the use of the FileName class to store the external
+       file name.
+
+       * FormGraphics.C (apply, update): use Kernel::bufferFilepath()
+       wrapper.
+
 2003-07-21  Angus Leeming  <leeming@lyx.org>
 
        * FormGraphics.C (apply, update):
index 353784986b989f9e3216a9f76e4bf3f439fac61a..c59471daa9f85b56efb3e220759e64ceaaa46628 100644 (file)
@@ -43,7 +43,8 @@ void FormExternal::apply()
 {
        InsetExternal::Params params = controller().params();
 
-       params.filename = fl_get_input(dialog_->input_filename);
+       string const buffer_path = kernel().bufferFilepath();
+       params.filename.set(getString(dialog_->input_filename), buffer_path);
 
        int const choice = fl_get_choice(dialog_->choice_template) - 1;
        params.templatename = controller().getTemplate(choice).lyxName;
@@ -122,7 +123,9 @@ void FormExternal::update()
 {
        InsetExternal::Params const & params = controller().params();
 
-       fl_set_input(dialog_->input_filename, params.filename.c_str());
+       string const buffer_path = kernel().bufferFilepath();
+       string const name = params.filename.outputFilename(buffer_path);
+       fl_set_input(dialog_->input_filename, name.c_str());
 
        int ID = controller().getTemplateNumber(params.templatename);
        if (ID < 0) ID = 0;
index b8848293019e645198a1d93ed2d8b27022fca49b..dcdc701fd2ab58ee830d3fc09286169033970e29 100644 (file)
@@ -22,7 +22,6 @@
 #include "Tooltips.h"
 #include "xforms_helpers.h"
 
-#include "buffer.h"
 #include "debug.h" // for lyxerr
 #include "lyxrc.h" // for lyxrc.display_graphics
 
@@ -294,7 +293,7 @@ void FormGraphics::apply()
 
        // the file section
        igp.filename.set(getString(file_->input_filename),
-                        kernel().buffer()->filePath());
+                        kernel().bufferFilepath());
 
        igp.lyxscale = strToInt(getString(file_->input_lyxscale));
        if (igp.lyxscale == 0) {
@@ -427,7 +426,7 @@ void FormGraphics::update() {
 
        // the file section
        string const name =
-               igp.filename.outputFilename(kernel().buffer()->filePath());
+               igp.filename.outputFilename(kernel().bufferFilepath());
        fl_set_input(file_->input_filename, name.c_str());
        fl_set_input(file_->input_lyxscale, tostr(igp.lyxscale).c_str());
 
index 22407f3e7e96adbad1fdc6cf339c70d13ef50559..839830b0a75df0a853a128263a9d8f042d3e6bcd 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-23  Angus Leeming  <leeming@lyx.org>
+
+       * insetexternal.[Ch]: store the external file name in a FileName
+       member variable rather than a string + associated changes.
+
 2003-07-21  Angus Leeming  <leeming@lyx.org>
 
        * insetgraphicsParams.[Ch]: store the graphics file name in
index 037d452caede263c5e91007022a30730b5a2d5e4..de1ae3c924b3ac9086f9273e490492e867815f6b 100644 (file)
@@ -121,12 +121,6 @@ void InsetExternal::statusChanged()
 }
 
 
-InsetExternal::Params const & InsetExternal::params() const
-{
-       return params_;
-}
-
-
 dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
@@ -134,18 +128,20 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
        case LFUN_EXTERNAL_EDIT: {
                Assert(cmd.view());
 
+               Buffer const * buffer = cmd.view()->buffer();
                InsetExternal::Params p;
-               InsetExternalMailer::string2params(cmd.argument, p);
-               editExternal(p, cmd.view()->buffer());
+               InsetExternalMailer::string2params(cmd.argument, buffer, p);
+               editExternal(p, buffer);
                return DISPATCHED_NOUPDATE;
        }
 
        case LFUN_INSET_MODIFY: {
                Assert(cmd.view());
 
+               Buffer const * buffer = cmd.view()->buffer();
                InsetExternal::Params p;
-               InsetExternalMailer::string2params(cmd.argument, p);
-               setParams(p, cmd.view()->buffer()->filePath());
+               InsetExternalMailer::string2params(cmd.argument, buffer, p);
+               setParams(p);
                cmd.view()->updateInset(this);
                return DISPATCHED;
        }
@@ -180,16 +176,11 @@ void InsetExternal::draw(PainterInfo & pi, int x, int y) const
 
 namespace {
 
-lyx::graphics::Params get_grfx_params(InsetExternal::Params const & eparams,
-                            string const & filepath)
+lyx::graphics::Params get_grfx_params(InsetExternal::Params const & eparams)
 {
        lyx::graphics::Params gparams;
 
-       if (!eparams.filename.empty()) {
-               Assert(AbsolutePath(filepath));
-               gparams.filename = MakeAbsPath(eparams.filename, filepath);
-       }
-
+       gparams.filename = eparams.filename.absFilename();
        gparams.scale = eparams.lyxscale;
        gparams.display = eparams.display;
 
@@ -226,7 +217,13 @@ string const getScreenLabel(InsetExternal::Params const & params)
 } // namespace anon
 
 
-void InsetExternal::setParams(Params const & p, string const & filepath)
+InsetExternal::Params const & InsetExternal::params() const
+{
+       return params_;
+}
+
+
+void InsetExternal::setParams(Params const & p)
 {
        // The stored params; what we would like to happen in an ideal world.
        params_.filename = p.filename;
@@ -237,7 +234,6 @@ void InsetExternal::setParams(Params const & p, string const & filepath)
        // We display the inset as a button by default.
        bool display_button = (!getTemplatePtr(params_) ||
                               params_.filename.empty() ||
-                              filepath.empty() ||
                               params_.display == lyx::graphics::NoDisplay);
 
        if (display_button) {
@@ -260,24 +256,32 @@ void InsetExternal::setParams(Params const & p, string const & filepath)
                        renderer_.reset(graphic_ptr);
                }
 
-               graphic_ptr->update(get_grfx_params(params_, filepath));
+               graphic_ptr->update(get_grfx_params(params_));
        }
 }
 
 
+BufferView * InsetExternal::view() const
+{
+       return renderer_->view();
+}
+
+
 string const InsetExternal::editMessage() const
 {
        return getScreenLabel(params_);
 }
 
 
-void InsetExternal::write(Buffer const *, ostream & os) const
+void InsetExternal::write(Buffer const * buffer, ostream & os) const
 {
        os << "External\n"
           << "\ttemplate " << params_.templatename << '\n';
 
        if (!params_.filename.empty())
-               os << "\tfilename " << params_.filename << '\n';
+               os << "\tfilename "
+                  << params_.filename.outputFilename(buffer->filePath())
+                  << '\n';
 
        if (params_.display != defaultDisplayType)
                os << "\tdisplay " << lyx::graphics::displayTranslator.find(params_.display)
@@ -323,7 +327,7 @@ void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
                case EX_FILENAME: {
                        lex.next();
                        string const name = lex.getString();
-                       params.filename = name;
+                       params.filename.set(name, buffer->filePath());
                        break;
                }
 
@@ -363,15 +367,14 @@ void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
        lex.popTable();
 
        // Replace the inset's store
-       string const path = buffer ? buffer->filePath() : string();
-       setParams(params, path);
+       setParams(params);
 
        lyxerr[Debug::INFO] << "InsetExternal::Read: "
-              << "template: '" << params_.templatename
-              << "' filename: '" << params_.filename
-              << "' display: '" << params_.display
-              << "' scale: '" << params_.lyxscale
-              << '\'' << endl;
+                           << "template: '" << params_.templatename
+                           << "' filename: '" << params_.filename.absFilename()
+                           << "' display: '" << params_.display
+                           << "' scale: '" << params_.lyxscale
+                           << '\'' << endl;
 }
 
 
@@ -493,8 +496,7 @@ void InsetExternal::updateExternal(string const & format,
        if (from_format.empty())
                return;
 
-       string from_file = params_.filename.empty() ?
-               string() : MakeAbsPath(params_.filename, buf->filePath());
+       string from_file = params_.filename.absFilename();
 
        if (from_format == "*") {
                if (from_file.empty())
@@ -550,10 +552,11 @@ string const doSubstitution(InsetExternal::Params const & params,
                            Buffer const * buffer, string const & s)
 {
        string result;
-       string const basename = ChangeExtension(params.filename, string());
+       string const absfilename = params.filename.absFilename();
+       string const basename = ChangeExtension(absfilename, string());
        string filepath;
 
-       result = subst(s, "$$FName", params.filename);
+       result = subst(s, "$$FName", absfilename);
        result = subst(result, "$$Basename", basename);
        result = subst(result, "$$FPath", filepath);
        result = subst(result, "$$Tempname", params.tempname);
@@ -619,11 +622,15 @@ InsetExternalMailer::InsetExternalMailer(InsetExternal & inset)
 
 string const InsetExternalMailer::inset2string() const
 {
-       return params2string(inset_.params());
+       BufferView * bv = inset_.view();
+       if (!bv)
+               return string();
+       return params2string(inset_.params(), bv->buffer());
 }
 
 
 void InsetExternalMailer::string2params(string const & in,
+                                       Buffer const * buffer,
                                        InsetExternal::Params & params)
 {
        params = InsetExternal::Params();
@@ -653,20 +660,21 @@ void InsetExternalMailer::string2params(string const & in,
 
        if (lex.isOK()) {
                InsetExternal inset;
-               inset.read(0, lex);
+               inset.read(buffer, lex);
                params = inset.params();
        }
 }
 
 
 string const
-InsetExternalMailer::params2string(InsetExternal::Params const & params)
+InsetExternalMailer::params2string(InsetExternal::Params const & params,
+                                  Buffer const * buffer)
 {
        InsetExternal inset;
-       inset.setParams(params, string());
+       inset.setParams(params);
        ostringstream data;
        data << name_ << ' ';
-       inset.write(0, data);
+       inset.write(buffer, data);
        data << "\\end_inset\n";
        return STRCONV(data.str());
 }
index 919a9ab4be3a23d5e890e08bf34793b4139d58cf..8f71ff76368f3c7205bd81a337388d11d3bcf85e 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "inset.h"
 #include "graphics/GraphicsTypes.h"
+#include "support/filename.h"
 #include "LString.h"
 
 #include <boost/scoped_ptr.hpp>
@@ -30,7 +31,7 @@ public:
                Params();
                ~Params();
                /// the filename
-               string filename;
+               lyx::support::FileName filename;
                /// the current template used
                string templatename;
                /// The name of the tempfile used for manipulations.
@@ -85,8 +86,13 @@ public:
        ///
        virtual InsetBase * clone() const;
 
+       /// return a copy of our current params
+       Params const & params() const;
+
        /// Set the inset parameters.
-       virtual void setParams(Params const &, string const & filepath);
+       virtual void setParams(Params const &);
+
+       virtual BufferView * view() const;
 
        /** update the file represented by the template.
            If \param external_in_tmpdir == true, then the generated file is
@@ -95,9 +101,6 @@ public:
        void updateExternal(string const &, Buffer const *,
                            bool external_in_tmpdir) const;
 
-       /// return a copy of our current params
-       Params const & params() const;
-
 private:
        /** This method is connected to the graphics loader, so we are
         *  informed when the image has been loaded.
@@ -133,9 +136,11 @@ public:
        ///
        virtual string const inset2string() const;
        ///
-       static void string2params(string const &, InsetExternal::Params &);
+       static void string2params(string const &, Buffer const *,
+                                 InsetExternal::Params &);
        ///
-       static string const params2string(InsetExternal::Params const &);
+       static string const params2string(InsetExternal::Params const &,
+                                         Buffer const *);
 private:
        ///
        static string const name_;