diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc index edcd38079a..73f79fd930 100644 --- a/lib/ui/stdcontext.inc +++ b/lib/ui/stdcontext.inc @@ -192,6 +192,8 @@ Menuset Item "Listing|L" "next-inset-modify changetype lstinputlisting" Separator Item "Settings...|S" "next-inset-toggle" + Separator + Item "Edit included file...|E" "inset-edit" End # @@ -271,7 +273,7 @@ Menuset Menu "context-graphics" Item "Settings...|S" "next-inset-toggle" Separator - Item "Edit externally...|x" "graphics-edit" + Item "Edit externally...|x" "inset-edit" End # diff --git a/src/frontends/qt4/GuiInclude.cpp b/src/frontends/qt4/GuiInclude.cpp index 0dd8ac11e9..6e15b2666a 100644 --- a/src/frontends/qt4/GuiInclude.cpp +++ b/src/frontends/qt4/GuiInclude.cpp @@ -15,7 +15,6 @@ #include "GuiInclude.h" #include "Buffer.h" -#include "Format.h" #include "FuncRequest.h" #include "LyXRC.h" @@ -289,11 +288,12 @@ void GuiInclude::browse() void GuiInclude::edit() { - if (isValid()) { - string const file = fromqstr(filenameED->text()); - slotOK(); - edit(file); - } + if (!isValid()) + return; + string const file = fromqstr(filenameED->text()); + slotOK(); + applyView(); + dispatch(FuncRequest(LFUN_INSET_EDIT)); } @@ -326,19 +326,6 @@ QString GuiInclude::browse(QString const & in_name, Type in_type) const } -void GuiInclude::edit(string const & file) -{ - string const ext = support::getExtension(file); - if (ext == "lyx") - dispatch(FuncRequest(LFUN_BUFFER_CHILD_OPEN, file)); - else - // tex file or other text file in verbatim mode - formats.edit(buffer(), - support::makeAbsPath(file, support::onlyPath(buffer().absFileName())), - "text"); -} - - bool GuiInclude::initialiseParams(std::string const & data) { InsetCommand::string2params("include", data, params_); diff --git a/src/frontends/qt4/GuiInclude.h b/src/frontends/qt4/GuiInclude.h index f066a2ab05..37f80fddf6 100644 --- a/src/frontends/qt4/GuiInclude.h +++ b/src/frontends/qt4/GuiInclude.h @@ -71,8 +71,6 @@ private: /// validate listings parameters and return an error message, if any docstring validate_listings_params(); /// - void edit(std::string const & file); - /// bool isValid(); /// Apply changes void applyView(); diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index 503c8124e7..55e8c4d6cf 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -66,6 +66,8 @@ protected: /// void doDispatch(Cursor & cur, FuncRequest & cmd); /// + bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; + /// docstring const getCommand() const { return p_.getCommand(); } /// std::string const & getCmdName() const { return p_.getCmdName(); } @@ -105,8 +107,6 @@ private: static bool isCompatibleCommand(std::string const & cmd); /// docstring contextMenu(BufferView const & bv, int x, int y) const; - /// - bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; /// This should provide the text for the button virtual docstring screenLabel() const = 0; diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 3cf4497e79..c85697385f 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -23,10 +23,12 @@ #include "DispatchResult.h" #include "ErrorList.h" #include "Exporter.h" +#include "Format.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "LaTeXFeatures.h" #include "LyX.h" +#include "LyXFunc.h" #include "LyXRC.h" #include "Lexer.h" #include "MetricsInfo.h" @@ -241,6 +243,11 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) LASSERT(&cur.buffer() == &buffer(), /**/); switch (cmd.action) { + case LFUN_INSET_EDIT: { + editIncluded(to_utf8(params()["filename"])); + break; + } + case LFUN_INSET_MODIFY: { InsetCommandParams p(INCLUDE_CODE); if (cmd.getArg(0) == "changetype") { @@ -276,6 +283,35 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd) } +void InsetInclude::editIncluded(string const & file) +{ + string const ext = support::getExtension(file); + if (ext == "lyx") { + FuncRequest fr(LFUN_BUFFER_CHILD_OPEN, file); + lyx::dispatch(fr); + } else + // tex file or other text file in verbatim mode + formats.edit(buffer(), + support::makeAbsPath(file, support::onlyPath(buffer().absFileName())), + "text"); +} + + +bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const +{ + switch (cmd.action) { + + case LFUN_INSET_EDIT: + flag.enabled(true); + return true; + + default: + return InsetCommand::getStatus(cur, cmd, flag); + } +} + + void InsetInclude::setParams(InsetCommandParams const & p) { InsetCommand::setParams(p); diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index f3f5ebf295..d06815100f 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -99,6 +99,8 @@ protected: InsetInclude(InsetInclude const &); /// void doDispatch(Cursor & cur, FuncRequest & cmd); + /// + bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; private: Inset * clone() const { return new InsetInclude(*this); } @@ -107,6 +109,8 @@ private: */ void fileChanged() const; + /// launch external application + void editIncluded(std::string const & file); /// set the parameters void setParams(InsetCommandParams const & params); /// get the text displayed on the button