Author: rgheck
Date: Thu Jan 13 02:47:41 2011
New Revision: 37198
URL: http://www.lyx.org/trac/changeset/37198

Log:
OK, the previous idea, that we don't need to check the masters of other
counters, was silly. So here we do.

Modified:
   lyx-devel/trunk/src/Counters.cpp
   lyx-devel/trunk/src/Counters.h

Modified: lyx-devel/trunk/src/Counters.cpp
==============================================================================
--- lyx-devel/trunk/src/Counters.cpp    Thu Jan 13 00:22:06 2011        (r37197)
+++ lyx-devel/trunk/src/Counters.cpp    Thu Jan 13 02:47:41 2011        (r37198)
@@ -145,6 +145,15 @@
 }
 
 
+bool Counter::checkAndRemoveMaster(docstring const & cnt)
+{
+       if (master_ != cnt)
+               return false;
+       master_ = docstring();
+       return true;
+}
+
+
 docstring const & Counter::labelString(bool in_appendix) const
 {
        return in_appendix ? labelstringappendix_ : labelstring_;
@@ -296,10 +305,17 @@
 
 bool Counters::remove(docstring const & cnt)
 {
-       // NOTE It might be worth trying to remove this counter
-       // as "master" for any counter that declares it, but we
-       // don't actually need to do so.
-       return counterList_.erase(cnt);
+       bool retval = counterList_.erase(cnt);
+       if (!retval)
+               return false;
+       CounterList::iterator it = counterList_.begin();
+       CounterList::iterator end = counterList_.end();
+       for (; it != end; ++it) {
+               if (it->second.checkAndRemoveMaster(cnt))
+                       LYXERR(Debug::TCLASS, "Removed master counter `" +
+                                       to_utf8(cnt) + "' from counter: " + 
to_utf8(it->first));
+       }
+       return retval;
 }
 
 

Modified: lyx-devel/trunk/src/Counters.h
==============================================================================
--- lyx-devel/trunk/src/Counters.h      Thu Jan 13 00:22:06 2011        (r37197)
+++ lyx-devel/trunk/src/Counters.h      Thu Jan 13 02:47:41 2011        (r37198)
@@ -50,6 +50,10 @@
        void reset();
        /// Returns the master counter of this counter.
        docstring const & master() const;
+       /// Checks if the master counter is cnt, and if so removes
+       /// it. This is used when a counter is deleted.
+       /// \return whether we removed the master.
+       bool checkAndRemoveMaster(docstring const & cnt);
        /// Returns a LaTeX-like string to format the counter. 
        /** This is similar to what one gets in LaTeX when using
         *  "\the<counter>". The \c in_appendix bool tells whether we

Reply via email to