mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 00:18:56 +02:00
Undo button functionality Issue #40
This commit is contained in:
parent
e94710ca64
commit
c5a3f866ab
9 changed files with 144 additions and 12 deletions
100
build/bundle.js
100
build/bundle.js
|
@ -4498,6 +4498,7 @@ var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.
|
|||
|
||||
var util = require('../util');
|
||||
var Main = require('../app');
|
||||
var Errors = require('../util/errors');
|
||||
|
||||
var Visualization = require('../visuals/visualization').Visualization;
|
||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||
|
@ -4523,6 +4524,7 @@ var Sandbox = Backbone.View.extend({
|
|||
this.initCommandCollection(options);
|
||||
this.initParseWaterfall(options);
|
||||
this.initGitShim(options);
|
||||
this.initUndoStack(options);
|
||||
|
||||
if (!options.wait) {
|
||||
this.takeControl();
|
||||
|
@ -4541,6 +4543,10 @@ var Sandbox = Backbone.View.extend({
|
|||
});
|
||||
},
|
||||
|
||||
initUndoStack: function(options) {
|
||||
this.undoStack = [];
|
||||
},
|
||||
|
||||
initCommandCollection: function(options) {
|
||||
// don't add it to just any collection -- adding to the
|
||||
// CommandUI collection will put in history
|
||||
|
@ -4552,6 +4558,9 @@ var Sandbox = Backbone.View.extend({
|
|||
},
|
||||
|
||||
initGitShim: function(options) {
|
||||
this.gitShim = new GitShim({
|
||||
beforeCB: _.bind(this.beforeCommandCB, this)
|
||||
});
|
||||
},
|
||||
|
||||
takeControl: function() {
|
||||
|
@ -4595,6 +4604,31 @@ var Sandbox = Backbone.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
beforeCommandCB: function(command) {
|
||||
this.pushUndo();
|
||||
},
|
||||
|
||||
pushUndo: function() {
|
||||
// go ahead and push the three onto the stack
|
||||
this.undoStack.push(this.mainVis.gitEngine.printTree());
|
||||
},
|
||||
|
||||
undo: function(command, deferred) {
|
||||
var toRestore = this.undoStack.pop();
|
||||
if (!toRestore) {
|
||||
command.set('error', new Errors.GitError({
|
||||
msg: 'The undo stack is empty!'
|
||||
}));
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
this.mainVis.reset(toRestore);
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
}, this.mainVis.getAnimationTime());
|
||||
},
|
||||
|
||||
commandSubmitted: function(value) {
|
||||
// allow other things to see this command (aka command history on terminal)
|
||||
Main.getEvents().trigger('commandSubmittedPassive', value);
|
||||
|
@ -4689,6 +4723,7 @@ var Sandbox = Backbone.View.extend({
|
|||
// some exceptions to the rule
|
||||
var commandMap = {
|
||||
'reset solved': this.resetSolved,
|
||||
'undo': this.undo,
|
||||
'help general': this.helpDialog,
|
||||
'help': this.helpDialog,
|
||||
'reset': this.reset,
|
||||
|
@ -4842,6 +4877,7 @@ var Sandbox = Backbone.View.extend({
|
|||
|
||||
reset: function(command, deferred) {
|
||||
this.mainVis.reset();
|
||||
this.initUndoStack();
|
||||
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
|
@ -6917,6 +6953,7 @@ var Level = Sandbox.extend({
|
|||
initGitShim: function(options) {
|
||||
// ok we definitely want a shim here
|
||||
this.gitShim = new GitShim({
|
||||
beforeCB: _.bind(this.beforeCommandCB, this),
|
||||
afterCB: _.bind(this.afterCommandCB, this),
|
||||
afterDeferHandler: _.bind(this.afterCommandDefer, this)
|
||||
});
|
||||
|
@ -6943,6 +6980,11 @@ var Level = Sandbox.extend({
|
|||
return myRegexMap;
|
||||
},
|
||||
|
||||
undo: function() {
|
||||
this.gitCommandsIssued.pop();
|
||||
Level.__super__.undo.apply(this, arguments);
|
||||
},
|
||||
|
||||
afterCommandCB: function(command) {
|
||||
var matched = false;
|
||||
_.each(this.commandsThatCount, function(regex) {
|
||||
|
@ -7345,10 +7387,11 @@ var Visualization = Backbone.View.extend({
|
|||
this.treeString = treeString;
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
reset: function(tree) {
|
||||
var treeString = tree || this.treeString;
|
||||
this.setTreeOpacity(0);
|
||||
if (this.treeString) {
|
||||
this.gitEngine.loadTreeFromString(this.treeString);
|
||||
this.gitEngine.loadTreeFromString(treeString);
|
||||
} else {
|
||||
this.gitEngine.defaultInit();
|
||||
}
|
||||
|
@ -13424,7 +13467,8 @@ var regexMap = {
|
|||
'build level': /^build level($|\s)/,
|
||||
'export tree': /^export tree$/,
|
||||
'import tree': /^import tree$/,
|
||||
'import level': /^import level$/
|
||||
'import level': /^import level$/,
|
||||
'undo': /^undo($|\s)/
|
||||
};
|
||||
|
||||
exports.instantCommands = instantCommands;
|
||||
|
@ -22016,6 +22060,7 @@ var Level = Sandbox.extend({
|
|||
initGitShim: function(options) {
|
||||
// ok we definitely want a shim here
|
||||
this.gitShim = new GitShim({
|
||||
beforeCB: _.bind(this.beforeCommandCB, this),
|
||||
afterCB: _.bind(this.afterCommandCB, this),
|
||||
afterDeferHandler: _.bind(this.afterCommandDefer, this)
|
||||
});
|
||||
|
@ -22042,6 +22087,11 @@ var Level = Sandbox.extend({
|
|||
return myRegexMap;
|
||||
},
|
||||
|
||||
undo: function() {
|
||||
this.gitCommandsIssued.pop();
|
||||
Level.__super__.undo.apply(this, arguments);
|
||||
},
|
||||
|
||||
afterCommandCB: function(command) {
|
||||
var matched = false;
|
||||
_.each(this.commandsThatCount, function(regex) {
|
||||
|
@ -22379,6 +22429,7 @@ var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.
|
|||
|
||||
var util = require('../util');
|
||||
var Main = require('../app');
|
||||
var Errors = require('../util/errors');
|
||||
|
||||
var Visualization = require('../visuals/visualization').Visualization;
|
||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||
|
@ -22404,6 +22455,7 @@ var Sandbox = Backbone.View.extend({
|
|||
this.initCommandCollection(options);
|
||||
this.initParseWaterfall(options);
|
||||
this.initGitShim(options);
|
||||
this.initUndoStack(options);
|
||||
|
||||
if (!options.wait) {
|
||||
this.takeControl();
|
||||
|
@ -22422,6 +22474,10 @@ var Sandbox = Backbone.View.extend({
|
|||
});
|
||||
},
|
||||
|
||||
initUndoStack: function(options) {
|
||||
this.undoStack = [];
|
||||
},
|
||||
|
||||
initCommandCollection: function(options) {
|
||||
// don't add it to just any collection -- adding to the
|
||||
// CommandUI collection will put in history
|
||||
|
@ -22433,6 +22489,9 @@ var Sandbox = Backbone.View.extend({
|
|||
},
|
||||
|
||||
initGitShim: function(options) {
|
||||
this.gitShim = new GitShim({
|
||||
beforeCB: _.bind(this.beforeCommandCB, this)
|
||||
});
|
||||
},
|
||||
|
||||
takeControl: function() {
|
||||
|
@ -22476,6 +22535,31 @@ var Sandbox = Backbone.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
beforeCommandCB: function(command) {
|
||||
this.pushUndo();
|
||||
},
|
||||
|
||||
pushUndo: function() {
|
||||
// go ahead and push the three onto the stack
|
||||
this.undoStack.push(this.mainVis.gitEngine.printTree());
|
||||
},
|
||||
|
||||
undo: function(command, deferred) {
|
||||
var toRestore = this.undoStack.pop();
|
||||
if (!toRestore) {
|
||||
command.set('error', new Errors.GitError({
|
||||
msg: 'The undo stack is empty!'
|
||||
}));
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
this.mainVis.reset(toRestore);
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
}, this.mainVis.getAnimationTime());
|
||||
},
|
||||
|
||||
commandSubmitted: function(value) {
|
||||
// allow other things to see this command (aka command history on terminal)
|
||||
Main.getEvents().trigger('commandSubmittedPassive', value);
|
||||
|
@ -22570,6 +22654,7 @@ var Sandbox = Backbone.View.extend({
|
|||
// some exceptions to the rule
|
||||
var commandMap = {
|
||||
'reset solved': this.resetSolved,
|
||||
'undo': this.undo,
|
||||
'help general': this.helpDialog,
|
||||
'help': this.helpDialog,
|
||||
'reset': this.reset,
|
||||
|
@ -22723,6 +22808,7 @@ var Sandbox = Backbone.View.extend({
|
|||
|
||||
reset: function(command, deferred) {
|
||||
this.mainVis.reset();
|
||||
this.initUndoStack();
|
||||
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
|
@ -22806,7 +22892,8 @@ var regexMap = {
|
|||
'build level': /^build level($|\s)/,
|
||||
'export tree': /^export tree$/,
|
||||
'import tree': /^import tree$/,
|
||||
'import level': /^import level$/
|
||||
'import level': /^import level$/,
|
||||
'undo': /^undo($|\s)/
|
||||
};
|
||||
|
||||
exports.instantCommands = instantCommands;
|
||||
|
@ -28471,10 +28558,11 @@ var Visualization = Backbone.View.extend({
|
|||
this.treeString = treeString;
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
reset: function(tree) {
|
||||
var treeString = tree || this.treeString;
|
||||
this.setTreeOpacity(0);
|
||||
if (this.treeString) {
|
||||
this.gitEngine.loadTreeFromString(this.treeString);
|
||||
this.gitEngine.loadTreeFromString(treeString);
|
||||
} else {
|
||||
this.gitEngine.defaultInit();
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
1
build/bundle.min.6040aa35.js
Normal file
1
build/bundle.min.6040aa35.js
Normal file
File diff suppressed because one or more lines are too long
2
build/bundle.min.js
vendored
2
build/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -409,7 +409,7 @@
|
|||
For a much easier time perusing the source, see the individual files at:
|
||||
https://github.com/pcottle/learnGitBranching
|
||||
-->
|
||||
<script src="build/bundle.min.20261aa4.js"></script>
|
||||
<script src="build/bundle.min.6040aa35.js"></script>
|
||||
|
||||
<!-- The advantage of github pages: super-easy, simple, slick static hostic.
|
||||
The downside? No raw logs to parse for analytics, so I have to include
|
||||
|
|
|
@ -257,6 +257,7 @@ var Level = Sandbox.extend({
|
|||
initGitShim: function(options) {
|
||||
// ok we definitely want a shim here
|
||||
this.gitShim = new GitShim({
|
||||
beforeCB: _.bind(this.beforeCommandCB, this),
|
||||
afterCB: _.bind(this.afterCommandCB, this),
|
||||
afterDeferHandler: _.bind(this.afterCommandDefer, this)
|
||||
});
|
||||
|
@ -283,6 +284,11 @@ var Level = Sandbox.extend({
|
|||
return myRegexMap;
|
||||
},
|
||||
|
||||
undo: function() {
|
||||
this.gitCommandsIssued.pop();
|
||||
Level.__super__.undo.apply(this, arguments);
|
||||
},
|
||||
|
||||
afterCommandCB: function(command) {
|
||||
var matched = false;
|
||||
_.each(this.commandsThatCount, function(regex) {
|
||||
|
|
|
@ -5,6 +5,7 @@ var Backbone = (!require('../util').isBrowser()) ? require('backbone') : window.
|
|||
|
||||
var util = require('../util');
|
||||
var Main = require('../app');
|
||||
var Errors = require('../util/errors');
|
||||
|
||||
var Visualization = require('../visuals/visualization').Visualization;
|
||||
var ParseWaterfall = require('../level/parseWaterfall').ParseWaterfall;
|
||||
|
@ -30,6 +31,7 @@ var Sandbox = Backbone.View.extend({
|
|||
this.initCommandCollection(options);
|
||||
this.initParseWaterfall(options);
|
||||
this.initGitShim(options);
|
||||
this.initUndoStack(options);
|
||||
|
||||
if (!options.wait) {
|
||||
this.takeControl();
|
||||
|
@ -48,6 +50,10 @@ var Sandbox = Backbone.View.extend({
|
|||
});
|
||||
},
|
||||
|
||||
initUndoStack: function(options) {
|
||||
this.undoStack = [];
|
||||
},
|
||||
|
||||
initCommandCollection: function(options) {
|
||||
// don't add it to just any collection -- adding to the
|
||||
// CommandUI collection will put in history
|
||||
|
@ -59,6 +65,9 @@ var Sandbox = Backbone.View.extend({
|
|||
},
|
||||
|
||||
initGitShim: function(options) {
|
||||
this.gitShim = new GitShim({
|
||||
beforeCB: _.bind(this.beforeCommandCB, this)
|
||||
});
|
||||
},
|
||||
|
||||
takeControl: function() {
|
||||
|
@ -102,6 +111,31 @@ var Sandbox = Backbone.View.extend({
|
|||
}
|
||||
},
|
||||
|
||||
beforeCommandCB: function(command) {
|
||||
this.pushUndo();
|
||||
},
|
||||
|
||||
pushUndo: function() {
|
||||
// go ahead and push the three onto the stack
|
||||
this.undoStack.push(this.mainVis.gitEngine.printTree());
|
||||
},
|
||||
|
||||
undo: function(command, deferred) {
|
||||
var toRestore = this.undoStack.pop();
|
||||
if (!toRestore) {
|
||||
command.set('error', new Errors.GitError({
|
||||
msg: 'The undo stack is empty!'
|
||||
}));
|
||||
deferred.resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
this.mainVis.reset(toRestore);
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
}, this.mainVis.getAnimationTime());
|
||||
},
|
||||
|
||||
commandSubmitted: function(value) {
|
||||
// allow other things to see this command (aka command history on terminal)
|
||||
Main.getEvents().trigger('commandSubmittedPassive', value);
|
||||
|
@ -196,6 +230,7 @@ var Sandbox = Backbone.View.extend({
|
|||
// some exceptions to the rule
|
||||
var commandMap = {
|
||||
'reset solved': this.resetSolved,
|
||||
'undo': this.undo,
|
||||
'help general': this.helpDialog,
|
||||
'help': this.helpDialog,
|
||||
'reset': this.reset,
|
||||
|
@ -349,6 +384,7 @@ var Sandbox = Backbone.View.extend({
|
|||
|
||||
reset: function(command, deferred) {
|
||||
this.mainVis.reset();
|
||||
this.initUndoStack();
|
||||
|
||||
setTimeout(function() {
|
||||
command.finishWith(deferred);
|
||||
|
|
|
@ -57,7 +57,8 @@ var regexMap = {
|
|||
'build level': /^build level($|\s)/,
|
||||
'export tree': /^export tree$/,
|
||||
'import tree': /^import tree$/,
|
||||
'import level': /^import level$/
|
||||
'import level': /^import level$/,
|
||||
'undo': /^undo($|\s)/
|
||||
};
|
||||
|
||||
exports.instantCommands = instantCommands;
|
||||
|
|
|
@ -131,10 +131,11 @@ var Visualization = Backbone.View.extend({
|
|||
this.treeString = treeString;
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
reset: function(tree) {
|
||||
var treeString = tree || this.treeString;
|
||||
this.setTreeOpacity(0);
|
||||
if (this.treeString) {
|
||||
this.gitEngine.loadTreeFromString(this.treeString);
|
||||
this.gitEngine.loadTreeFromString(treeString);
|
||||
} else {
|
||||
this.gitEngine.defaultInit();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue