mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-10 15:02:07 +01:00
Moved commands to a separate file.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
25
app/commandsCatalog.js
Normal file
25
app/commandsCatalog.js
Normal file
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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';
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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<handlers.length; i++) {
|
||||
if(handlers[i].canHandle(input)) {
|
||||
return handlers[i];
|
||||
@@ -78,15 +85,5 @@ app.compose(function() {
|
||||
resultView.display(new app.models.DisplayResult(input, error));
|
||||
}
|
||||
};
|
||||
|
||||
dispatcher.command('clear', function() {
|
||||
app.controller('resultViewCtrl').clear();
|
||||
});
|
||||
|
||||
dispatcher.command('em', function() {
|
||||
app.cmdConfig.emphasizeBytes = !app.cmdConfig.emphasizeBytes;
|
||||
});
|
||||
|
||||
return dispatcher;
|
||||
});
|
||||
});
|
||||
|
||||
28
index.html
28
index.html
@@ -30,6 +30,8 @@
|
||||
<script type="text/javascript" src="app/dispatcher.js"></script>
|
||||
<script type="text/javascript" src="app/services.js"></script>
|
||||
<script type="text/javascript" src="app/controllers.js"></script>
|
||||
<script type="text/javascript" src="app/commandsCatalog.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="css/styles.css" />
|
||||
</head>
|
||||
<body id="rootView">
|
||||
@@ -44,7 +46,7 @@
|
||||
<input id="in" type="text" class="expressionInput" data-controller="expressionInputCtrl" placeholder="type expression like '1>>2' or 'help' "/>
|
||||
|
||||
<span data-controller="configPanelCtrl" class="configPnl">
|
||||
<span id="emphasizeBytes" class="indicator">Emphasize Bytes<span>
|
||||
<span id="emphasizeBytes" class="indicator">Emphasize Bytes</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -127,30 +129,8 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
var app = window.app;
|
||||
|
||||
app.run(function(){
|
||||
|
||||
var dispatcher = app.get('dispatcher');
|
||||
|
||||
dispatcher.command('help', function() {
|
||||
return new app.models.HelpResult();
|
||||
});
|
||||
|
||||
// TODO: Make as function
|
||||
dispatcher.command({
|
||||
$expression:null,
|
||||
canHandle: function(input) { return app.get('expression').canParse(input); },
|
||||
handle: function(input) {
|
||||
return app.get('expression').parse(input);
|
||||
}
|
||||
});
|
||||
|
||||
app.emphasizeBytes = true; // TODO: Make into model
|
||||
app.debugMode = true;
|
||||
|
||||
});
|
||||
|
||||
app.bootstrap(document.getElementById('rootView'));
|
||||
|
||||
app.get('dispatcher').dispatch('help');
|
||||
app.get('dispatcher').dispatch('1|2');
|
||||
app.get('dispatcher').dispatch('1 2');
|
||||
|
||||
Reference in New Issue
Block a user