Repository: flex-asjs Updated Branches: refs/heads/develop 3b82a00d1 -> b00b22470
ObjectMap, UndoManager and CompressionUtils Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/b00b2247 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/b00b2247 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/b00b2247 Branch: refs/heads/develop Commit: b00b2247072f7c65ac0a289626d0f394f17bad1a Parents: 3b82a00 Author: Harbs <[email protected]> Authored: Mon Feb 13 01:01:50 2017 +0200 Committer: Harbs <[email protected]> Committed: Mon Feb 13 01:01:50 2017 +0200 ---------------------------------------------------------------------- .../projects/Core/src/main/flex/CoreClasses.as | 3 + .../org/apache/flex/utils/CompressionUtils.as | 69 +++++ .../flex/org/apache/flex/utils/ObjectMap.as | 171 ++++++++++++ .../org/apache/flex/utils/undo/IOperation.as | 54 ++++ .../org/apache/flex/utils/undo/IUndoManager.as | 187 +++++++++++++ .../org/apache/flex/utils/undo/UndoManager.as | 265 +++++++++++++++++++ 6 files changed, 749 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b00b2247/frameworks/projects/Core/src/main/flex/CoreClasses.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/CoreClasses.as b/frameworks/projects/Core/src/main/flex/CoreClasses.as index a5af3ca..38dabd9 100644 --- a/frameworks/projects/Core/src/main/flex/CoreClasses.as +++ b/frameworks/projects/Core/src/main/flex/CoreClasses.as @@ -146,16 +146,19 @@ internal class CoreClasses import org.apache.flex.utils.HTMLLoader; HTMLLoader; } import org.apache.flex.utils.BrowserUtils; BrowserUtils; + import org.apache.flex.utils.CompressionUtils; CompressionUtils; import org.apache.flex.utils.Endian; Endian; import org.apache.flex.utils.JXON; JXON; import org.apache.flex.utils.StringPadder; StringPadder; import org.apache.flex.utils.StringTrimmer; StringTrimmer; import org.apache.flex.utils.StringUtil; StringUtil; + import org.apache.flex.utils.ObjectMap;ObjectMap; import org.apache.flex.utils.ObjectUtil; ObjectUtil; import org.apache.flex.utils.Timer; Timer; import org.apache.flex.utils.UIDUtil; UIDUtil; import org.apache.flex.utils.UIUtils; UIUtils; import org.apache.flex.utils.URLUtils; URLUtils; + import org.apache.flex.utils.undo.UndoManager; UndoManager; COMPILE::JS { import org.apache.flex.events.utils.EventUtils; EventUtils; http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b00b2247/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CompressionUtils.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CompressionUtils.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CompressionUtils.as new file mode 100644 index 0000000..130b218 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/CompressionUtils.as @@ -0,0 +1,69 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.utils +{ + COMPILE::SWF + { + import flash.utils.ByteArray; + } + + public class CompressionUtils + { + /** + * FalconJX will inject html into the index.html file. Surround with + * "inject_html" tag as follows: + * + * <inject_html> + * <script src="https://cdnjs.cloudflare.com/ajax/libs/pako/1.0.3/pako.min.js"></script> + * </inject_html> + */ + + COMPILE::SWF + public static function inflate(data:BinaryData):BinaryData + { + var ba:ByteArray = new ByteArray(); + ba.writeBytes(data.array); + ba.inflate(); + return new BinaryData(ba); + } + + COMPILE::JS + public static function inflate(data:BinaryData):BinaryData + { + return new BinaryData(window["pako"].inflate(data.array).buffer); + } + + COMPILE::SWF + public static function deflate(data:BinaryData):BinaryData + { + var ba:ByteArray = new ByteArray(); + ba.writeBytes(data.array); + ba.deflate(); + return new BinaryData(ba); + } + + COMPILE::JS + public static function deflate(data:BinaryData):BinaryData + { + return new BinaryData(window["pako"].deflate(data.array).buffer); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b00b2247/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/ObjectMap.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/ObjectMap.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/ObjectMap.as new file mode 100644 index 0000000..917ac47 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/ObjectMap.as @@ -0,0 +1,171 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.utils +{ + COMPILE::SWF + { + import flash.utils.Dictionary; + } + + COMPILE::JS + { + import org.apache.flex.utils.UIDUtil; + } + + public class ObjectMap + { + public function ObjectMap(weak:Boolean=false) + { + _weak = weak; + COMPILE::SWF + { + _map = new Dictionary(weak); + } + COMPILE::JS + { + if(weak) + { + if(typeof WeakMap == "function") + _map = new WeakMap(); + else if(typeof Map == "function")//Map is supported, fall back to that + { + _map = new Map(); + _weak = false; + } + else + { + _map = {}; + _usesObjects = true; + } + } + else if(typeof Map == "function") + _map = new Map(); + else + { + _map = {}; + _usesObjects = true; + } + } + + } + private var _weak:Boolean; + private var _map:Object; + private var _usesObjects:Boolean = false; + COMPILE::SWF + public function delete(key:Object):void + { + delete _map[key]; + } + + COMPILE::SWF + public function get(key:Object):* + { + return _map[key]; + } + COMPILE::SWF + public function has(key:Object):Boolean + { + return _map[key] === undefined; + } + COMPILE::SWF + public function set(key:Object,value:*):void + { + _map[key] = value; + } + COMPILE::SWF + public function clear():void + { + _map = new Dictionary(_weak); + } + + COMPILE::JS + public function delete(key:Object):void + { + if(_usesObjects) + delete _map[key]; + else { + _map.delete(key); + } + } + + COMPILE::JS + public function get(key:Object):* + { + if(_usesObjects) + { + switch(key.constructor) + { + case Number: + case String: + return _map[key]; + case Object: + if(key.object_map_uid) + return _map[key["object_map_uid"]]; + else + return undefined; + default: + return undefined; + } + } + else + return _map.get(key); + } + COMPILE::JS + public function has(key:Object):Boolean + { + if(_usesObjects) + return _map[key] === undefined; + else + return _map.has(key); + } + COMPILE::JS + public function set(key:Object,value:*):void + { + if(_usesObjects) + { + switch(key.constructor) + { + case Number: + case String: + _map[key] = value; + case Object: + if(!key.object_map_uid) + key.object_map_uid = UIDUtil.createUID(); + _map[key["object_map_uid"]] = value; + default: + return; + } + } + else + _map.set(key,value); + } + COMPILE::JS + public function clear():void + { + if(_usesObjects) + _map = {}; + else if(_weak) + _map = new WeakMap(); + else + _map = new Map(); + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b00b2247/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/IOperation.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/IOperation.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/IOperation.as new file mode 100644 index 0000000..d5fe753 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/IOperation.as @@ -0,0 +1,54 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.utils.undo +{ + /** + * IOperation defines the interface for operations that can be undone and redone. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public interface IOperation + { + /** + * Reperforms the operation. + * + * <p>The operation is also responsible for pushing itself onto the undo stack.</p> + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function performRedo():void; + /** + * Reverses the operation. + * + * <p>The operation is also responsible for pushing itself onto the redo stack.</p> + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function performUndo():void; + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b00b2247/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/IUndoManager.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/IUndoManager.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/IUndoManager.as new file mode 100644 index 0000000..43817b8 --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/IUndoManager.as @@ -0,0 +1,187 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.utils.undo +{ + /** + * IUndoManager defines the interface for managing the undo and redo stacks. + * + * <p>An undo manager maintains a stack of operations that can be undone and redone.</p> + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public interface IUndoManager + { + /** + * Clears both the undo and the redo histories. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function clearAll():void; + + /** + * The maximum number of undoable or redoable operations to track. + * + * <p>To disable the undo function, set this value to 0.</p> + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function get undoAndRedoItemLimit():int; + function set undoAndRedoItemLimit(value:int):void; + + /** + * Indicates whether there is currently an operation that can be undone. + * + * @return Boolean <code>true</code>, if there is an operation on the undo stack that can be reversed. + * Otherwise, <code>false</code>. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function canUndo():Boolean; + + /** + * Returns the next operation to be undone. + * + * @return The undoable IOperation object, or <code>null</code>, if no undoable operation + * is on the stack. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function peekUndo():IOperation; + + /** + * Removes the next operation to be undone from the undo stack, and returns it. + * + * @return The undoable IOperation object, or <code>null</code>, if no undoable operation + * is on the stack. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function popUndo():IOperation; + + /** + * Adds an undoable operation to the undo stack. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function pushUndo(operation:IOperation):void; + + /** + * Clears the redo stack. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function clearRedo():void; + + /** + * Indicates whether there is currently an operation that can be redone. + * + * @return Boolean <code>true</code>, if there is an operation on the redo stack that can be redone. + * Otherwise, <code>false</code>. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function canRedo():Boolean; + + /** + * Returns the next operation to be redone. + * + * @return The redoable IOperation object, or <code>null</code>, if no redoable operation + * is on the stack. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function peekRedo():IOperation; + + /** + * Removes the next operation to be redone from the redo stack, and returns it. + * + * @return The redoable IOperation object, or <code>null</code>, if no redoable operation + * is on the stack. + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function popRedo():IOperation; + + /** + * Adds a redoable operation to the redo stack. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + function pushRedo(operation:IOperation):void; + + /** + * Removes the next IOperation object from the undo stack and calls the performUndo() + * function of that object. + * + * @see org.apache.flex.utils.undo.IUndoManager#canUndo() + * @see org.apache.flex.utils.undo.IUndoManager#clearUndo() + * @see org.apache.flex.utils.undo.IUndoManager#peekUndo() + * @see org.apache.flex.utils.undo.IUndoManager#pushUndo() + * @see org.apache.flex.utils.undo.IUndoManager#popUndo() + */ + function undo():void; + + /** + * Removes the next IOperation object from the redo stack and calls the performRedo() + * function of that object. + * + * @see org.apache.flex.utils.undo.IUndoManager#canRedo() + * @see org.apache.flex.utils.undo.IUndoManager#clearRedo() + * @see org.apache.flex.utils.undo.IUndoManager#peekRedo() + * @see org.apache.flex.utils.undo.IUndoManager#pushRedo() + * @see org.apache.flex.utils.undo.IUndoManager#popRedo() + */ + function redo():void; + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b00b2247/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/UndoManager.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/UndoManager.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/UndoManager.as new file mode 100644 index 0000000..a837e4f --- /dev/null +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/undo/UndoManager.as @@ -0,0 +1,265 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.utils.undo +{ + + /** + * The UndoManager class manages the history of editing operations on a text flow so + * that these operations can be undone and redone. + * + * <p>The undo manager maintains two stacks of IOperation objects. When a reversible + * operation is executed, it is placed on the undo stack. If that operation is undone, + * it is removed from the undo stack, reversed, and placed on the redo stack. Likewise, + * if that operation is then redone, it is removed from the redo stack, re-executed, and + * then placed onto the undo stack again. If another operation is executed first, the redo + * stack is cleared.</p> + * + * <p>If the TextFlow is modified directly (not via + * calls to the edit manager, but directly via calls to the managed FlowElement objects), then the edit manager + * clears the undo stack to prevent the stack from getting out of sync with the current state.</p> + * + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * + * @see flashx.textLayout.edit.EditManager + */ + public class UndoManager implements IUndoManager + { + private var undoStack:Vector.<IOperation>; + private var redoStack:Vector.<IOperation>; + + private var _undoAndRedoItemLimit:int = 25; + + /** + * Creates an UndoManager object. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function UndoManager() + { + undoStack = new Vector.<IOperation>; + redoStack = new Vector.<IOperation>; + } + + /** + * @copy IUndoManager#clearAll() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function clearAll():void + { + undoStack.length = 0; + redoStack.length = 0; + } + + /** + * @copy IUndoManager#canUndo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function canUndo():Boolean + { + return undoStack.length > 0; + } + + /** + * @copy IUndoManager#peekUndo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function peekUndo():IOperation + { + return undoStack.length > 0 ? undoStack[undoStack.length-1] : null; + } + + /** + * @copy IUndoManager#popUndo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function popUndo():IOperation + { + return IOperation(undoStack.pop()); + } + + /** + * @copy IUndoManager#pushUndo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function pushUndo(operation:IOperation):void + { + undoStack.push(operation); + trimUndoRedoStacks(); + } + + /** + * @copy IUndoManager#canRedo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function canRedo():Boolean + { + return redoStack.length > 0; + } + + /** + * @copy IUndoManager#clearRedo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function clearRedo():void + { + redoStack.length = 0; + } + + /** + * @copy IUndoManager#peekRedo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function peekRedo():IOperation + { + return redoStack.length > 0 ? redoStack[redoStack.length-1] : null; + } + + /** + * @copy IUndoManager#popRedo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function popRedo():IOperation + { + return IOperation(redoStack.pop()); + } + + /** + * @copy IUndoManager#pushRedo() + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function pushRedo(operation:IOperation):void + { + redoStack.push(operation); + trimUndoRedoStacks(); + } + + /** + * @copy IUndoManager#undoAndRedoItemLimit + * @tiptext The maximum number of undoable or redoable operations to track. + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get undoAndRedoItemLimit():int + { return _undoAndRedoItemLimit; } + public function set undoAndRedoItemLimit(value:int):void + { + _undoAndRedoItemLimit = value; + trimUndoRedoStacks(); + } + + /** + * @copy IUndoManager#undo() + * @see flashx.textLayout.edit.IEditManager#undo() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function undo():void + { + if (canUndo()) + { + var undoOp:IOperation = popUndo(); + undoOp.performUndo(); + } + } + + /** + * @copy IUndoManager#redo() + * + * @see flashx.textLayout.edit.IEditManager#redo() + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function redo():void + { + if (canRedo()) + { + var redoOp:IOperation = popRedo(); + redoOp.performRedo(); + } + } + + /** trim the sizes of the undo/redo stacks to the maximum limits */ + private function trimUndoRedoStacks():void + { + // trim the undoStack and the redoStack so its in bounds + var numItems:int = undoStack.length + redoStack.length; + if (numItems > _undoAndRedoItemLimit) + { + // trim redoStack first + var numToSplice:int = Math.min(numItems-_undoAndRedoItemLimit,redoStack.length); + if (numToSplice) + { + redoStack.splice(0,numToSplice); + numItems = undoStack.length+redoStack.length; + } + // trim some undoable items + if (numItems > _undoAndRedoItemLimit) + { + numToSplice = Math.min(numItems-_undoAndRedoItemLimit,undoStack.length); + undoStack.splice(0,numToSplice); + } + } + } + } +}
