#include "Counters.h"
#include "Layout.h"
-#include "Lexer.h"
#include "support/convert.h"
#include "support/counter_reps.h"
#include "support/docstring.h"
#include "support/gettext.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <algorithm>
CT_INITIALVALUE,
CT_GUINAME,
CT_LATEXNAME,
+ CT_REFFORMAT,
CT_END
};
{ "labelstringappendix", CT_LABELSTRING_APPENDIX },
{ "latexname", CT_LATEXNAME },
{ "prettyformat", CT_PRETTYFORMAT },
+ { "refformat", CT_REFFORMAT },
{ "within", CT_WITHIN }
};
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();
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_ + ")";
}
}
}
+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_;
}
+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
{
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);