Use GuiNames for counters.

This commit is contained in:
Richard Kimberly Heck 2020-05-02 23:00:17 -04:00
parent 6580c5753d
commit 666f90cdbb
3 changed files with 38 additions and 7 deletions

View File

@ -56,12 +56,14 @@ bool Counter::read(Lexer & lex)
CT_LABELSTRING_APPENDIX,
CT_PRETTYFORMAT,
CT_INITIALVALUE,
CT_GUINAME,
CT_END
};
LexerKeyword counterTags[] = {
{ "end", CT_END },
{ "initialvalue", CT_INITIALVALUE},
{ "guiname", CT_GUINAME },
{ "initialvalue", CT_INITIALVALUE},
{ "labelstring", CT_LABELSTRING },
{ "labelstringappendix", CT_LABELSTRING_APPENDIX },
{ "prettyformat", CT_PRETTYFORMAT },
@ -112,6 +114,10 @@ bool Counter::read(Lexer & lex)
lex.next();
labelstringappendix_ = lex.getDocString();
break;
case CT_GUINAME:
lex.next();
guiname_ = lex.getDocString();
break;
case CT_END:
getout = true;
break;
@ -349,6 +355,22 @@ void Counters::step(docstring const & ctr, UpdateType utype)
}
docstring const & Counters::guiName(docstring const & cntr) const
{
CounterList::const_iterator it = counterList_.find(cntr);
if (it == counterList_.end()) {
lyxerr << "step: Counter does not exist: "
<< to_utf8(cntr) << endl;
return empty_docstring();
}
docstring const & guiname = it->second.guiName();
if (guiname.empty())
return cntr;
return guiname;
}
void Counters::reset()
{
appendix_ = false;

View File

@ -67,6 +67,8 @@ public:
/// Similar, but used for formatted references in XHTML output.
/// E.g., for a section counter it might be "section \thesection"
docstring const & prettyFormat() const { return prettyformat_; }
///
docstring const & guiName() const { return guiname_; }
/// Returns a map of LaTeX-like strings to format the counter.
/** For each language, the string is similar to what one gets
@ -97,6 +99,8 @@ private:
docstring labelstringappendix_;
/// Similar, but used for formatted references in XHTML output
docstring prettyformat_;
///
docstring guiname_;
/// Cache of the labelstring with \\the<counter> expressions expanded,
/// indexed by language
mutable StringMap flatlabelstring_;
@ -174,6 +178,8 @@ public:
/// format given by Counter::prettyFormat().
docstring prettyCounter(docstring const & cntr,
std::string const & lang) const;
///
docstring const & guiName(docstring const & cntr) const;
/// Are we in appendix?
bool appendix() const { return appendix_; }
/// Set the state variable indicating whether we are in appendix.

View File

@ -59,7 +59,7 @@ GuiCounter::GuiCounter(GuiView & lv, QWidget * parent) :
void GuiCounter::processParams(InsetCommandParams const & params)
{
QString const & counter = toqstr(params["counter"]);
int c = counterCB->findText(counter);
int c = counterCB->findData(counter);
counterCB->setCurrentIndex(c);
QString cmd = toqstr(params.getCmdName());
@ -85,10 +85,13 @@ void GuiCounter::fillCombos()
if (!bv)
return;
std::vector<docstring> counts =
bv->buffer().params().documentClass().counters().listOfCounters();
for (auto const & c : counts)
counterCB->addItem(toqstr(c));
Counters const & cntrs =
bv->buffer().params().documentClass().counters();
std::vector<docstring> counts = cntrs.listOfCounters();
for (auto const & c : counts) {
docstring const & guiname = cntrs.guiName(c);
counterCB->addItem(toqstr(guiname), toqstr(c));
}
}
@ -118,7 +121,7 @@ docstring GuiCounter::dialogToParams() const
{
InsetCommandParams params(insetCode());
params["counter"] = qstring_to_ucs4(counterCB->currentText());
params["counter"] = qstring_to_ucs4(counterCB->itemData(counterCB->currentIndex()).toString());
params["value"] = convert<docstring>(valueSB->value());
params.setCmdName(fromqstr(actionCB->itemData(actionCB->currentIndex()).toString()));
params["lyxonly"] = from_ascii(lyxonlyXB->isChecked() ? "true" : "false");