]> git.lyx.org Git - features.git/commitdiff
LFUN_EXTERNAL_EDIT.
authorAngus Leeming <leeming@lyx.org>
Wed, 11 Jun 2003 11:01:34 +0000 (11:01 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 11 Jun 2003 11:01:34 +0000 (11:01 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7144 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/LyXAction.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlExternal.C
src/insets/ChangeLog
src/insets/graphicinset.C
src/insets/graphicinset.h
src/insets/insetexternal.C
src/insets/insetexternal.h
src/lfuns.h
src/lyxfunc.C

index 137b7d4ba6027f7b20410a23ed4db4ac41014891..0578d83184f91453d6cbbdbed82924cee63a8478 100644 (file)
@@ -1,3 +1,10 @@
+2003-06-10  Angus Leeming  <leeming@lyx.org>
+
+       * lfuns.h:
+       * LyXAction.C (init): new LFUN_EXTERNAL_EDIT.
+
+       * lyxfunc.C (dispatch): invoke it.
+
 2003-06-11  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * main.C: protect <ios> with HAVE_IOS
index 5dc982296d16cba3a767668a1a4278dad3490174..bf89d50509bef6f138d3d4e1553eb649456fa831 100644 (file)
@@ -325,6 +325,7 @@ void LyXAction::init()
                { LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
                { LFUN_PARAGRAPH_APPLY, "paragraph-params-apply", Noop },
                { LFUN_PARAGRAPH_UPDATE, "", Noop },
+               { LFUN_EXTERNAL_EDIT, "external-edit", Noop },
                { LFUN_NOACTION, "", Noop }
        };
 
index a9572740e1479a3f353942e0ab5299cd88081548..b9c6dd957e9b4fd9661e104cb4add6c73405ba54 100644 (file)
@@ -1,3 +1,8 @@
+2003-06-10  Angus Leeming  <leeming@lyx.org>
+
+       * ControlExternal.C (editExternal): invokes new LFUN_EXTERNAL_EDIT rather
+       than generate a new inset itself.
+
 2003-06-06  John Levon  <levon@movementarian.org>
 
        * ControlDocument.C: make sure a language change
index f6463e2c3087874d79907383a32b8d6f50074f08..c985ef4fd574e5bdddc356f8acedf5fa81f8af6a 100644 (file)
@@ -70,10 +70,8 @@ void ControlExternal::editExternal()
        lyx::Assert(params_.get());
 
        dialog().view().apply();
-       InsetExternal inset;
-       inset.setParams(*params_, kernel().buffer()->filePath());
-       inset.cache(kernel().bufferview());
-       inset.editExternal();
+       string const lfun = InsetExternalMailer::params2string(params());
+       kernel().dispatch(FuncRequest(LFUN_EXTERNAL_EDIT, lfun));
 }
 
 
index 291dab45ee9d8618c15a1fc1f409c45e159624e1..c5c7a3b6314e5e4ba370e166130af830a0d0b89f 100644 (file)
@@ -2,6 +2,17 @@
 
        * insettext.C (appendParagraphs): remove some commented code.
 
+2003-06-10  Angus Leeming  <leeming@lyx.org>
+
+       * graphicinset.[Ch] (view): removed the publicly accessible function to set
+       the cache.
+
+       * insetexternal.[Ch]: move tempname_ into the Params struct.
+       (Params d-tor): new function, to clean-up this temp file.
+       (localDispatch): dispatch LFUN_EXTERNAL_EDIT.
+       (cache): removed.
+       (editExternal, doSubstitution): move out of class.
+
 2003-06-10  Angus Leeming  <leeming@lyx.org>
 
        * graphicinset.[Ch] (params): removed.
index 04894eceee18a6d42d6c0aa170367e6c84faf19b..7d80bfeec4395d68b45f9d85aa48cb5977b7c3ae 100644 (file)
@@ -60,13 +60,6 @@ bool GraphicInset::hasFileChanged() const
 }
 
 
-void GraphicInset::view(BufferView * bv) const
-{
-       if (bv)
-               view_ = bv->owner()->view();
-}
-
-
 BufferView * GraphicInset::view() const
 {
        return view_.lock().get();
@@ -184,8 +177,8 @@ void GraphicInset::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void GraphicInset::draw(PainterInfo & pi, int x, int y) const
 {
-       // Cache the BufferView.
-       view(pi.base.bv);
+       if (pi.base.bv)
+               view_ = pi.base.bv->owner()->view();
 
 #if 0
        // Comment this out and see if anything goes wrong.
index ed79d49eb44acc404b314ca422a2bae59353d391..cccc74b892f0adbad580e7cd6d0420db9e927ad4 100644 (file)
@@ -51,8 +51,6 @@ public:
 
        /// Is the stored checksum different to that of the graphics loader?
        bool hasFileChanged() const;
-       /// Set the cached store.
-       void view(BufferView *) const;
        /// An accessor function to the cached store.
        BufferView * view() const;
 
index d0f23a0d33311e5a529cb98519feb8f0e78a6094..0cfc8586e55cdb5bf5d43c38a604b50dff926045 100644 (file)
@@ -54,13 +54,31 @@ grfx::DisplayType const defaultDisplayType = grfx::NoDisplay;
 
 unsigned int defaultLyxScale = 100;
 
+/// Substitute meta-variables in string s, makeing use of params and buffer.
+string const doSubstitution(InsetExternal::Params const & params,
+                           Buffer const * buffer, string const & s);
+
+/// Invoke the external editor.
+void editExternal(InsetExternal::Params const & params, Buffer const * buffer);
+
 } // namespace anon
 
 
 InsetExternal::Params::Params()
        : display(defaultDisplayType),
          lyxscale(defaultLyxScale)
-{}
+{
+       tempname = lyx::tempName(string(), "lyxext");
+       lyx::unlink(tempname);
+       // must have an extension for the converter code to work correctly.
+       tempname += ".tmp";
+}
+
+
+InsetExternal::Params::~Params()
+{
+       lyx::unlink(tempname);
+}
 
 
 InsetExternal::InsetExternal()
@@ -90,8 +108,6 @@ Inset * InsetExternal::clone() const
 
 InsetExternal::~InsetExternal()
 {
-       if (!tempname_.empty())
-               lyx::unlink(tempname_);
        InsetExternalMailer(*this).hideDialog();
 }
 
@@ -114,7 +130,18 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
 
+       case LFUN_EXTERNAL_EDIT: {
+               lyx::Assert(cmd.view());
+
+               InsetExternal::Params p;
+               InsetExternalMailer::string2params(cmd.argument, p);
+               editExternal(p, cmd.view()->buffer());
+               return DISPATCHED_NOUPDATE;
+       }
+       
        case LFUN_INSET_MODIFY: {
+               lyx::Assert(cmd.view());
+
                InsetExternal::Params p;
                InsetExternalMailer::string2params(cmd.argument, p);
                setParams(p, cmd.view()->buffer()->filePath());
@@ -137,12 +164,6 @@ dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
 }
 
 
-void InsetExternal::cache(BufferView * bv) const
-{
-       renderer_->view(bv);
-}
-
-
 void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        renderer_->metrics(mi, dim);
@@ -193,14 +214,14 @@ void InsetExternal::setParams(Params const & p, string const & filepath)
        // Update the display using the new parameters.
        if (params_.filename.empty() || !filepath.empty())
                renderer_->update(get_grfx_params(params_, filepath));  
-       string const msg = doSubstitution(0, params_.templ.guiName);
+       string const msg = doSubstitution(params_, 0, params_.templ.guiName);
        renderer_->setNoDisplayMessage(msg);
 }
 
 
 string const InsetExternal::editMessage() const
 {
-       return doSubstitution(0, params_.templ.guiName);
+       return doSubstitution(params_, 0, params_.templ.guiName);
 }
 
 
@@ -311,7 +332,7 @@ void InsetExternal::read(Buffer const * buffer, LyXLex & lex)
        // Update the display using the new parameters.
        if (buffer)
                renderer_->update(get_grfx_params(params_, buffer->filePath()));
-       string const msg = doSubstitution(0, params_.templ.guiName);
+       string const msg = doSubstitution(params_, 0, params_.templ.guiName);
        renderer_->setNoDisplayMessage(msg);
 }
 
@@ -331,7 +352,7 @@ int InsetExternal::write(string const & format,
        }
 
        updateExternal(format, buf, external_in_tmpdir);
-       string const str = doSubstitution(buf, cit->second.product);
+       string const str = doSubstitution(params_, buf, cit->second.product);
        os << str;
        return int(lyx::count(str.begin(), str.end(),'\n') + 1);
 }
@@ -397,56 +418,6 @@ void InsetExternal::validate(LaTeXFeatures & features) const
 }
 
 
-string const InsetExternal::doSubstitution(Buffer const * buffer,
-                                          string const & s) const
-{
-       string result;
-       string const basename = ChangeExtension(params_.filename, string());
-       string filepath;
-       bool external_in_tmpdir = false;
-       if (buffer && !buffer->tmppath.empty() && !buffer->niceFile) {
-               filepath = buffer->filePath();
-               if (lyxrc.use_tempdir)
-                       external_in_tmpdir = true;
-       }
-       if (tempname_.empty()) {
-               string const path = external_in_tmpdir ? buffer->tmppath : string();
-               tempname_ = lyx::tempName(path, "lyxext");
-               lyx::unlink(tempname_);
-               // must have an extension for the converter code to work correctly.
-               tempname_ += ".tmp";
-       }
-       result = subst(s, "$$FName", params_.filename);
-       result = subst(result, "$$Basename", basename);
-       result = subst(result, "$$FPath", filepath);
-       result = subst(result, "$$Tempname", tempname_);
-       result = subst(result, "$$Sysdir", system_lyxdir);
-
-       // Handle the $$Contents(filename) syntax
-       if (contains(result, "$$Contents(\"")) {
-
-               string::size_type const pos = result.find("$$Contents(\"");
-               string::size_type const end = result.find("\")", pos);
-               string const file = result.substr(pos + 12, end - (pos + 12));
-               string contents;
-               if (buffer) {
-                       Path p(buffer->filePath());
-                       if (!IsFileReadable(file))
-                               Path p(buffer->tmppath);
-                       if (IsFileReadable(file))
-                               contents = GetFileContents(file);
-               } else {
-                       contents = GetFileContents(file);
-               }
-               result = subst(result,
-                              ("$$Contents(\"" + file + "\")").c_str(),
-                              contents);
-       }
-
-       return result;
-}
-
-
 void InsetExternal::updateExternal(string const & format,
                                   Buffer const * buf,
                                   bool external_in_tmpdir) const
@@ -499,7 +470,8 @@ void InsetExternal::updateExternal(string const & format,
                        return;
        }
 
-       string const to_file = doSubstitution(buf, outputFormat.updateResult);
+       string const to_file = doSubstitution(params_, buf,
+                                             outputFormat.updateResult);
 
        FileInfo fi(from_file);
        string abs_to_file = to_file;
@@ -517,18 +489,57 @@ void InsetExternal::updateExternal(string const & format,
 }
 
 
-void InsetExternal::editExternal() const
+namespace {
+
+/// Substitute meta-variables in this string
+string const doSubstitution(InsetExternal::Params const & params,
+                           Buffer const * buffer, string const & s)
 {
-       ExternalTemplate const & et = params_.templ;
-       if (et.editCommand.empty())
-               return;
+       string result;
+       string const basename = ChangeExtension(params.filename, string());
+       string filepath;
+
+       result = subst(s, "$$FName", params.filename);
+       result = subst(result, "$$Basename", basename);
+       result = subst(result, "$$FPath", filepath);
+       result = subst(result, "$$Tempname", params.tempname);
+       result = subst(result, "$$Sysdir", system_lyxdir);
+
+       // Handle the $$Contents(filename) syntax
+       if (contains(result, "$$Contents(\"")) {
 
-       BufferView const * bv = renderer_->view();
-       Buffer const * buffer = bv ? bv->buffer() : 0;
+               string::size_type const pos = result.find("$$Contents(\"");
+               string::size_type const end = result.find("\")", pos);
+               string const file = result.substr(pos + 12, end - (pos + 12));
+               string contents;
+               if (buffer) {
+                       Path p(buffer->filePath());
+                       if (!IsFileReadable(file))
+                               Path p(buffer->tmppath);
+                       if (IsFileReadable(file))
+                               contents = GetFileContents(file);
+               } else {
+                       contents = GetFileContents(file);
+               }
+               result = subst(result,
+                              ("$$Contents(\"" + file + "\")").c_str(),
+                              contents);
+       }
+
+       return result;
+}
+
+
+void editExternal(InsetExternal::Params const & params, Buffer const * buffer)
+{
        if (!buffer)
                return;
 
-       string const command = doSubstitution(buffer, et.editCommand);
+       ExternalTemplate const & et = params.templ;
+       if (et.editCommand.empty())
+               return;
+
+       string const command = doSubstitution(params, buffer, et.editCommand);
 
        Path p(buffer->filePath());
        Forkedcall call;
@@ -539,6 +550,7 @@ void InsetExternal::editExternal() const
        call.startscript(Forkedcall::DontWait, command);
 }
 
+} // namespace anon
 
 string const InsetExternalMailer::name_("external");
 
index 0fe922c22236571479cf5914455dce9535e2ad7b..83285347febdb0a79c815aac75f9b8dff0384b87 100644 (file)
@@ -29,8 +29,11 @@ public:
        /// hold parameters settable from the GUI
        struct Params {
                Params();
+               ~Params();
                /// the filename
                string filename;
+               /// The name of the tempfile used for manipulations.
+               string tempname;
                /// the current template used
                ExternalTemplate templ;
                /// how the inset is displayed by LyX
@@ -46,10 +49,6 @@ public:
        virtual ~InsetExternal();
        ///
        virtual dispatch_result localDispatch(FuncRequest const & cmd);
-       /** Would not be needed if editExternal were dispatched properly from
-        *  the frontends rather than being invoked directly.
-        */
-       virtual void cache(BufferView *) const;
        ///
        void metrics(MetricsInfo &, Dimension &) const;
        ///
@@ -97,9 +96,6 @@ public:
        void updateExternal(string const &, Buffer const *,
                            bool external_in_tmpdir) const;
 
-       /// edit file of this template
-       void editExternal() const;
-
        /// return a copy of our current params
        Params const & params() const;
 
@@ -117,15 +113,9 @@ private:
        int write(string const & format, Buffer const *, std::ostream &,
                  bool external_in_tmpdir = false) const;
 
-       /// Substitute meta-variables in this string
-       string const doSubstitution(Buffer const *, string const & s) const;
-
        /// the current params
        Params params_;
 
-       /// A temp filename
-       mutable string tempname_;
-
        /// The thing that actually draws the image on LyX's screen.
        boost::scoped_ptr<GraphicInset> const renderer_;
 };
index 0ecea946a99e774b18096e15aa4bb4715e845fc0..14dcb4be1a3c7b4efdc036febf302894355b5be1 100644 (file)
@@ -335,6 +335,7 @@ enum kb_action {
        // 255
        LFUN_PARAGRAPH_APPLY,
        LFUN_PARAGRAPH_UPDATE,
+       LFUN_EXTERNAL_EDIT,
 
        LFUN_LASTACTION                  // end of the table
 };
index 293e23f3c53bbd928f20b65967facbb0076fc5bf..332f0eb267e73c260b93ada64eb4de96a49e1b99 100644 (file)
@@ -44,6 +44,7 @@
 #include "ParagraphParameters.h"
 
 #include "insets/insetcommand.h"
+#include "insets/insetexternal.h"
 #include "insets/insettabular.h"
 
 #include "mathed/formulamacro.h"
@@ -1588,6 +1589,12 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                owner->getDialogs().toggleTooltips();
                break;
 
+       case LFUN_EXTERNAL_EDIT: {
+               InsetExternal()
+                       .localDispatch(FuncRequest(view(), action, argument));
+               break;
+       }
+
        default:
                // Then if it was none of the above
                // Trying the BufferView::pimpl dispatch: