1. mst
  2. ooo340

Commits

Frank Schoenheit [fs]  committed ca0f977

fs34b: #i117039# restore old behavior of SfxUndoManager::EnableUndo: don't count the calls, but maintain a simple flag.
Consequently, let sw's UndoManager simply delegate now, and change the UndoManagerHelper to maintain a lock counter itself.

  • Participants
  • Parent commits 45f3326
  • Branches default

Comments (0)

Files changed (4)

File framework/source/fwe/helper/undomanagerhelper.cxx

View file
  • Ignore whitespace
         bool                                m_disposed;
         bool                                m_bAPIActionRunning;
         bool                                m_bProcessingEvents;
+        sal_Int32                           m_nLockCount;
         ::cppu::OInterfaceContainerHelper   m_aUndoListeners;
         ::cppu::OInterfaceContainerHelper   m_aModifyListeners;
         IUndoManagerImplementation&         m_rUndoManagerImplementation;
             ,m_disposed( false )
             ,m_bAPIActionRunning( false )
             ,m_bProcessingEvents( false )
+            ,m_nLockCount( 0 )
             ,m_aUndoListeners( m_aMutex )
             ,m_aModifyListeners( m_aMutex )
             ,m_rUndoManagerImplementation( i_undoManagerImpl )
         void clearRedo( IMutexGuard& i_instanceLock );
         void reset( IMutexGuard& i_instanceLock );
 
+        void lock();
+        void unlock();
+
         void addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
         {
             m_aUndoListeners.addInterface( i_listener );
     }
 
     //------------------------------------------------------------------------------------------------------------------
+    void UndoManagerHelper_Impl::lock()
+    {
+        // SYNCHRONIZED --->
+        ::osl::MutexGuard aGuard( getMutex() );
+
+        if ( ++m_nLockCount == 1 )
+        {
+            IUndoManager& rUndoManager = getUndoManager();
+            rUndoManager.EnableUndo( false );
+        }
+        // <--- SYNCHRONIZED
+    }
+
+    //------------------------------------------------------------------------------------------------------------------
+    void UndoManagerHelper_Impl::unlock()
+    {
+        // SYNCHRONIZED --->
+        ::osl::MutexGuard aGuard( getMutex() );
+
+        if ( m_nLockCount == 0 )
+            throw NotLockedException( ::rtl::OUString::createFromAscii( "Undo manager is not locked" ), getXUndoManager() );
+
+        if ( --m_nLockCount == 0 )
+        {
+            IUndoManager& rUndoManager = getUndoManager();
+            rUndoManager.EnableUndo( true );
+        }
+        // <--- SYNCHRONIZED
+    }
+
+    //------------------------------------------------------------------------------------------------------------------
     void UndoManagerHelper_Impl::impl_processRequest( ::boost::function0< void > const& i_request, IMutexGuard& i_instanceLock )
     {
         // create the request, and add it to our queue
     //------------------------------------------------------------------------------------------------------------------
     void UndoManagerHelper::lock()
     {
-        // SYNCHRONIZED --->
-        ::osl::MutexGuard aGuard( m_pImpl->getMutex() );
-
-        IUndoManager& rUndoManager = m_pImpl->getUndoManager();
-        rUndoManager.EnableUndo( false );
-        // <--- SYNCHRONIZED
+        m_pImpl->lock();
     }
 
     //------------------------------------------------------------------------------------------------------------------
     void UndoManagerHelper::unlock()
     {
-        // SYNCHRONIZED --->
-        ::osl::MutexGuard aGuard( m_pImpl->getMutex() );
-
-        IUndoManager& rUndoManager = m_pImpl->getUndoManager();
-        if ( rUndoManager.IsUndoEnabled() )
-            throw NotLockedException( ::rtl::OUString::createFromAscii( "Undo manager is not locked" ), m_pImpl->getXUndoManager() );
-        rUndoManager.EnableUndo( true );
-        // <--- SYNCHRONIZED
+        m_pImpl->unlock();
     }
 
     //------------------------------------------------------------------------------------------------------------------

File svl/inc/svl/undo.hxx

View file
  • Ignore whitespace
         /** clears the redo stack and removes the top undo action */
         virtual void            RemoveLastUndoAction() = 0;
 
-        // enables (true) or disables (false) recording of undo actions
-        // If undo actions are added while undo is disabled, they are deleted.
-        // Disabling undo does not clear the current undo buffer!
+        /** enables (true) or disables (false) recording of undo actions
+
+            If undo actions are added while undo is disabled, they are deleted.
+            Disabling undo does not clear the current undo buffer!
+
+            Multiple calls to <code>EnableUndo</code> are not cumulative. That is, calling <code>EnableUndo( false )</code>
+            twice, and then calling <code>EnableUndo( true )</code> means that Undo is enable afterwards.
+        */
         virtual void            EnableUndo( bool bEnable ) = 0;
 
         // returns true if undo is currently enabled

File svl/source/undo/undo.cxx

View file
  • Ignore whitespace
 	SfxUndoArray*   pActUndoArray;
 	SfxUndoArray*   pFatherUndoArray;
 
-    sal_Int32       mnLockCount;
     sal_Int32       mnMarks;
     sal_Int32       mnEmptyMark;
+    bool            mbUndoEnabled;
     bool            mbDoing;
     bool            mbClearUntilTopLevel;
 
         :pUndoArray( new SfxUndoArray( i_nMaxUndoActionCount ) )
         ,pActUndoArray( NULL )
         ,pFatherUndoArray( NULL )
-        ,mnLockCount( 0 )
         ,mnMarks( 0 )
         ,mnEmptyMark(MARK_INVALID)
+        ,mbUndoEnabled( true )
         ,mbDoing( false )
         ,mbClearUntilTopLevel( false )
     {
 
 void SfxUndoManager::ImplEnableUndo_Lock( bool const i_enable )
 {
-    if ( !i_enable )
-        ++m_pData->mnLockCount;
-    else
-    {
-        OSL_PRECOND( m_pData->mnLockCount > 0, "SfxUndoManager::ImplEnableUndo_NoNotify: not disabled, so why enabling?" );
-        if ( m_pData->mnLockCount > 0 )
-            --m_pData->mnLockCount;
-    }
+    if ( m_pData->mbUndoEnabled == i_enable )
+        return;
+    m_pData->mbUndoEnabled = i_enable;
 }
 
 //------------------------------------------------------------------------
 
 bool SfxUndoManager::ImplIsUndoEnabled_Lock() const
 {
-	return m_pData->mnLockCount == 0;
+	return m_pData->mbUndoEnabled;
 }
 
 //------------------------------------------------------------------------

File sw/source/core/undo/docundo.cxx

View file
  • Ignore whitespace
 
 void UndoManager::EnableUndo(bool bEnable)
 {
-    // UGLY: SfxUndoManager has a counter to match enable/disable calls
-    //       but the writer code expects that a single call switches
-    while (IsUndoEnabled() != bEnable)
-    {
-        SfxUndoManager::EnableUndo(bEnable);
-    }
+    // SfxUndoManager does not have a counter anymore, but reverted to the old behavior of
+    // having a simple boolean flag for locking. So, simply forward.
+    SfxUndoManager::EnableUndo(bEnable);
 }
 
 void UndoManager::AddUndoAction(SfxUndoAction *pAction, sal_Bool bTryMerge)