X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCounters.cpp;h=d6865d107d99dd6954b1e4a3d697c7449a2f8acd;hb=8b7584846c4e1a9c87a004fab479722fee7e3013;hp=fff4ac7d92984198c4a9bdb0b1bd466ec55784fa;hpb=22dc345e8cd292383be108ec9ca55af4abc58e96;p=lyx.git diff --git a/src/Counters.cpp b/src/Counters.cpp index fff4ac7d92..d6865d107d 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -52,6 +52,7 @@ bool Counter::read(Lexer & lex) CT_WITHIN = 1, CT_LABELSTRING, CT_LABELSTRING_APPENDIX, + CT_PRETTYFORMAT, CT_END }; @@ -59,6 +60,7 @@ bool Counter::read(Lexer & lex) { "end", CT_END }, { "labelstring", CT_LABELSTRING }, { "labelstringappendix", CT_LABELSTRING_APPENDIX }, + { "prettyformat", CT_PRETTYFORMAT }, { "within", CT_WITHIN } }; @@ -81,6 +83,10 @@ bool Counter::read(Lexer & lex) if (master_ == "none") master_.erase(); break; + case CT_PRETTYFORMAT: + lex.next(); + prettyformat_ = lex.getDocString(); + break; case CT_LABELSTRING: lex.next(); labelstring_ = lex.getDocString(); @@ -227,7 +233,7 @@ int Counters::value(docstring const & ctr) const } -void Counters::step(docstring const & ctr, bool track_counters) +void Counters::step(docstring const & ctr, UpdateType utype) { CounterList::iterator it = counterList_.find(ctr); if (it == counterList_.end()) { @@ -237,7 +243,7 @@ void Counters::step(docstring const & ctr, bool track_counters) } it->second.step(); - if (track_counters) { + if (utype == OutputUpdate) { LASSERT(!counter_stack_.empty(), /* */); counter_stack_.pop_back(); counter_stack_.push_back(ctr); @@ -539,6 +545,22 @@ docstring Counters::counterLabel(docstring const & format, } +docstring Counters::prettyCounter(docstring const & name, + string const & lang) const +{ + CounterList::const_iterator it = counterList_.find(name); + if (it == counterList_.end()) + return from_ascii("??"); + Counter const & ctr = it->second; + + docstring const value = theCounter(name, lang); + docstring const & format = ctr.prettyFormat(); + if (format.empty()) + return value; + return subst(format, from_ascii("##"), value); +} + + docstring Counters::currentCounter() const { LASSERT(!counter_stack_.empty(), /* */);