]> git.lyx.org Git - lyx.git/blobdiff - src/Counters.cpp
Update Win installer for new dictionary links. Untested.
[lyx.git] / src / Counters.cpp
index 0133f76bcab455f876c0f05631641313d09dfe32..114b18020b3d0b34690318f5046391f7e09314f3 100644 (file)
@@ -42,9 +42,10 @@ Counter::Counter()
 
 
 Counter::Counter(docstring const & mc, docstring const & ls,
-               docstring const & lsa, docstring const & guiname)
+               docstring const & lsa, docstring const & prettyformat,
+               docstring const & guiname)
        : initial_value_(0), saved_value_(0), parent_(mc), labelstring_(ls),
-         labelstringappendix_(lsa), guiname_(guiname)
+         labelstringappendix_(lsa), prettyformat_(prettyformat), guiname_(guiname)
 {
        reset();
 }
@@ -60,6 +61,7 @@ bool Counter::read(Lexer & lex)
                CT_INITIALVALUE,
                CT_GUINAME,
                CT_LATEXNAME,
+               CT_REFFORMAT,
                CT_END
        };
 
@@ -71,6 +73,7 @@ bool Counter::read(Lexer & lex)
                { "labelstringappendix", CT_LABELSTRING_APPENDIX },
                { "latexname", CT_LATEXNAME },
                { "prettyformat", CT_PRETTYFORMAT },
+               { "refformat", CT_REFFORMAT },
                { "within", CT_WITHIN }
        };
 
@@ -109,6 +112,15 @@ bool Counter::read(Lexer & lex)
                                lex.next();
                                prettyformat_ = lex.getDocString();
                                break;
+                       case CT_REFFORMAT: {
+                               lex.next();
+                               docstring const key = lex.getDocString();
+                               lex.next();
+                               docstring const value = lex.getDocString();
+                               ref_formats_[key] = value;
+                               // LYXERR0("refformat: " << key << " => " << value);
+                               break;
+                       }
                        case CT_LABELSTRING:
                                lex.next();
                                labelstring_ = lex.getDocString();
@@ -130,6 +142,13 @@ bool Counter::read(Lexer & lex)
                                getout = true;
                                break;
                }
+               // fall back on GuiName if PrettyFormat is empty
+               if (prettyformat_.empty()) {
+                       if (guiname_.empty())
+                               prettyformat_ = from_ascii("##");
+                       else
+                               prettyformat_ = "## (" + guiname_ + ")";
+               }
        }
 
        // Here if have a full counter if getout == true
@@ -182,6 +201,15 @@ void Counter::reset()
 }
 
 
+docstring const & Counter::refFormat(docstring const & prefix) const
+{
+       map<docstring, docstring>::const_iterator it = ref_formats_.find(prefix);
+       if (it == ref_formats_.end())
+               return prettyformat_;
+       return it->second;
+}
+
+
 docstring const & Counter::parent() const
 {
        return parent_;
@@ -220,6 +248,7 @@ void Counters::newCounter(docstring const & newc,
                          docstring const & parentc,
                          docstring const & ls,
                          docstring const & lsa,
+                         docstring const & prettyformat,
                          docstring const & guiname)
 {
        if (!parentc.empty() && !hasCounter(parentc)) {
@@ -228,7 +257,7 @@ void Counters::newCounter(docstring const & newc,
                       << endl;
                return;
        }
-       counterList_[newc] = Counter(parentc, ls, lsa, guiname);
+       counterList_[newc] = Counter(parentc, ls, lsa, prettyformat, guiname);
 }
 
 
@@ -344,7 +373,7 @@ void Counters::stepParent(docstring const & ctr, UpdateType utype)
 }
 
 
-void Counters::step(docstring const & ctr, UpdateType utype)
+void Counters::step(docstring const & ctr, UpdateType /* deleted */)
 {
        CounterList::iterator it = counterList_.find(ctr);
        if (it == counterList_.end()) {
@@ -354,11 +383,9 @@ void Counters::step(docstring const & ctr, UpdateType utype)
        }
 
        it->second.step();
-       if (utype == OutputUpdate) {
-               LBUFERR(!counter_stack_.empty());
-               counter_stack_.pop_back();
-               counter_stack_.push_back(ctr);
-       }
+       LBUFERR(!counter_stack_.empty());
+       counter_stack_.pop_back();
+       counter_stack_.push_back(ctr);
 
        resetChildren(ctr);
 }
@@ -476,6 +503,9 @@ docstring Counters::labelItem(docstring const & ctr,
        if (numbertype == "fnsymbol")
                return fnsymbolCounter(val);
 
+       if (numbertype == "superarabic")
+               return superarabicCounter(val);
+
        return convert<docstring>(val);
 }
 
@@ -592,6 +622,23 @@ docstring Counters::counterLabel(docstring const & format,
 }
 
 
+docstring Counters::formattedCounter(docstring const & name,
+                       docstring const & prex, 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 =
+               translateIfPossible(counterLabel(ctr.refFormat(prex), lang), lang);
+       if (format.empty())
+               return value;
+       return subst(format, from_ascii("##"), value);
+}
+
+
 docstring Counters::prettyCounter(docstring const & name,
                               string const & lang) const
 {
@@ -602,7 +649,7 @@ docstring Counters::prettyCounter(docstring const & name,
 
        docstring const value = theCounter(name, lang);
        docstring const & format =
-           translateIfPossible(ctr.prettyFormat(), lang);
+               translateIfPossible(counterLabel(ctr.prettyFormat(), lang), lang);
        if (format.empty())
                return value;
        return subst(format, from_ascii("##"), value);