adding the convept of next/previous to values in the command line
This commit is contained in:
parent
596fc88708
commit
e9fd963724
7 changed files with 310 additions and 144 deletions
|
|
@ -45,6 +45,7 @@ var EventEmitter = require('pilot/event_emitter').EventEmitter;
|
|||
var catalog = require('pilot/catalog');
|
||||
var Status = require('pilot/types').Status;
|
||||
var types = require('pilot/types');
|
||||
var util = require('pilot/util');
|
||||
|
||||
/*
|
||||
// TODO: this doesn't belong here - or maybe anywhere?
|
||||
|
|
@ -105,8 +106,16 @@ var thingCommand = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A lookup hash of our registered commands
|
||||
*/
|
||||
var commands = {};
|
||||
|
||||
/**
|
||||
* A sorted list of command names, we regularly want them in order, so pre-sort
|
||||
*/
|
||||
var commandNames = [];
|
||||
|
||||
/**
|
||||
* This registration method isn't like other Ace registration methods because
|
||||
* it doesn't return a decorated command because there is no functional
|
||||
|
|
@ -131,6 +140,9 @@ function addCommand(command) {
|
|||
upgradeType(param);
|
||||
}, this);
|
||||
commands[command.name] = command;
|
||||
|
||||
commandNames.push(command.name);
|
||||
commandNames.sort();
|
||||
};
|
||||
|
||||
function upgradeType(param) {
|
||||
|
|
@ -143,12 +155,9 @@ function upgradeType(param) {
|
|||
}
|
||||
|
||||
function removeCommand(command) {
|
||||
if (typeof command === 'string') {
|
||||
delete commands[command];
|
||||
}
|
||||
else {
|
||||
delete commands[command.name];
|
||||
}
|
||||
var name = (typeof command === 'string' ? command : command.name);
|
||||
delete commands[name];
|
||||
util.arrayRemove(commandNames, name);
|
||||
};
|
||||
|
||||
function getCommand(name) {
|
||||
|
|
@ -156,7 +165,7 @@ function getCommand(name) {
|
|||
};
|
||||
|
||||
function getCommandNames() {
|
||||
return Object.keys(commands);
|
||||
return commandNames;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -146,12 +146,13 @@ oop.implement(Setting.prototype, EventEmitter);
|
|||
* @constructor
|
||||
*/
|
||||
function Settings(persister) {
|
||||
/**
|
||||
* Storage for deactivated values
|
||||
*/
|
||||
// Storage for deactivated values
|
||||
this._deactivated = {};
|
||||
|
||||
// Storage for the active settings
|
||||
this._settings = {};
|
||||
// We often want sorted setting names. Cache
|
||||
this._settingNames = [];
|
||||
|
||||
if (persister) {
|
||||
this.setPersister(persister);
|
||||
|
|
@ -175,14 +176,18 @@ Settings.prototype = {
|
|||
addSetting: function(settingSpec) {
|
||||
var setting = new Setting(settingSpec, this);
|
||||
this._settings[setting.name] = setting;
|
||||
this._settingNames.push(setting.name);
|
||||
this._settingNames.sort();
|
||||
},
|
||||
|
||||
removeSetting: function(name) {
|
||||
removeSetting: function(setting) {
|
||||
var name = (typeof setting === 'string' ? setting : setting.name);
|
||||
delete this._settings[name];
|
||||
util.arrayRemove(this._settingNames, name);
|
||||
},
|
||||
|
||||
getSettingNames: function() {
|
||||
return Object.keys(this._settings);
|
||||
return this._settingNames;
|
||||
},
|
||||
|
||||
getSetting: function(name) {
|
||||
|
|
|
|||
|
|
@ -163,7 +163,23 @@ Type.prototype = {
|
|||
* <p>In old bespin, equality was based on the name. This may turn out to be
|
||||
* important in Ace too.
|
||||
*/
|
||||
name: undefined
|
||||
name: undefined,
|
||||
|
||||
/**
|
||||
* If there is some concept of a higher value, return it,
|
||||
* otherwise return undefined.
|
||||
*/
|
||||
increment: function(value) {
|
||||
return undefined;
|
||||
},
|
||||
|
||||
/**
|
||||
* If there is some concept of a lower value, return it,
|
||||
* otherwise return undefined.
|
||||
*/
|
||||
decrement: function(value) {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
exports.Type = Type;
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,10 @@ number.parse = function(value) {
|
|||
throw new Error('non-string passed to number.parse()');
|
||||
}
|
||||
|
||||
if (value.replace(/\s/g, '').length === 0) {
|
||||
return new Conversion(null, Status.INCOMPLETE, '');
|
||||
}
|
||||
|
||||
var reply = new Conversion(parseInt(value, 10));
|
||||
if (isNaN(reply.value)) {
|
||||
reply.status = Status.INVALID;
|
||||
|
|
@ -99,6 +103,14 @@ number.parse = function(value) {
|
|||
return reply;
|
||||
};
|
||||
|
||||
number.decrement = function(value) {
|
||||
return value - 1;
|
||||
};
|
||||
|
||||
number.increment = function(value) {
|
||||
return value + 1;
|
||||
};
|
||||
|
||||
number.name = 'number';
|
||||
|
||||
/**
|
||||
|
|
@ -126,7 +138,7 @@ SelectionType.prototype.parse = function(str) {
|
|||
if (!this.data) {
|
||||
throw new Error('Missing data on selection type extension.');
|
||||
}
|
||||
var data = (typeof(this.data) === "function") ? this.data() : this.data;
|
||||
var data = (typeof(this.data) === 'function') ? this.data() : this.data;
|
||||
|
||||
// The matchedValue could be the boolean value false
|
||||
var hasMatched = false;
|
||||
|
|
@ -162,6 +174,34 @@ SelectionType.prototype.fromString = function(str) {
|
|||
return str;
|
||||
};
|
||||
|
||||
SelectionType.prototype.decrement = function(value) {
|
||||
var data = (typeof this.data === 'function') ? this.data() : this.data;
|
||||
var index;
|
||||
if (value == null) {
|
||||
index = data.length - 1;
|
||||
}
|
||||
else {
|
||||
var name = this.stringify(value);
|
||||
var index = data.indexOf(name);
|
||||
index = (index === 0 ? data.length - 1 : index - 1);
|
||||
}
|
||||
return this.fromString(data[index]);
|
||||
};
|
||||
|
||||
SelectionType.prototype.increment = function(value) {
|
||||
var data = (typeof this.data === 'function') ? this.data() : this.data;
|
||||
var index;
|
||||
if (value == null) {
|
||||
index = 0;
|
||||
}
|
||||
else {
|
||||
var name = this.stringify(value);
|
||||
var index = data.indexOf(name);
|
||||
index = (index === data.length - 1 ? 0 : index + 1);
|
||||
}
|
||||
return this.fromString(data[index]);
|
||||
};
|
||||
|
||||
SelectionType.prototype.name = 'selection';
|
||||
|
||||
/**
|
||||
|
|
@ -206,6 +246,16 @@ DeferredType.prototype.parse = function(value) {
|
|||
return this.defer().parse(value);
|
||||
};
|
||||
|
||||
DeferredType.prototype.decrement = function(value) {
|
||||
var deferred = this.defer();
|
||||
return (deferred.decrement ? deferred.decrement(value) : undefined);
|
||||
};
|
||||
|
||||
DeferredType.prototype.increment = function(value) {
|
||||
var deferred = this.defer();
|
||||
return (deferred.increment ? deferred.increment(value) : undefined);
|
||||
};
|
||||
|
||||
DeferredType.prototype.name = 'deferred';
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue