fixing some more bugs

This commit is contained in:
Peter Cottle 2012-09-15 23:32:06 -07:00
parent 8ebb53b983
commit 94db9a3c7d
6 changed files with 37 additions and 11 deletions

View file

@ -33,12 +33,9 @@ var CommandBuffer = Backbone.Model.extend({
// processed. if it's not, we immediately process the first item // processed. if it's not, we immediately process the first item
// and then set the timeout. // and then set the timeout.
if (this.timeout) { if (this.timeout) {
console.log('timeout exists abort');
// timeout existence implies its being processed // timeout existence implies its being processed
return; return;
} }
console.log(this.timeout);
console.log('setting timeout');
this.setTimeout(); this.setTimeout();
}, },
@ -57,11 +54,13 @@ var CommandBuffer = Backbone.Model.extend({
// find a command with no error // find a command with no error
while (popped.get('error') && this.buffer.length) { while (popped.get('error') && this.buffer.length) {
popped = buffer.pop(); popped = this.buffer.pop();
} }
if (!popped.get('error')) { if (!popped.get('error')) {
// pass in a callback, so when this command is "done" we will process the next. // pass in a callback, so when this command is "done" we will process the next.
events.trigger('processCommand', popped, callback); events.trigger('processCommand', popped, callback);
} else {
this.clear();
} }
}, },

View file

@ -18,6 +18,7 @@ var Command = Backbone.Model.extend({
if (!this.get('createTime')) { if (!this.get('createTime')) {
this.set('createTime', new Date().toString()); this.set('createTime', new Date().toString());
} }
this.on('change:error', this.errorChanged, this);
}, },
initialize: function() { initialize: function() {
@ -31,20 +32,25 @@ var Command = Backbone.Model.extend({
} catch (err) { } catch (err) {
if (err instanceof CommandProcessError || if (err instanceof CommandProcessError ||
err instanceof GitError) { err instanceof GitError) {
this.formatError(err);
this.set('status', 'error'); this.set('status', 'error');
this.set('error', err);
} else if (err instanceof CommandResult) { } else if (err instanceof CommandResult) {
this.formatError(err);
this.set('status', 'finished'); this.set('status', 'finished');
this.set('error', err);
} else { } else {
throw err; throw err;
} }
} }
}, },
formatError: function(err) { errorChanged: function(model, err) {
this.set('error', err); this.set('err', err);
this.set('result', err.toResult()); this.set('status', 'error');
this.formatError();
},
formatError: function() {
this.set('result', this.get('err').toResult());
}, },
getShortcutMap: function() { getShortcutMap: function() {

View file

@ -692,7 +692,21 @@ GitEngine.prototype.dispatch = function(command, callback) {
}); });
command.set('status', 'processing'); command.set('status', 'processing');
try {
this[command.get('method') + 'Starter'](); this[command.get('method') + 'Starter']();
} catch (err) {
if (err instanceof GitError ||
err instanceof CommandResult) {
// short circuit animation by just setting error and returning
command.set('error', err);
callback();
return;
} else {
throw err;
}
}
// TODO (get rid of) // TODO (get rid of)
for (var i = 0; i < 3; i++) { for (var i = 0; i < 3; i++) {

View file

@ -36,6 +36,8 @@ $(document).ready(function(){
gitEngine = new GitEngine(); gitEngine = new GitEngine();
gitVisuals = new GitVisuals(); gitVisuals = new GitVisuals();
$('#commandTextField').focus();
}); });

View file

@ -108,12 +108,16 @@ var CommandView = Backbone.View.extend({
}, },
wasChanged: function(model, changeEvent) { wasChanged: function(model, changeEvent) {
console.log('command changed', model, changeEvent);
// for changes that are just comestic, we actually only want to toggle classes // for changes that are just comestic, we actually only want to toggle classes
// with jquery rather than brutally delete a html of HTML // with jquery rather than brutally delete a html of HTML
var changes = changeEvent.changes; var changes = changeEvent.changes;
var changeKeys = _.keys(changes); var changeKeys = _.keys(changes);
if (_.difference(changeKeys, ['status']) == 0) { if (_.difference(changeKeys, ['status']) == 0) {
this.updateStatus(); this.updateStatus();
} else if (_.difference(changeKeys, ['error']) == 0) {
// the above will
this.render();
} else { } else {
this.render(); this.render();
} }
@ -160,6 +164,8 @@ var CommandLineHistoryView = Backbone.View.extend({
this.collection.on('add', this.addOne, this); this.collection.on('add', this.addOne, this);
this.collection.on('reset', this.addAll, this); this.collection.on('reset', this.addAll, this);
this.collection.on('all', this.render, this); this.collection.on('all', this.render, this);
this.collection.on('change', this.scrollDown, this);
}, },
scrollDown: function() { scrollDown: function() {

View file

@ -7,7 +7,6 @@ function GitVisuals() {
} }
GitVisuals.prototype.drawVisuals = function(sys, ctx, canvas) { GitVisuals.prototype.drawVisuals = function(sys, ctx, canvas) {
this.drawRefs(sys, ctx, canvas); this.drawRefs(sys, ctx, canvas);
}; };