moving slowly towards other things processing

This commit is contained in:
Peter Cottle 2013-01-01 22:12:25 -08:00
parent 423a353e28
commit a180426cfb
6 changed files with 571 additions and 544 deletions

File diff suppressed because it is too large Load diff

View file

@ -3,6 +3,8 @@ var Backbone = require('backbone');
var Constants = require('../util/constants'); var Constants = require('../util/constants');
var Views = require('../views'); var Views = require('../views');
var util = require('../util');
var Command = require('../models/commandModel').Command;
/** /**
* Globals * Globals
@ -37,7 +39,7 @@ var init = function(){
eventBaton.trigger('documentClick', e); eventBaton.trigger('documentClick', e);
}); });
// zoom level measure, I wish there was a jquery event for this // zoom level measure, I wish there was a jquery event for this :/
require('../util/zoomLevel').setupZoomPoll(function(level) { require('../util/zoomLevel').setupZoomPoll(function(level) {
eventBaton.trigger('zoomChange', level); eventBaton.trigger('zoomChange', level);
}, this); }, this);
@ -87,8 +89,6 @@ function UI() {
collection: this.commandCollection collection: this.commandCollection
}); });
// command prompt event fires an event when commands are ready,
// hence it doesn't need access to the collection anymore
this.commandPromptView = new CommandViews.CommandPromptView({ this.commandPromptView = new CommandViews.CommandPromptView({
el: $('#commandLineBar') el: $('#commandLineBar')
}); });
@ -97,8 +97,19 @@ function UI() {
el: $('#commandLineHistory'), el: $('#commandLineHistory'),
collection: this.commandCollection collection: this.commandCollection
}); });
eventBaton.stealBaton('commandSubmitted', this.commandSubmitted, this);
} }
UI.prototype.commandSubmitted = function(value) {
events.trigger('commandSubmittedPassive', value);
util.splitTextCommand(value, function(command) {
this.commandCollection.add(new Command({
rawStr: command
}));
}, this);
};
exports.getEvents = function() { exports.getEvents = function() {
return events; return events;
}; };

View file

@ -15,6 +15,8 @@ var keyboard = require('../util/keyboard');
var CommandPromptView = Backbone.View.extend({ var CommandPromptView = Backbone.View.extend({
initialize: function(options) { initialize: function(options) {
Main.getEvents().on('commandSubmittedPassive', this.addToCommandHistory, this);
// uses local storage // uses local storage
this.commands = new CommandEntryCollection(); this.commands = new CommandEntryCollection();
this.commands.fetch({ this.commands.fetch({
@ -196,18 +198,19 @@ var CommandPromptView = Backbone.View.extend({
Backbone.sync('create', rolled, function() { }); Backbone.sync('create', rolled, function() { });
}, },
addToCommandHistory: function(value, index) { addToCommandHistory: function(value) {
// this method will fire from events too (like clicking on a visNode),
// so the index might not be present or relevant. a value of -1
// means we should add it regardless
index = (index === undefined) ? -1 : index;
// we should add the command to our local storage history // we should add the command to our local storage history
// if it's not a blank line and this is a new command... // if it's not a blank line and this is a new command...
// or if we edited the command in place in history // or if we edited the command in place in history
var shouldAdd = (value.length && index == -1) || var shouldAdd = (value.length && this.index === -1) ||
((value.length && index !== -1 && ((value.length && this.index !== -1 &&
this.commands.toArray()[index].get('text') !== value)); this.commands.toArray()[this.index].get('text') !== value));
if (this.index !== -1) {
console.log(this.commands.toArray()[this.index]);
}
console.log('should add', shouldAdd);
if (!shouldAdd) { if (!shouldAdd) {
return; return;
@ -227,11 +230,6 @@ var CommandPromptView = Backbone.View.extend({
submitCommand: function(value) { submitCommand: function(value) {
Main.getEventBaton().trigger('commandSubmitted', value); Main.getEventBaton().trigger('commandSubmitted', value);
/*
var command = new Command({
rawStr: value
});
*/
} }
}); });

View file

@ -4,6 +4,7 @@ var Backbone = require('backbone');
var GRAPHICS = require('../util/constants').GRAPHICS; var GRAPHICS = require('../util/constants').GRAPHICS;
var GLOBAL = require('../util/constants').GLOBAL; var GLOBAL = require('../util/constants').GLOBAL;
var Main = require('../app');
var Collections = require('../models/collections'); var Collections = require('../models/collections');
var CommitCollection = Collections.CommitCollection; var CommitCollection = Collections.CommitCollection;
@ -36,8 +37,7 @@ function GitVisuals(options) {
this.branchCollection.on('remove', this.removeBranch, this); this.branchCollection.on('remove', this.removeBranch, this);
this.deferred = []; this.deferred = [];
this.events = require('../app').getEvents(); Main.getEvents().on('refreshTree', this.refreshTree, this);
this.events.on('refreshTree', this.refreshTree, this);
} }
GitVisuals.prototype.defer = function(action) { GitVisuals.prototype.defer = function(action) {
@ -618,7 +618,7 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
GitVisuals.prototype.canvasResize = _.debounce(function(width, height) { GitVisuals.prototype.canvasResize = _.debounce(function(width, height) {
// refresh when we are ready // refresh when we are ready
if (GLOBAL.isAnimating) { if (GLOBAL.isAnimating) {
this.events.trigger('commandSubmitted', 'refresh'); Main.getEventBaton().trigger('commandSubmitted', 'refresh');
} else { } else {
this.refreshTree(); this.refreshTree();
} }

View file

@ -319,7 +319,7 @@ var VisBranch = VisBase.extend({
_.each(objs, function(rObj) { _.each(objs, function(rObj) {
rObj.click(function() { rObj.click(function() {
Main.getEvents().trigger('commandSubmitted', commandStr); Main.getEventBaton().trigger('commandSubmitted', commandStr);
}); });
$(rObj.node).css('cursor', 'pointer'); $(rObj.node).css('cursor', 'pointer');
}); });

View file

@ -318,7 +318,7 @@ var VisNode = VisBase.extend({
var Main = require('../app'); var Main = require('../app');
_.each([this.get('circle'), this.get('text')], function(rObj) { _.each([this.get('circle'), this.get('text')], function(rObj) {
rObj.click(function() { rObj.click(function() {
Main.getEvents().trigger('commandSubmitted', commandStr); Main.getEventBaton().trigger('commandSubmitted', commandStr);
}); });
$(rObj.node).css('cursor', 'pointer'); $(rObj.node).css('cursor', 'pointer');
}); });