Permalink
Browse files

Add undo/redo for removing track events

Also fixed a bug. When redoing the addTrackEventCommand, it now adds
the previously deleted track event instead of creating a new one.
  • Loading branch information...
1 parent 702f792 commit fe14711beb601ed3bbd400c128cb5e1241e3c423 @mbuttu committed Apr 20, 2012
Showing with 45 additions and 20 deletions.
  1. +44 −17 src/core/commands.js
  2. +1 −3 src/ui/ui.js
View
@@ -30,23 +30,6 @@ define( [ "./undomanager" ], function( UndoManager ){
}
}); //addEventListener
- function addTrackEventCommand( options ) {
- var track = options.track, trackEvent;
-
- return makeCommand({
- execute: function(){
- trackEvent = track.addTrackEvent({
- type: options.type,
- popcornOptions: options.popcornOptions
- });
- return trackEvent;
- },
- undo: function(){
- track.removeTrackEvent( trackEvent );
- }
- });
- }; //addTrackEventCommand
-
function changeMediaUrlCommand( options ){
var media = options.media,
oldUrl = media.url,
@@ -92,10 +75,54 @@ define( [ "./undomanager" ], function( UndoManager ){
});
}; //addTrackCommand
+ function addTrackEventCommand( options ) {
+ var track = options.track,
+ trackEvent;
+
+ return makeCommand({
+ execute: function(){
+ if ( !trackEvent ) {
+ trackEvent = track.addTrackEvent({
+ type: options.type,
+ popcornOptions: options.popcornOptions
+ });
+ }
+ else {
+ track.addTrackEvent( trackEvent );
+ }
+
+ return trackEvent;
+ },
+ undo: function(){
+ track.removeTrackEvent( trackEvent );
+ }
+ });
+ }; //addTrackEventCommand
+
+ function removeTrackEventsCommand( trackEvents ) {
+
+ return makeCommand({
+ execute: function(){
+ for( var i = 0; i < trackEvents.length; i++ ) {
+ trackEvents[ i ].track.removeTrackEvent( trackEvents[ i ] );
+ } // for
+ },
+ undo: function(){
+ for( var i = 0; i < trackEvents.length; i++ ) {
+ trackEvents[ i ].track.addTrackEvent( trackEvents[ i ] );
+ } // for
+ }
+ });
+ }; //removeTrackEventsCommand
+
butter.addTrackEvent = function( options ){
return addTrackEventCommand( options ).execute();
}; //addTrackEvent
+ butter.removeTrackEvents = function( trackEvents ){
+ removeTrackEventsCommand( trackEvents ).execute();
+ }; //removeTrackEvent
+
butter.changeMediaUrl = function( options ){
changeMediaUrlCommand( options ).execute();
}; //changeMediaUrl
View
@@ -350,9 +350,7 @@ define( [ "core/eventmanager", "./toggler", "./logo-spinner", "./context-button"
8: function( e ) { // del key
if( butter.selectedEvents.length ) {
e.preventDefault();
- for( var i = 0; i < butter.selectedEvents.length; i++ ) {
- butter.selectedEvents[ i ].track.removeTrackEvent( butter.selectedEvents[ i ] );
- } // for
+ butter.removeTrackEvents( butter.selectedEvents );
butter.selectedEvents = [];
} // if
}, // del key

0 comments on commit fe14711

Please sign in to comment.