Skip to content

Commit

Permalink
Replaced app getUndoStack by addToUndoStack. Fixes #197.
Browse files Browse the repository at this point in the history
Allows to check if the stack is created. Thanks @yossidev!
  • Loading branch information
ivmartel committed Jan 19, 2016
1 parent 544fd6b commit 969e381
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,15 @@ dwv.App = function ()
this.getToolboxController = function () { return toolboxController; };

/**
* Get the undo stack.
* @method getUndoStack
* @return {Object} The undo stack.
* Add a command to the undo stack.
* @method addToUndoStack
* @param {Object} The command to add.
*/
this.getUndoStack = function () { return undoStack; };
this.addToUndoStack = function (cmd) {
if ( undoStack !== null ) {
undoStack.add(cmd);
}
};

/**
* Get the data loaders.
Expand Down
2 changes: 1 addition & 1 deletion src/app/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dwv.State = function (app)
cmd.onUndo = eventCallback;
}
cmd.execute();
app.getUndoStack().add(cmd);
app.addToUndoStack(cmd);
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/tools/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ dwv.tool.Draw = function (app, shapeFactoryList)
// execute it
command.execute();
// save it in undo stack
app.getUndoStack().add(command);
app.addToUndoStack(command);

// set shape on
var shape = group.getChildren( function (node) {
Expand Down Expand Up @@ -749,7 +749,7 @@ dwv.tool.Draw = function (app, shapeFactoryList)
delcmd.onExecute = fireEvent;
delcmd.onUndo = fireEvent;
delcmd.execute();
app.getUndoStack().add(delcmd);
app.addToUndoStack(delcmd);
}
else {
// save drag move
Expand All @@ -759,7 +759,7 @@ dwv.tool.Draw = function (app, shapeFactoryList)
var mvcmd = new dwv.tool.MoveGroupCommand(this.getParent(), cmdName, translation, drawLayer);
mvcmd.onExecute = fireEvent;
mvcmd.onUndo = fireEvent;
app.getUndoStack().add(mvcmd);
app.addToUndoStack(mvcmd);
// the move is handled by kinetic, trigger an event manually
fireEvent({'type': 'draw-move'});
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ dwv.tool.ShapeEditor = function (app)
chgcmd.onExecute = drawEventCallback;
chgcmd.onUndo = drawEventCallback;
chgcmd.execute();
app.getUndoStack().add(chgcmd);
app.addToUndoStack(chgcmd);
// reset start anchor
startAnchor = endAnchor;
});
Expand Down
6 changes: 3 additions & 3 deletions src/tools/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ dwv.tool.filter.Threshold = function ( app )
var command = new dwv.tool.RunFilterCommand(filter, app);
command.execute();
// save command in undo stack
app.getUndoStack().add(command);
app.addToUndoStack(command);
};

}; // class dwv.tool.filter.Threshold
Expand Down Expand Up @@ -305,7 +305,7 @@ dwv.tool.filter.Sharpen = function ( app )
var command = new dwv.tool.RunFilterCommand(filter, app);
command.execute();
// save command in undo stack
app.getUndoStack().add(command);
app.addToUndoStack(command);
};

}; // dwv.tool.filter.Sharpen
Expand Down Expand Up @@ -365,7 +365,7 @@ dwv.tool.filter.Sobel = function ( app )
var command = new dwv.tool.RunFilterCommand(filter, app);
command.execute();
// save command in undo stack
app.getUndoStack().add(command);
app.addToUndoStack(command);
};

}; // class dwv.tool.filter.Sobel
Expand Down
2 changes: 1 addition & 1 deletion src/tools/livewire.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ dwv.tool.Livewire = function(app)
self.mousemove(event);
console.log("Done.");
// save command in undo stack
app.getUndoStack().add(command);
app.addToUndoStack(command);
// set flag
self.started = false;
}
Expand Down

0 comments on commit 969e381

Please sign in to comment.