Skip to content

Commit 5b2d83b

Browse files
committed
step-8 Operations
* Adding an OperationManager to a Context * adding undoable Operations to the Context's OperationManager from within a CommandHandler
1 parent 713377d commit 5b2d83b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/helloWorld/commandHandlers/AddStringCommandHandler.as

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package helloWorld.commandHandlers
22
{
3+
import core.app.operations.AddItemOperation;
34
import core.appEx.core.commandHandlers.ICommandHandler;
45
import core.editor.CoreEditor;
56

@@ -15,8 +16,9 @@ package helloWorld.commandHandlers
1516
{
1617
var context:StringListContext = CoreEditor.contextManager.getLatestContextOfType(StringListContext);
1718

18-
var length:int = context.dataProvider.length;
19-
context.dataProvider.addItem("Item " + (length+1));
19+
var item:String = "Item " + (context.dataProvider.length+1);
20+
var addItemOperation:AddItemOperation = new AddItemOperation( item, context.dataProvider );
21+
context.operationManager.addOperation(addItemOperation);
2022
}
2123
}
2224
}

src/helloWorld/contexts/StringListContext.as

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@ package helloWorld.contexts
22
{
33
import flash.display.DisplayObject;
44

5+
import core.appEx.core.contexts.IOperationManagerContext;
56
import core.appEx.core.contexts.IVisualContext;
7+
import core.appEx.managers.OperationManager;
68
import core.data.ArrayCollection;
79

810
import helloWorld.ui.views.StringListView;
911

10-
public class StringListContext implements IVisualContext
12+
public class StringListContext implements IVisualContext, IOperationManagerContext
1113
{
1214
private var _view :StringListView;
1315

1416
private var _dataProvider :ArrayCollection;
1517

18+
private var _operationManager :OperationManager;
19+
1620
public function StringListContext()
1721
{
1822
_view = new StringListView();
1923

2024
_dataProvider = new ArrayCollection();
21-
_dataProvider.addItem( "Item 1" );
22-
_dataProvider.addItem( "Item 2" );
23-
_dataProvider.addItem( "Item 3" );
24-
2525
_view.dataProvider = _dataProvider;
26+
27+
_operationManager = new OperationManager();
2628
}
2729

2830
public function get view():DisplayObject
@@ -32,9 +34,11 @@ package helloWorld.contexts
3234

3335
public function dispose():void
3436
{
35-
37+
_operationManager.dispose();
3638
}
3739

3840
public function get dataProvider():ArrayCollection { return _dataProvider; }
41+
42+
public function get operationManager():OperationManager { return _operationManager; }
3943
}
4044
}

0 commit comments

Comments
 (0)