InsetCommandParams() now takes an InsetCode rather than a string.

These changes are just adaptations to the new signature.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21072 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2007-10-19 17:22:55 +00:00
parent b6c89e2db0
commit e158e07c29
23 changed files with 241 additions and 238 deletions

View File

@ -1409,7 +1409,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
case REF_CODE:
case TOC_CODE:
case HYPERLINK_CODE: {
InsetCommandParams p(name);
InsetCommandParams p(code);
data = InsetCommandMailer::params2string(name, p);
break;
}
@ -1419,7 +1419,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
if (data.empty())
// default type is requested
data = "include";
InsetCommandParams p("include", data);
InsetCommandParams p(INCLUDE_CODE, data);
data = InsetIncludeMailer::params2string(p);
break;
}
@ -1435,7 +1435,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
break;
}
case CITE_CODE: {
InsetCommandParams p("cite");
InsetCommandParams p(CITE_CODE);
data = InsetCommandMailer::params2string(name, p);
break;
}
@ -1539,7 +1539,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
arg = token(argument, '|', 0);
opt1 = token(argument, '|', 1);
}
InsetCommandParams icp("cite");
InsetCommandParams icp(CITE_CODE);
icp["key"] = from_utf8(arg);
if (!opt1.empty())
icp["before"] = from_utf8(opt1);

View File

@ -2432,7 +2432,7 @@ int Paragraph::checkBiblio(bool track_changes)
//There was no inset at the beginning, so we need to create one with
//the key and label of the one we erased.
InsetBibitem * inset(new InsetBibitem(InsetCommandParams("bibitem")));
InsetBibitem * inset(new InsetBibitem(InsetCommandParams(BIBITEM_CODE)));
// restore values of previously deleted item in this par.
if (!oldkey.empty())
inset->setParam("key", oldkey);

View File

@ -1060,7 +1060,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
case LFUN_HYPERLINK_INSERT: {
InsetCommandParams p("href");
InsetCommandParams p(HYPERLINK_CODE);
docstring content;
if (cur.selection()) {
content = cur.selectionAsString(false);
@ -1079,7 +1079,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
case LFUN_LABEL_INSERT: {
InsetCommandParams p("label");
InsetCommandParams p(LABEL_CODE);
// Try to generate a valid label
p["name"] = (cmd.argument().empty()) ?
cur.getPossibleLabel() :

View File

@ -147,7 +147,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
return new InsetOptArg(params);
case LFUN_BIBITEM_INSERT:
return new InsetBibitem(InsetCommandParams("bibitem"));
return new InsetBibitem(InsetCommandParams(BIBITEM_CODE));
case LFUN_FLOAT_INSERT: {
// check if the float type exists
@ -182,7 +182,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
return new InsetIndex(params);
case LFUN_NOMENCL_INSERT: {
InsetCommandParams icp("nomenclature");
InsetCommandParams icp(NOMENCL_CODE);
icp["symbol"] = cmd.argument().empty() ?
bv->cursor().innerText()->getStringToIndex(bv->cursor()) :
cmd.argument();
@ -211,13 +211,13 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
}
case LFUN_INDEX_PRINT:
return new InsetPrintIndex(InsetCommandParams("index_print"));
return new InsetPrintIndex(InsetCommandParams(INDEX_PRINT_CODE));
case LFUN_NOMENCL_PRINT:
return new InsetPrintNomencl(InsetCommandParams("nomencl_print"));
return new InsetPrintNomencl(InsetCommandParams(NOMENCL_PRINT_CODE));
case LFUN_TOC_INSERT:
return new InsetTOC(InsetCommandParams("toc"));
return new InsetTOC(InsetCommandParams(TOC_CODE));
case LFUN_ENVIRONMENT_INSERT:
return new InsetEnvironment(params, cmd.argument());
@ -237,103 +237,104 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
lyxerr << "No such inset '" << name << "'.";
return 0;
case BIBITEM_CODE: {
InsetCommandParams icp(name);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetBibitem(icp);
}
case BIBITEM_CODE: {
InsetCommandParams icp(code);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetBibitem(icp);
}
case BIBTEX_CODE: {
InsetCommandParams icp(name);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetBibtex(icp);
}
case BIBTEX_CODE: {
InsetCommandParams icp(code);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetBibtex(icp);
}
case CITE_CODE: {
InsetCommandParams icp("citation");
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetCitation(icp);
}
case CITE_CODE: {
InsetCommandParams icp(code);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetCitation(icp);
}
case ERT_CODE: {
InsetCollapsable::CollapseStatus st;
InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
return new InsetERT(params, st);
}
case ERT_CODE: {
InsetCollapsable::CollapseStatus st;
InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
return new InsetERT(params, st);
}
case LISTINGS_CODE: {
InsetListingsParams par;
InsetListingsMailer::string2params(to_utf8(cmd.argument()), par);
return new InsetListings(params, par);
}
case LISTINGS_CODE: {
InsetListingsParams par;
InsetListingsMailer::string2params(to_utf8(cmd.argument()), par);
return new InsetListings(params, par);
}
case EXTERNAL_CODE: {
Buffer const & buffer = bv->buffer();
InsetExternalParams iep;
InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, iep);
auto_ptr<InsetExternal> inset(new InsetExternal);
inset->setParams(iep, buffer);
return inset.release();
}
case EXTERNAL_CODE: {
Buffer const & buffer = bv->buffer();
InsetExternalParams iep;
InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, iep);
auto_ptr<InsetExternal> inset(new InsetExternal);
inset->setParams(iep, buffer);
return inset.release();
}
case GRAPHICS_CODE: {
Buffer const & buffer = bv->buffer();
InsetGraphicsParams igp;
InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, igp);
auto_ptr<InsetGraphics> inset(new InsetGraphics);
inset->setParams(igp);
return inset.release();
}
case GRAPHICS_CODE: {
Buffer const & buffer = bv->buffer();
InsetGraphicsParams igp;
InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, igp);
auto_ptr<InsetGraphics> inset(new InsetGraphics);
inset->setParams(igp);
return inset.release();
}
case HYPERLINK_CODE: {
InsetCommandParams icp(name);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetHyperlink(icp);
}
case HYPERLINK_CODE: {
InsetCommandParams icp(code);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetHyperlink(icp);
}
case INCLUDE_CODE: {
InsetCommandParams iip(name);
InsetIncludeMailer::string2params(to_utf8(cmd.argument()), iip);
return new InsetInclude(iip);
}
case INCLUDE_CODE: {
InsetCommandParams iip(code);
InsetIncludeMailer::string2params(to_utf8(cmd.argument()), iip);
return new InsetInclude(iip);
}
case INDEX_CODE:
return new InsetIndex(params);
case NOMENCL_CODE: {
InsetCommandParams icp(name);
InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), icp);
return new InsetNomencl(icp);
}
case NOMENCL_CODE: {
InsetCommandParams icp(code);
InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), icp);
return new InsetNomencl(icp);
}
case LABEL_CODE: {
InsetCommandParams icp(name);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetLabel(icp);
}
case LABEL_CODE: {
InsetCommandParams icp(code);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetLabel(icp);
}
case REF_CODE: {
InsetCommandParams icp(name);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetRef(icp, bv->buffer());
}
case REF_CODE: {
InsetCommandParams icp(code);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetRef(icp, bv->buffer());
}
case TOC_CODE: {
InsetCommandParams icp("toc");
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetTOC(icp);
}
case TOC_CODE: {
InsetCommandParams icp(code);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
return new InsetTOC(icp);
}
case VSPACE_CODE: {
VSpace vspace;
InsetVSpaceMailer::string2params(to_utf8(cmd.argument()), vspace);
return new InsetVSpace(vspace);
}
case VSPACE_CODE: {
VSpace vspace;
InsetVSpaceMailer::string2params(to_utf8(cmd.argument()), vspace);
return new InsetVSpace(vspace);
}
default:
lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT."
<< std::endl;
return 0;
default:
lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT."
<< std::endl;
return 0;
}
} //end LFUN_INSET_INSERT
@ -417,7 +418,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
//we do not know in advance that we're dealing with a command inset.
//Worst case, we could put it in each case below. Better, we could
//pass the lexer to the constructor and let the params be built there.
InsetCommandParams inscmd(insetType);
InsetCommandParams inscmd(code);
inscmd.read(lex);
switch (code) {
@ -499,7 +500,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
InsetBranchParams()));
} else if (tmptok == "Include") {
//FIXME
InsetCommandParams p("include");
InsetCommandParams p(INCLUDE_CODE);
inset.reset(new InsetInclude(p));
} else if (tmptok == "Environment") {
lex.next();

View File

@ -270,7 +270,7 @@ namespace lyx {
namespace frontend {
GuiCommand::GuiCommand(LyXView & lv, string const & name)
: GuiDialog(lv, name), params_(name), lfun_name_(name)
: GuiDialog(lv, name), params_(insetCode(name)), lfun_name_(name)
{
}

View File

@ -60,7 +60,7 @@ using support::getVectorFromString;
GuiInclude::GuiInclude(LyXView & lv)
: GuiDialog(lv, "include"), params_("include")
: GuiDialog(lv, "include"), params_(INCLUDE_CODE)
{
setupUi(this);
setViewTitle(_("Child Document"));

View File

@ -52,7 +52,7 @@ using support::makeDisplayPath;
static std::string const lfun_name_ = "ref";
GuiRef::GuiRef(LyXView & lv)
: GuiDialog(lv, "ref"), params_("ref")
: GuiDialog(lv, "ref"), params_(REF_CODE)
{
setupUi(this);
setViewTitle(_("Cross-reference"));

View File

@ -44,7 +44,7 @@ namespace lyx {
namespace frontend {
GuiToc::GuiToc(GuiViewBase & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
: DockView(parent, "toc", area, flags), params_("toc")
: DockView(parent, "toc", area, flags), params_(TOC_CODE)
{
widget_ = new TocWidget(*this);
setWidget(widget_);

View File

@ -139,6 +139,20 @@ InsetCode insetCode(std::string const & name)
}
std::string insetName(InsetCode c)
{
static TranslatorMap const translator = build_translator();
TranslatorMap::const_iterator it = translator.begin();
TranslatorMap::const_iterator end = translator.end();
for (; it != end; ++it) {
if (it->second == c)
return it->first;
}
return std::string();
}
void Inset::dispatch(Cursor & cur, FuncRequest & cmd)
{
cur.updateFlags(Update::Force | Update::FitCursor);

View File

@ -59,7 +59,7 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetCommandParams p("bibitem");
InsetCommandParams p(BIBITEM_CODE);
InsetCommandMailer::string2params("bibitem", to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
cur.noUpdate();

View File

@ -89,7 +89,7 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetCommandParams p("bibtex");
InsetCommandParams p(BIBTEX_CODE);
try {
if (!InsetCommandMailer::string2params("bibtex",
to_utf8(cmd.argument()), p)) {

View File

@ -15,6 +15,7 @@
#include "InsetCommand.h"
#include "InsetCode.h"
#include "BiblioInfo.h"
@ -63,7 +64,7 @@ private:
class Cache {
public:
///
Cache() : engine(biblio::ENGINE_BASIC), params("citation") {}
Cache() : engine(biblio::ENGINE_BASIC), params(CITE_CODE) {}
///
biblio::CiteEngine engine;
///

View File

@ -112,7 +112,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
break;
case LFUN_INSET_MODIFY: {
InsetCommandParams p(p_.insetType());
InsetCommandParams p(p_.code());
InsetCommandMailer::string2params(mailer_name_, to_utf8(cmd.argument()), p);
if (p.getCmdName().empty())
cur.noUpdate();
@ -187,6 +187,7 @@ string const InsetCommandMailer::inset2string(Buffer const &) const
}
//FIXME This could take an InsetCode instead of a string
bool InsetCommandMailer::string2params(
string const & name, string const & in, InsetCommandParams & params)
{
@ -219,6 +220,7 @@ bool InsetCommandMailer::string2params(
}
//FIXME This could take an InsetCode instead of a string
string const
InsetCommandMailer::params2string(string const & name,
InsetCommandParams const & params)

View File

@ -35,24 +35,21 @@ using support::ExceptionMessage;
using support::WarningException;
//FIXME There is no reason now for this to take a string argument.
//It'd be much more robust if it took an InsetCode, since then
//the compiler would do some checking for us.
InsetCommandParams::InsetCommandParams(string const & insetType)
: insetType_(insetType), preview_(false)
InsetCommandParams::InsetCommandParams(InsetCode code)
: insetCode_(code), preview_(false)
{
cmdName_ = getDefaultCmd(insetType);
info_ = findInfo(insetType, cmdName_);
cmdName_ = getDefaultCmd(code);
info_ = findInfo(code, cmdName_);
BOOST_ASSERT(info_);
params_.resize(info_->n);
}
InsetCommandParams::InsetCommandParams(string const & insetType,
InsetCommandParams::InsetCommandParams(InsetCode code,
string const & cmdName)
: insetType_(insetType), cmdName_(cmdName), preview_(false)
: insetCode_(code), cmdName_(cmdName), preview_(false)
{
info_ = findInfo(insetType, cmdName);
info_ = findInfo(code, cmdName);
BOOST_ASSERT(info_);
params_.resize(info_->n);
}
@ -64,30 +61,26 @@ InsetCommandParams::InsetCommandParams(string const & insetType,
//a reason to use it in some cases? What should happen in the single
//arg case, then? Maybe use the default? or leave that up to the inset?
InsetCommandParams::CommandInfo const *
InsetCommandParams::findInfo(std::string const & insetType)
InsetCommandParams::findInfo(InsetCode code)
{
// No parameter may be named "preview", because that is a required
// flag for all commands.
// InsetBibitem
if (insetType == "bibitem") {
switch (code) {
case BIBITEM_CODE: {
static const char * const paramnames[] = {"label", "key", ""};
static const bool isoptional[] = {true, false};
static const CommandInfo info = {2, paramnames, isoptional};
return &info;
}
// InsetBibtex
if (insetType == "bibtex") {
case BIBTEX_CODE: {
static const char * const paramnames[] =
{"options", "btprint", "bibfiles", ""};
static const bool isoptional[] = {true, true, false};
static const CommandInfo info = {3, paramnames, isoptional};
return &info;
}
// InsetCitation
if (insetType == "citation") {
case CITE_CODE: {
// standard cite does only take one argument if jurabib is
// not used, but jurabib extends this to two arguments, so
// we have to allow both here. InsetCitation takes care that
@ -98,127 +91,115 @@ InsetCommandParams::findInfo(std::string const & insetType)
static const CommandInfo info = {3, paramnames, isoptional};
return &info;
}
// InsetFloatlist
if (insetType == "floatlist") {
case FLOAT_LIST_CODE: {
static const char * const paramnames[] = {"type", ""};
static const bool isoptional[] = {false};
static const CommandInfo info = {1, paramnames, isoptional};
return &info;
}
// InsetHfill
if (insetType == "hfill") {
case HFILL_CODE: {
static const char * const paramnames[] = {""};
static const CommandInfo info = {0, paramnames, 0};
return &info;
}
// InsetHyperlink
if (insetType == "href") {
case HYPERLINK_CODE: {
static const char * const paramnames[] =
{"name", "target", ""};
static const bool isoptional[] = {true, false};
static const CommandInfo info = {2, paramnames, isoptional};
return &info;
}
// InsetInclude
//FIXME This is really correct only for lstinputlistings, but it shouldn't
//cause a problem before we get things sorted out. Eventually, this calls
//InsetInclude::getParams(cmdName_), or something of the sort.
if (insetType == "include") {
case INCLUDE_CODE: {
//This is only correct for the case of listings, but it'll do for now.
//In the other cases, this second parameter should just be empty.
static const char * const paramnames[] = {"filename", "lstparams", ""};
static const bool isoptional[] = {false, true};
static const CommandInfo info = {2, paramnames, isoptional};
return &info;
}
// InsetIndex, InsetPrintIndex, InsetLabel
if (insetType == "index" || insetType == "index_print" || insetType == "label") {
case INDEX_CODE:
case INDEX_PRINT_CODE:
case LABEL_CODE: {
static const char * const paramnames[] = {"name", ""};
static const bool isoptional[] = {false};
static const CommandInfo info = {1, paramnames, isoptional};
return &info;
}
// InsetNomencl
if (insetType == "nomenclature") {
case NOMENCL_CODE: {
static const char * const paramnames[] = {"prefix", "symbol", "description", ""};
static const bool isoptional[] = {true, false, false};
static const CommandInfo info = {3, paramnames, isoptional};
return &info;
}
// InsetPrintNomencl
if (insetType == "nomencl_print") {
case NOMENCL_PRINT_CODE: {
static const char * const paramnames[] = {"labelwidth", ""};
static const bool isoptional[] = {true};
static const CommandInfo info = {1, paramnames, isoptional};
return &info;
}
// InsetRef
if (insetType == "ref") {
case REF_CODE: {
static const char * const paramnames[] =
{"name", "reference", ""};
static const bool isoptional[] = {true, false};
static const CommandInfo info = {2, paramnames, isoptional};
return &info;
}
// InsetTOC
if (insetType == "toc") {
case TOC_CODE: {
static const char * const paramnames[] = {"type", ""};
static const bool isoptional[] = {false};
static const CommandInfo info = {1, paramnames, isoptional};
return &info;
}
default:
BOOST_ASSERT(false);
}
return 0;
}
//FIXME Will eventually call a static method, etc.
InsetCommandParams::CommandInfo const *
InsetCommandParams::findInfo(std::string const & insetType,
std::string const & cmdName)
InsetCommandParams::findInfo(InsetCode code,
std::string const &/* cmdName*/)
{
return findInfo(insetType);
return findInfo(code);
}
//FIXME Should call InsetBibitem::getDefaultCmd(), eg
std::string InsetCommandParams::getDefaultCmd(std::string insetType) {
if (insetType == "bibitem")
return "bibitem";
if (insetType == "bibtex")
return "bibtex"; //this is an unused dummy
if (insetType == "citation")
return "cite";
if (insetType == "floatlist")
return "listoftables";
if (insetType == "hfill")
return "hfill";
if (insetType == "href")
return "href";
if (insetType == "include")
return "include";
if (insetType == "index")
return "index";
if (insetType == "index_print")
return "print_index";
if (insetType == "label")
return "label";
if (insetType == "nomenclature")
return "nomenclature";
if (insetType == "nomencl_print")
return "printnomenclature";
if (insetType == "ref")
return "ref";
if (insetType == "toc")
return "tableofcontents";
BOOST_ASSERT(false);
std::string InsetCommandParams::getDefaultCmd(InsetCode code) {
switch (code) {
case BIBITEM_CODE:
return "bibitem";
case BIBTEX_CODE:
return "bibtex"; //this is an unused dummy
case CITE_CODE:
return "cite";
case FLOAT_LIST_CODE:
return "listoftables";
case HFILL_CODE:
return "hfill";
case HYPERLINK_CODE:
return "href";
case INCLUDE_CODE:
return "include";
case INDEX_CODE:
return "index";
case INDEX_PRINT_CODE:
return "print_index";
case LABEL_CODE:
return "label";
case NOMENCL_CODE:
return "nomenclature";
case NOMENCL_PRINT_CODE:
return "printnomenclature";
case REF_CODE:
return "ref";
case TOC_CODE:
return "tableofcontents";
default:
BOOST_ASSERT(false);
}
return "";
}
@ -227,9 +208,12 @@ void InsetCommandParams::setCmdName(string const & name)
{
//FIXME Check command compatibility
cmdName_ = name;
BOOST_ASSERT(!insetType_.empty());
CommandInfo const * const info = findInfo(insetType_, cmdName_);
BOOST_ASSERT(info);
CommandInfo const * const info = findInfo(insetCode_, cmdName_);
if (!info) {
lyxerr << "Command '" << name << "' is not compatible with a '" <<
insetType() << "' inset." << std::endl;
return;
}
ParamVector params(info->n);
// Overtake parameters with the same name
for (size_t i = 0; i < info_->n; ++i) {
@ -318,19 +302,18 @@ void InsetCommandParams::read(Lexer & lex)
//FIXME
if (lex.isOK()) {
lex.next();
string insetType = lex.getString();
if (!insetType_.empty() && insetType != insetType_) {
string const insetType = lex.getString();
InsetCode const code = insetCode(insetType);
if (code != insetCode_) {
lex.printError("InsetCommand: Attempt to change type of parameters.");
throw ExceptionMessage(WarningException, _("InsetCommand Error: "),
from_utf8("Attempt to change type of parameters."));
}
// OK, we survived...
insetType_ = insetType;
}
if (lex.isOK()) {
lex.next();
string test = lex.getString();
string const test = lex.getString();
if (test != "LatexCommand") {
lex.printError("InsetCommand: no LatexCommand line found.");
throw ExceptionMessage(WarningException, _("InsetCommand error:"),
@ -345,11 +328,11 @@ void InsetCommandParams::read(Lexer & lex)
//upon what insetType_ is.
//it's possible that should go into InsetCommand.cpp,
//or maybe it's a standalone function.
info_ = findInfo(insetType_, cmdName_);
info_ = findInfo(insetCode_, cmdName_);
if (!info_) {
lex.printError("InsetCommand: Unknown inset name `$$Token'");
throw ExceptionMessage(WarningException,
_("Unknown inset name: "), from_utf8(insetType_));
_("Unknown inset name: "), from_utf8(insetType()));
}
string token;
@ -387,7 +370,7 @@ void InsetCommandParams::read(Lexer & lex)
void InsetCommandParams::write(ostream & os) const
{
os << "CommandInset " << insetType_ << '\n';
os << "CommandInset " << insetType() << '\n';
os << "LatexCommand " << cmdName_ << '\n';
for (size_t i = 0; i < info_->n; ++i)
if (!params_[i].empty())
@ -440,7 +423,7 @@ std::string const InsetCommandParams::getOptions() const
if (info_->optional[i])
return to_utf8(params_[i]);
lyxerr << "Programming error: get nonexisting option in "
<< insetType_ << " inset." << endl;
<< insetType() << " inset." << endl;
return string();
}
@ -457,7 +440,7 @@ std::string const InsetCommandParams::getSecOptions() const
}
// Happens in InsetCitation
lyxerr << "Programming error: get nonexisting second option in "
<< insetType_ << " inset." << endl;
<< insetType() << " inset." << endl;
return string();
}
@ -480,7 +463,7 @@ void InsetCommandParams::setOptions(std::string const & o)
return;
}
lyxerr << "Programming error: set nonexisting option in "
<< insetType_ << " inset." << endl;
<< insetType() << " inset." << endl;
}
@ -498,7 +481,7 @@ void InsetCommandParams::setSecOptions(std::string const & s)
}
// Happens in InsetCitation
lyxerr << "Programming error: set nonexisting second option in "
<< insetType_ << " inset." << endl;
<< insetType() << " inset." << endl;
}
@ -539,7 +522,7 @@ void InsetCommandParams::clear()
bool operator==(InsetCommandParams const & o1,
InsetCommandParams const & o2)
{
return o1.insetType_ == o2.insetType_ &&
return o1.insetCode_ == o2.insetCode_ &&
o1.cmdName_ == o2.cmdName_ &&
o1.info_ == o2.info_ &&
o1.params_ == o2.params_ &&

View File

@ -13,6 +13,7 @@
#ifndef INSETCOMMANDPARAMS_H
#define INSETCOMMANDPARAMS_H
#include "InsetCode.h"
#include "support/docstring.h"
#include <iosfwd>
@ -25,15 +26,16 @@ class Lexer;
class InsetCommandParams {
public:
/// Construct parameters for inset \p insetType, using
/// \p insetType as default for \p cmdName_.
explicit InsetCommandParams(std::string const & insetType);
/// Construct parameters for inset \p insetType with
/// Construct parameters for inset of type \p code.
explicit InsetCommandParams(InsetCode code);
/// Construct parameters for inset of type \p code with
/// command name \p cmdName.
explicit InsetCommandParams(std::string const & insetType,
explicit InsetCommandParams(InsetCode code,
std::string const & cmdName);
///
std::string insetType() const { return insetType_; }
std::string insetType() const { return insetName(insetCode_); }
///
InsetCode code() const { return insetCode_; }
///
void read(Lexer &);
/// Parse the command
@ -82,21 +84,21 @@ private:
/// Tells whether a parameter is optional
bool const * optional;
};
/// Get information for inset type \p insetType.
/// Get information for inset type \p code.
/// Returns 0 if the inset is not known.
static CommandInfo const * findInfo(std::string const & insetType);
/// Get information for \p insetType and command \p cmdName.
static CommandInfo const * findInfo(InsetCode code);
/// Get information for \p code and command \p cmdName.
/// Returns 0 if the combination is not known.
/// Don't call this without first making sure the command name is
/// acceptable to the inset.
static CommandInfo const * findInfo(std::string const & insetType,
static CommandInfo const * findInfo(InsetCode code,
std::string const & cmdName);
///
std::string getDefaultCmd(std::string insetType);
std::string getDefaultCmd(InsetCode);
/// Description of all command properties
CommandInfo const * info_;
/// what kind of inset we're the parameters for
std::string insetType_;
InsetCode insetCode_;
/// The name of this command as it appears in .lyx and .tex files
std::string cmdName_;
///

View File

@ -38,12 +38,12 @@ using std::ostream;
InsetFloatList::InsetFloatList()
: InsetCommand(InsetCommandParams("floatlist"), "toc")
: InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
{}
InsetFloatList::InsetFloatList(string const & type)
: InsetCommand(InsetCommandParams("floatlist"), "toc")
: InsetCommand(InsetCommandParams(FLOAT_LIST_CODE), "toc")
{
setParam("type", from_ascii(type));
}

View File

@ -20,7 +20,7 @@ namespace lyx {
InsetHFill::InsetHFill()
: InsetCommand(InsetCommandParams("hfill"), std::string())
: InsetCommand(InsetCommandParams(HFILL_CODE), std::string())
{}

View File

@ -136,7 +136,7 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetCommandParams p("include");
InsetCommandParams p(INCLUDE_CODE);
InsetIncludeMailer::string2params(to_utf8(cmd.argument()), p);
if (!p.getCmdName().empty()) {
if (isListings(p)){

View File

@ -54,7 +54,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetCommandParams p("label");
InsetCommandParams p(LABEL_CODE);
// FIXME UNICODE
InsetCommandMailer::string2params("label", to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {

View File

@ -84,7 +84,7 @@ int InsetRef::latex(Buffer const &, odocstream & os,
{
// We don't want to output p_["name"], since that is only used
// in docbook. So we construct new params, without it, and use that.
InsetCommandParams p("ref", getCmdName());
InsetCommandParams p(REF_CODE, getCmdName());
p["reference"] = getParam("reference");
os << escape(p.getCommand());
return 0;

View File

@ -1095,7 +1095,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
if (old_label.empty())
old_label = default_label;
InsetCommandParams p("label");
InsetCommandParams p(LABEL_CODE);
p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
std::string const data = InsetCommandMailer::params2string("label", p);
@ -1112,7 +1112,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
//lyxerr << "arg: " << to_utf8(cmd.argument()) << endl;
std::string const name = cmd.getArg(0);
if (name == "label") {
InsetCommandParams p("label");
InsetCommandParams p(LABEL_CODE);
InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), p);
docstring str = p["name"];
cur.recordUndoInset();

View File

@ -174,7 +174,7 @@ int InsetMathRef::docbook(Buffer const & buf, odocstream & os,
string const InsetMathRef::createDialogStr(string const & name) const
{
InsetCommandParams icp(to_ascii(commandname()));
InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
icp["reference"] = asString(cell(0));
if (!cell(1).empty())
icp["name"] = asString(cell(1));

View File

@ -424,7 +424,7 @@ bool createInsetMath_fromDialogStr(docstring const & str, MathData & ar)
if (name != "ref" )
return false;
InsetCommandParams icp("ref");
InsetCommandParams icp(REF_CODE);
// FIXME UNICODE
InsetCommandMailer::string2params("ref", to_utf8(str), icp);
mathed_parse_cell(ar, icp.getCommand());