]> git.lyx.org Git - lyx.git/blobdiff - src/Counters.cpp
Amend 6c3447c8: FindAdv: sometimes a space is added on some math symbols
[lyx.git] / src / Counters.cpp
index 1a9c6af6375de88fb7831c01ac35901899f31188..703125f537f16d4a84723d16f0d40cb0f494906f 100644 (file)
@@ -15,7 +15,6 @@
 
 #include "Counters.h"
 #include "Layout.h"
-#include "Lexer.h"
 
 #include "support/convert.h"
 #include "support/counter_reps.h"
@@ -23,6 +22,7 @@
 #include "support/docstring.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
+#include "support/Lexer.h"
 #include "support/lstrings.h"
 
 #include <algorithm>
@@ -61,6 +61,7 @@ bool Counter::read(Lexer & lex)
                CT_INITIALVALUE,
                CT_GUINAME,
                CT_LATEXNAME,
+               CT_REFFORMAT,
                CT_END
        };
 
@@ -72,6 +73,7 @@ bool Counter::read(Lexer & lex)
                { "labelstringappendix", CT_LABELSTRING_APPENDIX },
                { "latexname", CT_LATEXNAME },
                { "prettyformat", CT_PRETTYFORMAT },
+               { "refformat", CT_REFFORMAT },
                { "within", CT_WITHIN }
        };
 
@@ -110,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();
@@ -131,11 +142,12 @@ bool Counter::read(Lexer & lex)
                                getout = true;
                                break;
                }
-               if (prettyformat_ == "") { // fall back on GuiName if PrettyFormat is empty
-                       if (guiname_ == "")
+               // fall back on GuiName if PrettyFormat is empty
+               if (prettyformat_.empty()) {
+                       if (guiname_.empty())
                                prettyformat_ = from_ascii("##");
                        else
-                               prettyformat_ = "## (" + guiname_ + " counter)";
+                               prettyformat_ = "## (" + guiname_ + ")";
                }
        }
 
@@ -189,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_;
@@ -601,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
 {