Transfer LFUN_DIALOG_SHOW_NEW_INSET to BufferView and put InsetCommand related code to new function decodeInsetParam() in InsetCommand.cpp.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31468 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2009-09-26 17:19:18 +00:00
parent 3f371011f9
commit 09f96833bf
4 changed files with 131 additions and 120 deletions

View File

@ -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;
}

View File

@ -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()) {

View File

@ -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

View File

@ -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