+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(), /* */);
+ return counter_stack_.back();
+}
+
+
+void Counters::setActiveLayout(Layout const & lay)
+{
+ LASSERT(!layout_stack_.empty(), return);
+ Layout const * const lastlay = layout_stack_.back();
+ // we want to check whether the layout has changed and, if so,
+ // whether we are coming out of or going into an environment.
+ if (!lastlay) {
+ layout_stack_.pop_back();
+ layout_stack_.push_back(&lay);
+ if (lay.isEnvironment())
+ beginEnvironment();
+ } else if (lastlay->name() != lay.name()) {
+ layout_stack_.pop_back();
+ layout_stack_.push_back(&lay);
+ if (lastlay->isEnvironment()) {
+ // we are coming out of an environment
+ // LYXERR0("Out: " << lastlay->name());
+ endEnvironment();
+ }
+ if (lay.isEnvironment()) {
+ // we are going into a new environment
+ // LYXERR0("In: " << lay.name());
+ beginEnvironment();
+ }
+ }
+}
+
+
+void Counters::beginEnvironment()
+{
+ docstring cnt = counter_stack_.back();
+ counter_stack_.push_back(cnt);
+ deque<docstring>::const_iterator it = counter_stack_.begin();
+ deque<docstring>::const_iterator en = counter_stack_.end();
+// docstring d;
+// for (; it != en; ++it)
+// d += " --> " + *it;
+// LYXERR0(counter_stack_.size() << ": " << d);
+}
+
+
+void Counters::endEnvironment()
+{
+ LASSERT(!counter_stack_.empty(), return);
+ counter_stack_.pop_back();
+ deque<docstring>::const_iterator it = counter_stack_.begin();
+ deque<docstring>::const_iterator en = counter_stack_.end();
+// docstring d;
+// for (; it != en; ++it)
+// d += " --> " + *it;
+// LYXERR0(counter_stack_.size() << ": " << d);
+}
+
+