Skip to content

Commit

Permalink
Updated docs, renamed files for more friendliness.
Browse files Browse the repository at this point in the history
  • Loading branch information
timoxley committed Aug 17, 2010
1 parent d68cc3b commit 1546c5f
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 229 deletions.
13 changes: 9 additions & 4 deletions Readme.textile
@@ -1,4 +1,9 @@
h1. Undoable Commands for Robotlegs Framework
h1. Undoable Commands and History Controller for the Robotlegs Framework

Undoable Commands aims to fill all possible
UndoableCommandBase is a fairly barebones undoable command framework. You can use this to implement your own history controller (whether this is )

h2. Features

* Keeps a linear history of executed Commands
* Step back and forward through history
Expand All @@ -7,14 +12,14 @@ h1. Undoable Commands for Robotlegs Framework

h2. Quickstart

* Download the "latest release swc":http://github.com/secoif/robotlegs-utilities-UndoableCommand/downloads Note the swc is compiled with a Flex 4 nightly build. It should work just fine, but let me know if you have any trouble using it. Feel free to download source and compile for yourself though. The test cases depend on FlexUnit4.
* Download the "latest release swc":http://github.com/secoif/robotlegs-utilities-UndoableCommand/downloads Feel free to download source and compile for yourself, the test cases depend on FlexUnit4.
* Include downloaded swc in your project
* Create your command which extends ManagedUndoableCommand (I know, it's wordy, :/ )
* Create your command which extends UndoableCommand
* Override the protected methods doExecute and undoExecute. doExecute should contain the code you want to execute when the command is fired. undoExecute should contain whatever code is needed to manually undo the actions performed by doExecute. The last line in both of these methods should be the call to super.doExecute()/undoExecute().
* Put the following lines (+ necessary imports) into your Robotlegs context:

<pre>
// CommandHistory manages undo/redo history
// Create a CommandHistory to manages undo/redo history
injector.mapSingleton(CommandHistory);
// Events to trigger undo and redo
commandMap.mapEvent(HistoryEvent.STEP_FORWARD, StepForwardCommand, HistoryEvent);
Expand Down
64 changes: 36 additions & 28 deletions src/FlexUnitApplication.mxml
@@ -1,30 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" xmlns:flexunit="flexunit.flexui.*" creationComplete="onCreationComplete()" >
<fx:Script>
<![CDATA[
<?xml version="1.0" encoding="utf-8"?>

import org.flexunit.runner.Request;
import tests.TestHistory;
import tests.TestHistoryEvents;
import tests.TestManagedUndoableCommand;
import tests.TestUndoableCommand;
<!-- This is an auto generated file and is not intended for modification. -->

public function currentRunTestSuite():Array
{
var testsToRun:Array = new Array();
testsToRun.push(tests.TestHistory);
testsToRun.push(tests.TestHistoryEvents);
testsToRun.push(tests.TestManagedUndoableCommand);
testsToRun.push(tests.TestUndoableCommand);
return testsToRun;
}
private function onCreationComplete():void
{
testRunner.runWithFlexUnit4Runner(currentRunTestSuite(), "robotlegs-utilities-UndoableCommand");
}
]]>
</fx:Script>
<flexunit:FlexUnitTestRunnerUI id="testRunner"/>
</s:Application>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:flexui="flexunit.flexui.*" creationComplete="onCreationComplete()">
<fx:Script>
<![CDATA[
import tests.TestUndoableCommand;
import tests.TestManagedUndoableCommand;
import tests.TestHistoryEvents;
import tests.TestHistory;
public function currentRunTestSuite():Array
{
var testsToRun:Array = new Array();
testsToRun.push(tests.TestHistory);
testsToRun.push(tests.TestHistoryEvents);
testsToRun.push(tests.TestManagedUndoableCommand);
testsToRun.push(tests.TestUndoableCommand);
return testsToRun;
}
private function onCreationComplete():void
{
testRunner.runWithFlexUnit4Runner(currentRunTestSuite(), "robotlegs-utilities-UndoableCommand");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<flexui:FlexUnitTestRunnerUI id="testRunner">
</flexui:FlexUnitTestRunnerUI>
</s:Application>
45 changes: 25 additions & 20 deletions src/org/robotlegs/utilities/undoablecommand/CommandHistory.as
Expand Up @@ -4,18 +4,22 @@ package org.robotlegs.utilities.undoablecommand

import org.robotlegs.utilities.undoablecommand.interfaces.*;

/**
* Provides an interface to manage undo/redo history and fires events on the eventDispatcher
* when history events occur.
*/
public class CommandHistory
{
/**
* Command history data store.
* Vector chosen over array for strongtyping & speed
* Vector chosen over array for strong typing & speed
*/
private var _historyStack:Vector.<IUndoableCommand>;

/**
* Pointer to the current command in the history stack
* Index starts at 1.
* If this is 0, we are pointing to null at the start of the stack
* First command starts at index 1.
* If this is 0, we are pointing to no command (null) at the start of the stack
*/
public var currentPosition:uint;

Expand All @@ -28,24 +32,24 @@ package org.robotlegs.utilities.undoablecommand
}

/**
* Test if we can move forward through the history stack
* True if there's a command to redo
* @return true if there's a command to redo
*/
public function get canStepForward():Boolean {
return (currentPosition < numberOfHistoryItems);
}

/**
* Test if we can move backward through the history stack
* True if there's a command to undo
* @return true if there's a command to undo
*/
public function get canStepBackward():Boolean {
return (currentPosition > 0);
}

/**
* Move forward through the history stack
* i.e. redo/execute the next command on the history stack
*
* Redo/execute the next command on the history stack
* @return position in history stack after this operation
*/
public function stepForward():uint {
Expand All @@ -59,8 +63,7 @@ package org.robotlegs.utilities.undoablecommand
}

/**
* Move backward through the history stack
* i.e. undo the previous command on the history stack
* Undo the previous command on the history stack and set the currentCommand to the previous command
* @return position in history stack after this operation
*/
public function stepBackward():uint {
Expand Down Expand Up @@ -91,9 +94,9 @@ package org.robotlegs.utilities.undoablecommand
}

/**
* Undo all/some commands
* @param numTimes number of positions to move backward. The default, 0, rewinds to the start of the history
* @return position in history stack after this operation
* Undo all or some number of commands.
* @param numTimes number of positions to move backward. The default, 0, rewinds to the start of the history (undoes all commands)
* @return position in history stack after the rewind operation completes
*/
public function rewind(numTimes:uint = 0):uint {
var positionToMoveTo:uint;
Expand All @@ -114,9 +117,10 @@ package org.robotlegs.utilities.undoablecommand
}

/**
* Redo all/some commands
* @param numTimes number of positions to move forward. The default, 0, fast forwards to the end of the history
* @return position in history stack after this operation
* Redo all or some number of commands.
* @param numTimes number of positions to move forward.
* The default, 0, fast forwards to the last item in the history (most recent).
* @return position in history stack after the fastForward operation completes
*/
public function fastForward(numTimes:uint = 0):uint {
var positionToMoveTo:uint;
Expand All @@ -138,18 +142,18 @@ package org.robotlegs.utilities.undoablecommand
}

/**
* @return total number of items in history,
* irrespective of whether they have been undone
* Total number of items in history, irrespective of their undone/redone state.
* @return total number of items in history
*/
public function get numberOfHistoryItems():uint {
return _historyStack.length;
}

/**
* Push a command onto the history stack
* If there are commands that are yet to be redone,
* Push a new command into the current position on the history stack and execute it.
* If there are commands further forward in the history stack,
* those commands are lost and this command becomes
* the top of the command stack.
* new top of the command stack.
*
* @return position in history stack after this operation
*/
Expand All @@ -166,6 +170,7 @@ package org.robotlegs.utilities.undoablecommand
}

/**
* Gets the command at the top of the history stack. This command will have already been executed.
* @return command at the current position in the history stack,
* or null if we're at position 0, or there are simply no commands
* @see currentPosition
Expand Down
101 changes: 0 additions & 101 deletions src/org/robotlegs/utilities/undoablecommand/ManagedUndoableCommand.as

This file was deleted.

0 comments on commit 1546c5f

Please sign in to comment.