1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2007-2010 Adobe Systems Incorporated 5// All Rights Reserved. 6// 7// NOTICE: Adobe permits you to use, modify, and distribute this file 8// in accordance with the terms of the license agreement accompanying it. 9// 10//////////////////////////////////////////////////////////////////////////////// 11package flashx.textLayout.operations 12{ 13 import flashx.textLayout.debug.assert; 14 import flashx.textLayout.edit.SelectionState; 15 import flashx.textLayout.elements.ContainerFormattedElement; 16 import flashx.textLayout.elements.FlowElement; 17 import flashx.textLayout.elements.FlowGroupElement; 18 import flashx.textLayout.elements.ParagraphFormattedElement; 19 import flashx.textLayout.elements.TextFlow; 20 import flashx.textLayout.formats.ITextLayoutFormat; 21 import flashx.textLayout.formats.TextLayoutFormat; 22 import flashx.textLayout.tlf_internal; 23 24 use namespace tlf_internal; 25 26 /** 27 * The ChangeElementIDOperation class encapsulates an element ID change. 28 * 29 * @see flashx.textLayout.elements.FlowElement 30 * @see flashx.textLayout.edit.EditManager 31 * @see flashx.textLayout.events.FlowOperationEvent 32 * 33 * @playerversion Flash 10 34 * @playerversion AIR 1.5 35 * @langversion 3.0 36 */ 37 public class ApplyElementIDOperation extends FlowElementOperation 38 { 39 private var _origID:String; 40 private var _newID:String; 41 42 /** 43 * Creates a ChangeElementIDOperation object. 44 * 45 * <p>If the <code>relativeStart</code> or <code>relativeEnd</code> parameters are set, then the existing 46 * element is split into two elements, one using the existing ID and the other 47 * using the new ID. If both parameters are set, then the existing element is split into three elements. 48 * The first and last elements of the set are both assigned the original ID.</p> 49 * 50 * @param operationState Specifies the selection state before the operation 51 * @param targetElement Specifies the element to change 52 * @param newID The ID to assign 53 * @param relativeStart An offset from the beginning of the target element. 54 * @param relativeEnd An offset from the end of the target element. 55 * 56 * @playerversion Flash 10 57 * @playerversion AIR 1.5 58 * @langversion 3.0 59 */ 60 public function ApplyElementIDOperation(operationState:SelectionState, targetElement:FlowElement, newID:String, relativeStart:int = 0, relativeEnd:int = -1) 61 { 62 _newID = newID; 63 super(operationState,targetElement,relativeStart,relativeEnd); 64 } 65 66 /** 67 * The ID assigned by this operation. 68 * 69 * @playerversion Flash 10 70 * @playerversion AIR 1.5 71 * @langversion 3.0 72 */ 73 public function get newID():String 74 { return _newID; } 75 public function set newID(val:String):void 76 { _newID = val; } 77 78 /** @private */ 79 public override function doOperation():Boolean 80 { 81 var targetElement:FlowElement = getTargetElement(); 82 _origID = targetElement.id; 83 84 adjustForDoOperation(targetElement); 85 86 targetElement.id = _newID; 87 return true; 88 } 89 90 /** @private */ 91 public override function undo():SelectionState 92 { 93 var targetElement:FlowElement = getTargetElement(); 94 targetElement.id = _origID; 95 96 adjustForUndoOperation(targetElement); 97 98 return originalSelectionState; 99 } 100 } 101}