diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 96094ea605..cce0932f98 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1779,6 +1779,17 @@ bool BufferView::dispatch(FuncRequest const & cmd) getIntl().toggleKeyMap(); break; + case LFUN_DIALOG_SHOW_NEW_INSET: { + string const name = cmd.getArg(0); + string data = trim(to_utf8(cmd.argument()).substr(name.size())); + if (decodeInsetParam(name, data, buffer_)) + lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data)); + else + lyxerr << "Inset type '" << name << + "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl; + break; + } + default: return false; } diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 19d2b086c4..2dda89129e 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -43,6 +43,7 @@ #include "Intl.h" #include "KeyMap.h" #include "Language.h" +#include "LaTeXFeatures.h" #include "Lexer.h" #include "LyXAction.h" #include "lyxfind.h" @@ -57,21 +58,7 @@ #include "Session.h" #include "SpellChecker.h" -#include "insets/InsetBox.h" -#include "insets/InsetBranch.h" #include "insets/InsetCommand.h" -#include "insets/InsetERT.h" -#include "insets/InsetExternal.h" -#include "insets/InsetFloat.h" -#include "insets/InsetGraphics.h" -#include "insets/InsetInclude.h" -#include "insets/InsetListings.h" -#include "insets/InsetNote.h" -#include "insets/InsetPhantom.h" -#include "insets/InsetSpace.h" -#include "insets/InsetTabular.h" -#include "insets/InsetVSpace.h" -#include "insets/InsetWrap.h" #include "frontends/alert.h" #include "frontends/Application.h" @@ -84,6 +71,7 @@ #include "support/FileName.h" #include "support/filetools.h" #include "support/gettext.h" +#include "support/lassert.h" #include "support/lstrings.h" #include "support/Path.h" #include "support/Package.h" @@ -591,112 +579,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd) theServer().notifyClient(to_utf8(dispatch_buffer)); break; - case LFUN_DIALOG_SHOW_NEW_INSET: { - LASSERT(lv, /**/); - string const name = cmd.getArg(0); - InsetCode code = insetCode(name); - string data = trim(to_utf8(cmd.argument()).substr(name.size())); - bool insetCodeOK = true; - switch (code) { - case BIBITEM_CODE: - case BIBTEX_CODE: - case INDEX_CODE: - case LABEL_CODE: - case NOMENCL_CODE: - case NOMENCL_PRINT_CODE: - case REF_CODE: - case TOC_CODE: - case HYPERLINK_CODE: { - InsetCommandParams p(code); - data = InsetCommand::params2string(name, p); - break; - } - case INCLUDE_CODE: { - // data is the include type: one of "include", - // "input", "verbatiminput" or "verbatiminput*" - if (data.empty()) - // default type is requested - data = "include"; - InsetCommandParams p(INCLUDE_CODE, data); - data = InsetCommand::params2string("include", p); - break; - } - case BOX_CODE: { - // \c data == "Boxed" || "Frameless" etc - InsetBoxParams p(data); - data = InsetBox::params2string(p); - break; - } - case BRANCH_CODE: { - InsetBranchParams p; - data = InsetBranch::params2string(p); - break; - } - case CITE_CODE: { - InsetCommandParams p(CITE_CODE); - data = InsetCommand::params2string(name, p); - break; - } - case ERT_CODE: { - data = InsetERT::params2string(InsetCollapsable::Open); - break; - } - case EXTERNAL_CODE: { - InsetExternalParams p; - data = InsetExternal::params2string(p, *buffer); - break; - } - case FLOAT_CODE: { - InsetFloatParams p; - data = InsetFloat::params2string(p); - break; - } - case LISTINGS_CODE: { - InsetListingsParams p; - data = InsetListings::params2string(p); - break; - } - case GRAPHICS_CODE: { - InsetGraphicsParams p; - data = InsetGraphics::params2string(p, *buffer); - break; - } - case NOTE_CODE: { - InsetNoteParams p; - data = InsetNote::params2string(p); - break; - } - case PHANTOM_CODE: { - InsetPhantomParams p; - data = InsetPhantom::params2string(p); - break; - } - case SPACE_CODE: { - InsetSpaceParams p; - data = InsetSpace::params2string(p); - break; - } - case VSPACE_CODE: { - VSpace space; - data = InsetVSpace::params2string(space); - break; - } - case WRAP_CODE: { - InsetWrapParams p; - data = InsetWrap::params2string(p); - break; - } - default: - lyxerr << "Inset type '" << name << - "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl; - insetCodeOK = false; - break; - } // end switch(code) - if (insetCodeOK) - dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data)); - break; - } - case LFUN_CITATION_INSERT: { LASSERT(lv, /**/); if (!argument.empty()) { diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index 378866c2a0..9d8d10d935 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -21,6 +21,22 @@ #include "Lexer.h" #include "MetricsInfo.h" +#include "insets/InsetBox.h" +#include "insets/InsetBranch.h" +#include "insets/InsetCommand.h" +#include "insets/InsetERT.h" +#include "insets/InsetExternal.h" +#include "insets/InsetFloat.h" +#include "insets/InsetGraphics.h" +#include "insets/InsetInclude.h" +#include "insets/InsetListings.h" +#include "insets/InsetNote.h" +#include "insets/InsetPhantom.h" +#include "insets/InsetSpace.h" +#include "insets/InsetTabular.h" +#include "insets/InsetVSpace.h" +#include "insets/InsetWrap.h" + #include "support/debug.h" #include "support/gettext.h" @@ -218,4 +234,103 @@ string InsetCommand::params2string(string const & name, } +bool decodeInsetParam(string const & name, string & data, + Buffer const & buffer) +{ + InsetCode const code = insetCode(name); + switch (code) { + case BIBITEM_CODE: + case BIBTEX_CODE: + case INDEX_CODE: + case LABEL_CODE: + case NOMENCL_CODE: + case NOMENCL_PRINT_CODE: + case REF_CODE: + case TOC_CODE: + case HYPERLINK_CODE: { + InsetCommandParams p(code); + data = InsetCommand::params2string(name, p); + break; + } + case INCLUDE_CODE: { + // data is the include type: one of "include", + // "input", "verbatiminput" or "verbatiminput*" + if (data.empty()) + // default type is requested + data = "include"; + InsetCommandParams p(INCLUDE_CODE, data); + data = InsetCommand::params2string("include", p); + break; + } + case BOX_CODE: { + // \c data == "Boxed" || "Frameless" etc + InsetBoxParams p(data); + data = InsetBox::params2string(p); + break; + } + case BRANCH_CODE: { + InsetBranchParams p; + data = InsetBranch::params2string(p); + break; + } + case CITE_CODE: { + InsetCommandParams p(CITE_CODE); + data = InsetCommand::params2string(name, p); + break; + } + case ERT_CODE: { + data = InsetERT::params2string(InsetCollapsable::Open); + break; + } + case EXTERNAL_CODE: { + InsetExternalParams p; + data = InsetExternal::params2string(p, buffer); + break; + } + case FLOAT_CODE: { + InsetFloatParams p; + data = InsetFloat::params2string(p); + break; + } + case LISTINGS_CODE: { + InsetListingsParams p; + data = InsetListings::params2string(p); + break; + } + case GRAPHICS_CODE: { + InsetGraphicsParams p; + data = InsetGraphics::params2string(p, buffer); + break; + } + case NOTE_CODE: { + InsetNoteParams p; + data = InsetNote::params2string(p); + break; + } + case PHANTOM_CODE: { + InsetPhantomParams p; + data = InsetPhantom::params2string(p); + break; + } + case SPACE_CODE: { + InsetSpaceParams p; + data = InsetSpace::params2string(p); + break; + } + case VSPACE_CODE: { + VSpace space; + data = InsetVSpace::params2string(space); + break; + } + case WRAP_CODE: { + InsetWrapParams p; + data = InsetWrap::params2string(p); + break; + } + default: + return false; + } // end switch(code) + return true; +} + } // namespace lyx diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index a4dd7c3340..e8f18bbf0c 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -120,6 +120,9 @@ private: mutable RenderButton button_; }; +/// Decode InsetCommand considering Inset name and data. +bool decodeInsetParam(std::string const & name, std::string & data, + Buffer const & buffer); } // namespace lyx