Remove the name parameter from string2params and params2string. We can always derive the name with insetName(params.code()).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35891 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Vincent van Ravesteijn 2010-10-29 00:25:28 +00:00
parent e313d3a12b
commit c5b9664476
27 changed files with 62 additions and 73 deletions

View File

@ -1846,7 +1846,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
icp["key"] = from_utf8(arg);
if (!opt1.empty())
icp["before"] = from_utf8(opt1);
string icstr = InsetCommand::params2string("citation", icp);
string icstr = InsetCommand::params2string(icp);
FuncRequest fr(LFUN_INSET_INSERT, icstr);
lyx::dispatch(fr);
break;

View File

@ -1560,7 +1560,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
}
p["target"] = (cmd.argument().empty()) ?
content : cmd.argument();
string const data = InsetCommand::params2string("href", p);
string const data = InsetCommand::params2string(p);
if (p["target"].empty()) {
bv->showDialog("href", data);
} else {
@ -1576,7 +1576,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
p["name"] = (cmd.argument().empty()) ?
cur.getPossibleLabel() :
cmd.argument();
string const data = InsetCommand::params2string("label", p);
string const data = InsetCommand::params2string(p);
if (cmd.argument().empty()) {
bv->showDialog("label", data);
@ -1692,7 +1692,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
else
p["symbol"] = cmd.argument();
string const data = InsetCommand::params2string("nomenclature", p);
string const data = InsetCommand::params2string(p);
bv->showDialog("nomenclature", data);
break;
}
@ -1703,7 +1703,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
p["type"] = from_ascii("idx");
else
p["type"] = cmd.argument();
string const data = InsetCommand::params2string("index_print", p);
string const data = InsetCommand::params2string(p);
FuncRequest fr(LFUN_INSET_INSERT, data);
dispatch(cur, fr);
break;

View File

@ -219,19 +219,19 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
case BIBITEM_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetBibitem(buf, icp);
}
case BIBTEX_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetBibtex(buf, icp);
}
case CITE_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetCitation(buf, icp);
}
@ -259,13 +259,13 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
case HYPERLINK_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetHyperlink(buf, icp);
}
case INCLUDE_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetInclude(buf, icp);
}
@ -276,19 +276,19 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
case INDEX_PRINT_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetPrintIndex(buf, icp);
}
case LABEL_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetLabel(buf, icp);
}
case LINE_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetLine(buf, icp);
}
@ -300,13 +300,13 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
case NOMENCL_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetNomencl(buf, icp);
}
case REF_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetRef(buf, icp);
}
@ -318,7 +318,7 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
case TOC_CODE: {
InsetCommandParams icp(code);
InsetCommand::string2params(name, to_utf8(cmd.argument()), icp);
InsetCommand::string2params(to_utf8(cmd.argument()), icp);
return new InsetTOC(buf, icp);
}

View File

@ -49,7 +49,7 @@ docstring GuiBibitem::dialogToParams() const
InsetCommandParams params(insetCode());
params["key"] = qstring_to_ucs4(keyED->text());
params["label"] = qstring_to_ucs4(labelED->text());
return from_utf8(InsetCommand::params2string("bibitem", params));
return from_utf8(InsetCommand::params2string(params));
}

View File

@ -547,14 +547,14 @@ QString GuiBibtex::styleFile() const
bool GuiBibtex::initialiseParams(std::string const & data)
{
InsetCommand::string2params("bibtex", data, params_);
InsetCommand::string2params(data, params_);
return true;
}
void GuiBibtex::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("bibtex", params_);
std::string const lfun = InsetCommand::params2string(params_);
dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -622,7 +622,7 @@ void GuiCitation::setCitedKeys()
bool GuiCitation::initialiseParams(string const & data)
{
InsetCommand::string2params("citation", data, params_);
InsetCommand::string2params(data, params_);
CiteEngine const engine = buffer().params().citeEngine();
citeStyles_ = citeStyles(engine);
init();
@ -748,7 +748,7 @@ vector<docstring> GuiCitation::searchKeys(BiblioInfo const & bi,
void GuiCitation::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("citation", params_);
std::string const lfun = InsetCommand::params2string(params_);
dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -81,8 +81,7 @@ docstring GuiHyperlink::dialogToParams() const
else if (fileRB->isChecked())
params["type"] = qstring_to_ucs4("file:");
params.setCmdName("href");
return from_ascii(InsetHyperlink::params2string("href", params));
return from_ascii(InsetHyperlink::params2string(params));
}

View File

@ -335,7 +335,7 @@ QString GuiInclude::browse(QString const & in_name, Type in_type) const
bool GuiInclude::initialiseParams(std::string const & data)
{
InsetCommand::string2params("include", data, params_);
InsetCommand::string2params(data, params_);
paramsToDialog(params_);
return true;
}
@ -343,7 +343,7 @@ bool GuiInclude::initialiseParams(std::string const & data)
void GuiInclude::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("include", params_);
std::string const lfun = InsetCommand::params2string(params_);
dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -54,14 +54,14 @@ docstring GuiLabel::dialogToParams() const
{
InsetCommandParams params(insetCode());
params["name"] = qstring_to_ucs4(keywordED->text());
return from_ascii(InsetLabel::params2string("label", params));
return from_ascii(InsetLabel::params2string(params));
}
bool GuiLabel::initialiseParams(std::string const & data)
{
InsetCommandParams p(insetCode());
if (!InsetCommand::string2params("label", data, p))
if (!InsetCommand::string2params(data, p))
return false;
keywordED->setText(toqstr(p["name"]));
return true;

View File

@ -77,7 +77,7 @@ docstring GuiLine::dialogToParams() const
params["width"] = from_utf8(widgetsToLength(WidthLE, WidthUnitCO));
params["height"] = from_utf8(widgetsToLength(HeightLE, HeightUnitCO));
params.setCmdName("rule");
return from_ascii(InsetLine::params2string("line", params));
return from_ascii(InsetLine::params2string(params));
}

View File

@ -56,7 +56,7 @@ docstring GuiNomenclature::dialogToParams() const
QString description = descriptionTE->toPlainText();
description.replace('\n',"\\\\");
params["description"] = qstring_to_ucs4(description);
return from_ascii(InsetNomencl::params2string("nomenclature", params));
return from_ascii(InsetNomencl::params2string(params));
}

View File

@ -138,7 +138,7 @@ bool GuiPrintNomencl::isValid() const
bool GuiPrintNomencl::initialiseParams(std::string const & data)
{
InsetCommand::string2params("nomencl_print", data, params_);
InsetCommand::string2params(data, params_);
paramsToDialog(params_);
return true;
}
@ -146,7 +146,7 @@ bool GuiPrintNomencl::initialiseParams(std::string const & data)
void GuiPrintNomencl::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("nomencl_print", params_);
std::string const lfun = InsetCommand::params2string(params_);
dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -113,7 +113,7 @@ bool GuiPrintindex::initialiseParams(string const & data)
{
// The name passed with LFUN_INSET_APPLY is also the name
// used to identify the mailer.
InsetCommand::string2params("index_print", data, params_);
InsetCommand::string2params(data, params_);
paramsToDialog(params_);
return true;
}
@ -121,7 +121,7 @@ bool GuiPrintindex::initialiseParams(string const & data)
void GuiPrintindex::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("index_print", params_);
std::string const lfun = InsetCommand::params2string(params_);
dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -496,14 +496,14 @@ void GuiRef::filterLabels()
bool GuiRef::initialiseParams(std::string const & data)
{
InsetCommand::string2params("ref", data, params_);
InsetCommand::string2params(data, params_);
return true;
}
void GuiRef::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("ref", params_);
std::string const lfun = InsetCommand::params2string(params_);
dispatch(FuncRequest(getLfun(), lfun));
}

View File

@ -1389,7 +1389,7 @@ void MenuDefinition::expandIndicesContext(Buffer const * buf, bool listof)
if (listof) {
InsetCommandParams p(INDEX_PRINT_CODE);
p["type"] = cit->shortcut();
string const data = InsetCommand::params2string("index_print", p);
string const data = InsetCommand::params2string(p);
addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(cit->index()),
FuncRequest(LFUN_INSET_MODIFY, data)));
} else {

View File

@ -116,7 +116,7 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetCommandParams p(BIBITEM_CODE);
InsetCommand::string2params("bibitem", to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
cur.noScreenUpdate();
break;

View File

@ -88,8 +88,7 @@ void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetCommandParams p(BIBTEX_CODE);
try {
if (!InsetCommand::string2params("bibtex",
to_utf8(cmd.argument()), p)) {
if (!InsetCommand::string2params(to_utf8(cmd.argument()), p)) {
cur.noScreenUpdate();
break;
}

View File

@ -152,7 +152,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
break;
}
InsetCommandParams p(p_.code());
InsetCommand::string2params(mailer_name_, to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (p.getCmdName().empty())
cur.noScreenUpdate();
else
@ -166,7 +166,7 @@ void InsetCommand::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_DIALOG_UPDATE: {
string const name = to_utf8(cmd.argument());
cur.bv().updateDialog(name, params2string(name, params()));
cur.bv().updateDialog(name, params2string(params()));
break;
}
@ -216,14 +216,13 @@ docstring InsetCommand::contextMenu(BufferView const &, int, int) const
bool InsetCommand::showInsetDialog(BufferView * bv) const
{
if (!mailer_name_.empty())
bv->showDialog(mailer_name_, params2string(mailer_name_, p_),
bv->showDialog(mailer_name_, params2string(p_),
const_cast<InsetCommand *>(this));
return true;
}
// FIXME This could take an InsetCode instead of a string
bool InsetCommand::string2params(string const & name, string const & data,
bool InsetCommand::string2params(string const & data,
InsetCommandParams & params)
{
params.clear();
@ -232,6 +231,7 @@ bool InsetCommand::string2params(string const & name, string const & data,
// This happens when inset-insert is called without argument except for the
// inset type; ex:
// "inset-insert toc"
string const name = insetName(params.code());
if (data == name)
return true;
istringstream dstream(data);
@ -245,12 +245,10 @@ bool InsetCommand::string2params(string const & name, string const & data,
}
// FIXME This could take an InsetCode instead of a string
string InsetCommand::params2string(string const & name,
InsetCommandParams const & params)
string InsetCommand::params2string(InsetCommandParams const & params)
{
ostringstream data;
data << name << ' ';
data << insetName(params.code()) << ' ';
params.write(data);
data << "\\end_inset\n";
return data.str();
@ -273,7 +271,7 @@ bool decodeInsetParam(string const & name, string & data,
case TOC_CODE:
case HYPERLINK_CODE: {
InsetCommandParams p(code);
data = InsetCommand::params2string(name, p);
data = InsetCommand::params2string(p);
break;
}
case INCLUDE_CODE: {
@ -283,7 +281,7 @@ bool decodeInsetParam(string const & name, string & data,
// default type is requested
data = "include";
InsetCommandParams p(INCLUDE_CODE, data);
data = InsetCommand::params2string("include", p);
data = InsetCommand::params2string(p);
break;
}
case BOX_CODE: {
@ -299,7 +297,7 @@ bool decodeInsetParam(string const & name, string & data,
}
case CITE_CODE: {
InsetCommandParams p(CITE_CODE);
data = InsetCommand::params2string(name, p);
data = InsetCommand::params2string(p);
break;
}
case ERT_CODE: {

View File

@ -46,14 +46,11 @@ public:
///
InsetCommand const * asInsetCommand() const { return this; }
/// \return true if params are successfully read
static bool string2params(std::string const & name,
std::string const & data,
static bool string2params(std::string const & data,
InsetCommandParams &);
///
static std::string params2string(std::string const & name,
InsetCommandParams const &);
static std::string params2string(InsetCommandParams const &);
///
InsetCommandParams const & params() const { return p_; }
///

View File

@ -245,7 +245,7 @@ void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
InsetCommand::doDispatch(cur, cmd);
p = params();
} else
InsetCommand::string2params("include", to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (!p.getCmdName().empty()) {
if (isListings(p)){
InsetListingsParams new_params(to_utf8(p["lstparams"]));

View File

@ -493,8 +493,7 @@ void InsetPrintIndex::doDispatch(Cursor & cur, FuncRequest & cmd)
}
InsetCommandParams p(INDEX_PRINT_CODE);
// FIXME UNICODE
InsetCommand::string2params("index_print",
to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
cur.noScreenUpdate();
break;
@ -527,8 +526,7 @@ bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
} if (cmd.getArg(0) == "index_print"
&& cmd.getArg(1) == "CommandInset") {
InsetCommandParams p(INDEX_PRINT_CODE);
InsetCommand::string2params("index_print",
to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (suffixIs(p.getCmdName(), '*')) {
status.setEnabled(true);
status.setOnOff(false);

View File

@ -192,7 +192,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetCommandParams p(LABEL_CODE);
// FIXME UNICODE
InsetCommand::string2params("label", to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
cur.noScreenUpdate();
break;
@ -214,7 +214,7 @@ void InsetLabel::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_LABEL_INSERT_AS_REF: {
InsetCommandParams p(REF_CODE, "ref");
p["reference"] = getParam("name");
string const data = InsetCommand::params2string("ref", p);
string const data = InsetCommand::params2string(p);
lyx::dispatch(FuncRequest(LFUN_INSET_INSERT, data));
break;
}

View File

@ -71,8 +71,7 @@ void InsetLine::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetCommandParams p(LINE_CODE);
// FIXME UNICODE
InsetCommand::string2params("line",
to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
cur.noScreenUpdate();
break;

View File

@ -169,8 +169,7 @@ void InsetPrintNomencl::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetCommandParams p(NOMENCL_PRINT_CODE);
// FIXME UNICODE
InsetCommand::string2params("nomencl_print",
to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
if (p.getCmdName().empty()) {
cur.noScreenUpdate();
break;

View File

@ -1318,7 +1318,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
InsetCommandParams p(LABEL_CODE);
p["name"] = cmd.argument().empty() ? old_label : cmd.argument();
string const data = InsetCommand::params2string("label", p);
string const data = InsetCommand::params2string(p);
if (cmd.argument().empty())
cur.bv().showDialog("label", data);
@ -1382,7 +1382,7 @@ void InsetMathHull::doDispatch(Cursor & cur, FuncRequest & cmd)
string const name = cmd.getArg(0);
if (name == "label") {
InsetCommandParams p(LABEL_CODE);
InsetCommand::string2params(name, to_utf8(cmd.argument()), p);
InsetCommand::string2params(to_utf8(cmd.argument()), p);
docstring str = p["name"];
cur.recordUndoInset();
row_type const r = (type_ == hullMultline) ? nrows() - 1 : cur.row();

View File

@ -187,13 +187,13 @@ void InsetMathRef::updateBuffer(ParIterator const & it, UpdateType /*utype*/)
}
string const InsetMathRef::createDialogStr(string const & name) const
string const InsetMathRef::createDialogStr(string const & /*name*/) const
{
InsetCommandParams icp(REF_CODE, to_ascii(commandname()));
icp["reference"] = asString(cell(0));
if (!cell(1).empty())
icp["name"] = asString(cell(1));
return InsetCommand::params2string(name, icp);
return InsetCommand::params2string(icp);
}
@ -212,7 +212,7 @@ void InsetMathRef::changeTarget(docstring const & target)
MathData ar;
Buffer & buf = buffer();
if (createInsetMath_fromDialogStr(
from_utf8(InsetCommand::params2string("ref", icp)), ar)) {
from_utf8(InsetCommand::params2string(icp)), ar)) {
*this = *ar[0].nucleus()->asRefInset();
// FIXME audit setBuffer calls
setBuffer(buf);

View File

@ -520,7 +520,7 @@ bool createInsetMath_fromDialogStr(docstring const & str, MathData & ar)
if (name == "ref") {
InsetCommandParams icp(REF_CODE);
// FIXME UNICODE
InsetCommand::string2params("ref", to_utf8(str), icp);
InsetCommand::string2params(to_utf8(str), icp);
Encoding const * const utf8 = encodings.fromLyXName("utf8");
OutputParams op(utf8);
mathed_parse_cell(ar, icp.getCommand(op));