Skip to main content
Known Participant
August 17, 2009
Question

popUndo broken queue undo

  • August 17, 2009
  • 1 reply
  • 894 views
Hello,

The problem happened when I added an image and then applied a format that was removed from the queue with popUndo(), because I do not want him to do the next operation to undo.

to see the problem is just paste the code below into a new file .as.

package

{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
   
    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.conversion.TextFilter;
    import flashx.textLayout.edit.EditManager;
    import flashx.textLayout.edit.IEditManager;
    import flashx.textLayout.edit.IUndoManager;
    import flashx.textLayout.edit.SelectionState;
    import flashx.textLayout.elements.InlineGraphicElement;
    import flashx.textLayout.elements.InlineGraphicElementStatus;
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.events.StatusChangeEvent;
    import flashx.textLayout.formats.Float;
    import flashx.textLayout.formats.TextLayoutFormat;
    import flashx.textLayout.operations.InsertInlineGraphicOperation;
    import flashx.undo.UndoManager;

    public class InlineGraphicUndoRedo extends Sprite
    {
        private static const markup:String = '<?xml version="1.0" encoding="utf-8"?><TextFlow fontSize="14" paddingBottom="inherit" lineBreak="inherit" paddingTop="4" textIndent="15" verticalAlign="inherit" paddingRight="inherit" paddingLeft="4" whiteSpaceCollapse="preserve" xmlns="http://ns.adobe.com/textLayout/2008"><p marginBottom="15">This is some textttt.</p></TextFlow>';
       
        public function InlineGraphicUndoRedo()
        {
            super();
           
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

               var s:Sprite;
              
               s = new Sprite()

              addChild(s);
              s.x = 10;
              s.y = 200;
              var textFlow:TextFlow = fillComposer(markup,s);
             
              var em:IEditManager = textFlow.interactionManager as IEditManager;
            var selState:SelectionState = new SelectionState(textFlow,1,1);
            em.doOperation(new InsertInlineGraphicOperation(selState,'http://tarrascao.files.wordpress.com/2008/12/universo_digital.jpg',214,140,Float.NONE));
           
            var img:InlineGraphicElement = textFlow.findLeaf(1) as InlineGraphicElement;
           
            var cf:TextLayoutFormat = new TextLayoutFormat();
            cf.lineHeight = 100;    
           
            var um = EditManager(textFlow.interactionManager).undoManager;
           
            trace(um.peekUndo())
            EditManager(textFlow.interactionManager).applyLeafFormat(cf,
            new SelectionState(textFlow, img.getAbsoluteStart(), img.getAbsoluteStart()+1));
            textFlow.flowComposer.updateAllControllers();           
            trace(um.peekUndo());
           
            um.popUndo();  // whether comment this line, works, but is not what I need

                       
            trace(um.peekUndo())
           
            textFlow.flowComposer.updateAllControllers();
        }

          private function fillComposer(markup:String,s:Sprite):TextFlow   
          {
              var textFlow:TextFlow = TextFilter.importToFlow(markup, TextFilter.TEXT_LAYOUT_FORMAT);
              var controller:ContainerController = new ContainerController(s,400,400);
              textFlow.flowComposer.addController(controller);
              textFlow.flowComposer.updateAllControllers();
              textFlow.interactionManager = new EditManager(new UndoManager());
              textFlow.addEventListener(StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGED,graphicLoaded);
              return textFlow;
          }
         
          static private function graphicLoaded(evt:StatusChangeEvent):void
          {
              if (evt.status == InlineGraphicElementStatus.SIZE_PENDING || evt.status == InlineGraphicElementStatus.READY)
                  evt.element.getTextFlow().flowComposer.updateAllControllers();
          }

    }
}



This topic has been closed for replies.

1 reply

Adobe Employee
August 19, 2009

I'm not entirely understanding what the problem is here.

Are you attempting to "pop" the ApplyFormatOperation and then undo the InsertInlineGraphicOperation?  If so that is explicitly disabled.  Undos have to be undone in order and if one is discarded the remaining ones are invalid.  textFlow maintains a generationNumber that is incremented on each model change.  The undo code explitily checks that it matches.

Hope that helps,

Richard

Known Participant
August 19, 2009

Hello Richard,

Yes, it was what I was trying to do.
I wanted to remove the operation 'ApplyFormatOperation ' and have the 'InsertInlineGraphicOperation' available to next undo.

I understand the reason becouse it does not work, but then what is the popUndo do ?

Thanks, Richard
Adobe Employee
August 20, 2009

Its exposed so that on the IUndoManager interface as a necessary method for implementing an UndoManager.  It removes the operation when it is being undone.  There's also some logic that combines a new operation with a previous one and then pops an operation.

Richard