Skip to main content
Inspiring
October 10, 2009
Question

Undo stack changed event

  • October 10, 2009
  • 2 replies
  • 786 views

Is there and event that fires when the undo stack has changed?   (I thought I read about such an event, for the benefit of allowing the TLF to work with other stuff).  How about a property that tells you how many items are on the stack?  (Again, I thought there was one - but probably wishful thinking that the TLF had adequate hooks to make the programmer's life easier).

This topic has been closed for replies.

2 replies

Aaronius9er9er
Inspiring
May 27, 2010

Here's a basic example implementation in case it helps anyone. Right now I'm only dispatching events for pushUndo() but it portrays the idea.  I also haven't exposed how many items are in the undo list, but that should be easy.

I likewise felt the UndoManager should dispatch events by default.  Maybe the decision was made as an optimization thing, but I wouldn't think it would make much of a hit.

package controller.textUndo
{
     import flash.events.Event;
     import flash.events.EventDispatcher;
     import flash.events.IEventDispatcher;
     
     import flashx.undo.IOperation;
     import flashx.undo.UndoManager;
     
     [Event(name="undoPushed", type="svg.controller.textUndo.TextUndoManagerEvent")]
     public class EventfulUndoManager extends UndoManager implements IEventDispatcher
     {
          public function EventfulUndoManager()
          {
               super();
          }
          
          override public function pushUndo(operation:IOperation):void
          {
               super.pushUndo(operation);
               dispatchEvent(new TextUndoManagerEvent(TextUndoManagerEvent.UNDO_PUSHED, operation));
          }
          
          private var _dispatcher:EventDispatcher;
          
          protected function get dispatcher():EventDispatcher
          {
               if (!_dispatcher)
               {
                    _dispatcher = new EventDispatcher(this);
               }
               return _dispatcher;
          }
          
          public function addEventListener(type:String, listener:Function,
                    useCapture:Boolean=false, priority:int=0,
                    useWeakReference:Boolean=false):void
          {
               dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
          }
          
          public function     removeEventListener(type:String, listener:Function,
                    useCapture:Boolean=false):void
          {
               dispatcher.removeEventListener(type, listener, useCapture);
          }
          
          public function dispatchEvent(event:Event):Boolean
          {
               return dispatcher.dispatchEvent(event);
          }
          
          public function     hasEventListener(type:String):Boolean
          {
               return dispatcher.hasEventListener(type);
          }
          
          public function     willTrigger(type:String):Boolean
          {
               return dispatcher.willTrigger(type);
          }
     }
}

Adobe Employee
October 12, 2009

There's no event for when the undo stack changes. If you want to know about this, you could use your own UndoManager -- make a custom undo manager that inherits from UndoManager and overrides the relevant functions.

Likewise, you can't tell how many items are on the stack directly, but you can pop them all and push them back on. But if you had your own undo manager, you could easily add this on. If you are trying to map into a bigger application that has its own undo information, this is something you would probably need anyway.

Hope this helps,

- robin