]> git.lyx.org Git - lyx.git/blobdiff - src/Counters.cpp
Correct the mess introduced in r33250.
[lyx.git] / src / Counters.cpp
index fff4ac7d92984198c4a9bdb0b1bd466ec55784fa..d6865d107d99dd6954b1e4a3d697c7449a2f8acd 100644 (file)
@@ -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(), /* */);