diff --git a/app/app.js b/app/app.js index 9433b37..f0b1381 100644 --- a/app/app.js +++ b/app/app.js @@ -4,9 +4,9 @@ var app = new core.AppShell(di); - app.cmdConfig = core.ObservableObject.create({ + app.set('cmdConfig', core.ObservableObject.create({ emphasizeBytes: true - }); + })); app.debugMode = false; diff --git a/app/commandsCatalog.js b/app/commandsCatalog.js new file mode 100644 index 0000000..180e80e --- /dev/null +++ b/app/commandsCatalog.js @@ -0,0 +1,25 @@ +app.run(function() { + + var dispatcher = app.get('dispatcher'); + + dispatcher.commands({ + 'help': function() { + return new app.models.HelpResult(); + }, + 'clear': function() { + app.controller('resultViewCtrl').clear(); + }, + 'em': function() { + var cfg = app.get('cmdConfig'); + cfg.emphasizeBytes = !cfg.cmdConfig.emphasizeBytes; + } + }); + + // TODO: Make as function + dispatcher.command({ + canHandle: function(input) { return app.get('expression').canParse(input); }, + handle: function(input) { + return app.get('expression').parse(input); + } + }); +}); diff --git a/app/controllers.js b/app/controllers.js index ffb5ad1..78259cc 100644 --- a/app/controllers.js +++ b/app/controllers.js @@ -46,7 +46,6 @@ app.compose(function() { } args.preventDefault(); - return; } }) } @@ -77,14 +76,16 @@ app.compose(function() { app.controller('configPanelCtrl', { onViewAttached: function (){ var self = this; - self.update(); - app.cmdConfig.observe(function(){ - self.update(); + var cfg = app.get('cmdConfig'); + self.update(cfg); + + cfg.observe(function(){ + self.update(cfg); }); }, - update: function () { + update: function (cfg) { var emIndicator = this.viewElement.querySelector('#emphasizeBytes'); - emIndicator.style.display = app.cmdConfig.emphasizeBytes ? '' : 'none'; + emIndicator.style.display = cfg.emphasizeBytes ? '' : 'none'; } }); diff --git a/app/dispatcher.js b/app/dispatcher.js index aea14cf..dd58c05 100644 --- a/app/dispatcher.js +++ b/app/dispatcher.js @@ -4,7 +4,7 @@ app.compose(function() { var is = app.get('is'); var resultView = app.controller('resultViewCtrl'); - var dispatcher = { + return { dispatch: function(rawInput) { var input = rawInput.trim(); var handler = this.findHandler(input); @@ -28,6 +28,13 @@ app.compose(function() { // app.command('dispatchInput').execute({input:input}); }, + commands: function(catalog) { + for(var key in catalog) { + if(catalog.hasOwnProperty(key)) { + this.command(key, catalog[key]); + } + } + }, command: function(cmd, handler) { var h = this.createHandler(cmd, handler); if(h == null){ @@ -59,7 +66,7 @@ app.compose(function() { return null; }, findHandler: function (input) { - var i= 0, h; + var i= 0; for(i;i + + @@ -44,7 +46,7 @@ - Emphasize Bytes + Emphasize Bytes @@ -127,30 +129,8 @@