X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCommandParams.cpp;h=bb4882874af1b0220dba13776023ab8e34f1250e;hb=2906a35663b92030b0668a42ab370dba8ffca4cf;hp=608bc883c58100da7b1678030e8e1db3e8716c20;hpb=1178b30c542266a42e91e46900825a0722049623;p=lyx.git diff --git a/src/insets/InsetCommandParams.cpp b/src/insets/InsetCommandParams.cpp index 608bc883c5..bb4882874a 100644 --- a/src/insets/InsetCommandParams.cpp +++ b/src/insets/InsetCommandParams.cpp @@ -23,6 +23,7 @@ #include "InsetInclude.h" #include "InsetIndex.h" #include "InsetLabel.h" +#include "InsetLine.h" #include "InsetNomencl.h" #include "InsetRef.h" #include "InsetTOC.h" @@ -70,6 +71,8 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName) return InsetPrintIndex::findInfo(cmdName); case LABEL_CODE: return InsetLabel::findInfo(cmdName); + case LINE_CODE: + return InsetLine::findInfo(cmdName); case NOMENCL_CODE: return InsetNomencl::findInfo(cmdName); case NOMENCL_PRINT_CODE: @@ -81,7 +84,7 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName) default: LASSERT(false, /**/); } - static const ParamInfo pi; + static ParamInfo pi; return pi; // to silence the warning } @@ -200,6 +203,8 @@ string InsetCommandParams::getDefaultCmd(InsetCode code) return InsetPrintIndex::defaultCommand(); case LABEL_CODE: return InsetLabel::defaultCommand(); + case LINE_CODE: + return InsetLine::defaultCommand(); case NOMENCL_CODE: return InsetNomencl::defaultCommand(); case NOMENCL_PRINT_CODE: @@ -234,6 +239,8 @@ bool InsetCommandParams::isCompatibleCommand(InsetCode code, string const & s) return InsetPrintIndex::isCompatibleCommand(s); case LABEL_CODE: return InsetLabel::isCompatibleCommand(s); + case LINE_CODE: + return InsetLine::isCompatibleCommand(s); case NOMENCL_CODE: return InsetNomencl::isCompatibleCommand(s); case NOMENCL_PRINT_CODE: @@ -251,7 +258,7 @@ bool InsetCommandParams::isCompatibleCommand(InsetCode code, string const & s) void InsetCommandParams::setCmdName(string const & name) { - if (!isCompatibleCommand(insetCode_, cmdName_)) { + if (!isCompatibleCommand(insetCode_, name)) { LYXERR0("InsetCommand: Incompatible command name " << name << "."); throw ExceptionMessage(WarningException, _("InsetCommand Error: "), @@ -358,17 +365,25 @@ bool InsetCommandParams::writeEmptyOptional(ParamInfo::const_iterator ci) const } - docstring InsetCommandParams::prepareCommand(OutputParams const & runparams, docstring const & command, ParamInfo::ParamHandling handling) const { docstring result; - if (handling == ParamInfo::HANDLING_LATEXIFY) { + switch (handling) { + case ParamInfo::HANDLING_LATEXIFY: { docstring uncodable; for (size_t n = 0; n < command.size(); ++n) { try { - result += runparams.encoding->latexChar(command[n]); + char_type const c = command[n]; + docstring const latex = runparams.encoding->latexChar(c); + result += latex; + if (latex.length() > 1 && latex[latex.length() - 1] != '}') { + // Prevent eating of a following + // space or command corruption by + // following characters + result += "{}"; + } } catch (EncodingException & /* e */) { LYXERR0("Uncodable character in command inset!"); if (runparams.dryrun) { @@ -384,14 +399,19 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams, // issue a warning about omitted characters // FIXME: should be passed to the error dialog frontend::Alert::warning(_("Uncodable characters"), - bformat(_("The following characters that are used in an inset (%1$s) are\n" - "not representable in the current encoding and have been omitted:\n%2$s."), + bformat(_("The following characters that are used in the inset %1$s are not\n" + "representable in the current encoding and therefore have been omitted:\n%2$s."), from_utf8(insetType()), uncodable)); } - } else if (handling == ParamInfo::HANDLING_ESCAPE) + break; + } + case ParamInfo::HANDLING_ESCAPE: result = escape(command); - else + break; + case ParamInfo::HANDLING_NONE: result = command; + break; + } // switch return result; } @@ -410,14 +430,14 @@ docstring InsetCommandParams::getCommand(OutputParams const & runparams) const break; case ParamInfo::LATEX_REQUIRED: { - docstring const & data = + docstring const data = prepareCommand(runparams, (*this)[name], it->handling()); s += '{' + data + '}'; noparam = false; break; } case ParamInfo::LATEX_OPTIONAL: { - docstring const & data = + docstring const data = prepareCommand(runparams, (*this)[name], it->handling()); if (!data.empty()) { s += '[' + data + ']';