ENiGMA 1/2 WILL USE SPACES FROM THIS POINT ON VS TABS
* Really just to make GitHub formatting happy. Arg.
This commit is contained in:
@@ -22,186 +22,186 @@ const _ = require('lodash');
|
||||
exports.MCIViewFactory = MCIViewFactory;
|
||||
|
||||
function MCIViewFactory(client) {
|
||||
this.client = client;
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
MCIViewFactory.UserViewCodes = [
|
||||
'TL', 'ET', 'ME', 'MT', 'PL', 'BT', 'VM', 'HM', 'SM', 'TM', 'KE',
|
||||
'TL', 'ET', 'ME', 'MT', 'PL', 'BT', 'VM', 'HM', 'SM', 'TM', 'KE',
|
||||
|
||||
//
|
||||
// XY is a special MCI code that allows finding positions
|
||||
// and counts for key lookup, but does not explicitly
|
||||
// represent a visible View on it's own
|
||||
//
|
||||
'XY',
|
||||
//
|
||||
// XY is a special MCI code that allows finding positions
|
||||
// and counts for key lookup, but does not explicitly
|
||||
// represent a visible View on it's own
|
||||
//
|
||||
'XY',
|
||||
];
|
||||
|
||||
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||
assert(mci.code);
|
||||
assert(mci.id > 0);
|
||||
assert(mci.position);
|
||||
assert(mci.code);
|
||||
assert(mci.id > 0);
|
||||
assert(mci.position);
|
||||
|
||||
var view;
|
||||
var options = {
|
||||
client : this.client,
|
||||
id : mci.id,
|
||||
ansiSGR : mci.SGR,
|
||||
ansiFocusSGR : mci.focusSGR,
|
||||
position : { row : mci.position[0], col : mci.position[1] },
|
||||
};
|
||||
var view;
|
||||
var options = {
|
||||
client : this.client,
|
||||
id : mci.id,
|
||||
ansiSGR : mci.SGR,
|
||||
ansiFocusSGR : mci.focusSGR,
|
||||
position : { row : mci.position[0], col : mci.position[1] },
|
||||
};
|
||||
|
||||
// :TODO: These should use setPropertyValue()!
|
||||
function setOption(pos, name) {
|
||||
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
||||
options[name] = mci.args[pos];
|
||||
}
|
||||
}
|
||||
// :TODO: These should use setPropertyValue()!
|
||||
function setOption(pos, name) {
|
||||
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
||||
options[name] = mci.args[pos];
|
||||
}
|
||||
}
|
||||
|
||||
function setWidth(pos) {
|
||||
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
||||
if(!_.isObject(options.dimens)) {
|
||||
options.dimens = {};
|
||||
}
|
||||
options.dimens.width = parseInt(mci.args[pos], 10);
|
||||
}
|
||||
}
|
||||
function setWidth(pos) {
|
||||
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
||||
if(!_.isObject(options.dimens)) {
|
||||
options.dimens = {};
|
||||
}
|
||||
options.dimens.width = parseInt(mci.args[pos], 10);
|
||||
}
|
||||
}
|
||||
|
||||
function setFocusOption(pos, name) {
|
||||
if(mci.focusArgs && mci.focusArgs.length > pos && mci.focusArgs[pos].length > 0) {
|
||||
options[name] = mci.focusArgs[pos];
|
||||
}
|
||||
}
|
||||
function setFocusOption(pos, name) {
|
||||
if(mci.focusArgs && mci.focusArgs.length > pos && mci.focusArgs[pos].length > 0) {
|
||||
options[name] = mci.focusArgs[pos];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Note: Keep this in sync with UserViewCodes above!
|
||||
//
|
||||
switch(mci.code) {
|
||||
// Text Label (Text View)
|
||||
case 'TL' :
|
||||
setOption(0, 'textStyle');
|
||||
setOption(1, 'justify');
|
||||
setWidth(2);
|
||||
//
|
||||
// Note: Keep this in sync with UserViewCodes above!
|
||||
//
|
||||
switch(mci.code) {
|
||||
// Text Label (Text View)
|
||||
case 'TL' :
|
||||
setOption(0, 'textStyle');
|
||||
setOption(1, 'justify');
|
||||
setWidth(2);
|
||||
|
||||
view = new TextView(options);
|
||||
break;
|
||||
view = new TextView(options);
|
||||
break;
|
||||
|
||||
// Edit Text
|
||||
case 'ET' :
|
||||
setWidth(0);
|
||||
// Edit Text
|
||||
case 'ET' :
|
||||
setWidth(0);
|
||||
|
||||
setOption(1, 'textStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
setOption(1, 'textStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
|
||||
view = new EditTextView(options);
|
||||
break;
|
||||
view = new EditTextView(options);
|
||||
break;
|
||||
|
||||
// Masked Edit Text
|
||||
case 'ME' :
|
||||
setOption(0, 'textStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
// Masked Edit Text
|
||||
case 'ME' :
|
||||
setOption(0, 'textStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
|
||||
view = new MaskEditTextView(options);
|
||||
break;
|
||||
view = new MaskEditTextView(options);
|
||||
break;
|
||||
|
||||
// Multi Line Edit Text
|
||||
case 'MT' :
|
||||
// :TODO: apply params
|
||||
view = new MultiLineEditTextView(options);
|
||||
break;
|
||||
// Multi Line Edit Text
|
||||
case 'MT' :
|
||||
// :TODO: apply params
|
||||
view = new MultiLineEditTextView(options);
|
||||
break;
|
||||
|
||||
// Pre-defined Label (Text View)
|
||||
// :TODO: Currently no real point of PL -- @method replaces this pretty much... probably remove
|
||||
case 'PL' :
|
||||
if(mci.args.length > 0) {
|
||||
options.text = getPredefinedMCIValue(this.client, mci.args[0]);
|
||||
if(options.text) {
|
||||
setOption(1, 'textStyle');
|
||||
setOption(2, 'justify');
|
||||
setWidth(3);
|
||||
// Pre-defined Label (Text View)
|
||||
// :TODO: Currently no real point of PL -- @method replaces this pretty much... probably remove
|
||||
case 'PL' :
|
||||
if(mci.args.length > 0) {
|
||||
options.text = getPredefinedMCIValue(this.client, mci.args[0]);
|
||||
if(options.text) {
|
||||
setOption(1, 'textStyle');
|
||||
setOption(2, 'justify');
|
||||
setWidth(3);
|
||||
|
||||
view = new TextView(options);
|
||||
}
|
||||
}
|
||||
break;
|
||||
view = new TextView(options);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// Button
|
||||
case 'BT' :
|
||||
if(mci.args.length > 0) {
|
||||
options.dimens = { width : parseInt(mci.args[0], 10) };
|
||||
}
|
||||
// Button
|
||||
case 'BT' :
|
||||
if(mci.args.length > 0) {
|
||||
options.dimens = { width : parseInt(mci.args[0], 10) };
|
||||
}
|
||||
|
||||
setOption(1, 'textStyle');
|
||||
setOption(2, 'justify');
|
||||
setOption(1, 'textStyle');
|
||||
setOption(2, 'justify');
|
||||
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
|
||||
view = new ButtonView(options);
|
||||
break;
|
||||
view = new ButtonView(options);
|
||||
break;
|
||||
|
||||
// Vertial Menu
|
||||
case 'VM' :
|
||||
setOption(0, 'itemSpacing');
|
||||
setOption(1, 'justify');
|
||||
setOption(2, 'textStyle');
|
||||
// Vertial Menu
|
||||
case 'VM' :
|
||||
setOption(0, 'itemSpacing');
|
||||
setOption(1, 'justify');
|
||||
setOption(2, 'textStyle');
|
||||
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
|
||||
view = new VerticalMenuView(options);
|
||||
break;
|
||||
view = new VerticalMenuView(options);
|
||||
break;
|
||||
|
||||
// Horizontal Menu
|
||||
case 'HM' :
|
||||
setOption(0, 'itemSpacing');
|
||||
setOption(1, 'textStyle');
|
||||
// Horizontal Menu
|
||||
case 'HM' :
|
||||
setOption(0, 'itemSpacing');
|
||||
setOption(1, 'textStyle');
|
||||
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
|
||||
view = new HorizontalMenuView(options);
|
||||
break;
|
||||
view = new HorizontalMenuView(options);
|
||||
break;
|
||||
|
||||
case 'SM' :
|
||||
setOption(0, 'textStyle');
|
||||
setOption(1, 'justify');
|
||||
case 'SM' :
|
||||
setOption(0, 'textStyle');
|
||||
setOption(1, 'justify');
|
||||
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
|
||||
view = new SpinnerMenuView(options);
|
||||
break;
|
||||
view = new SpinnerMenuView(options);
|
||||
break;
|
||||
|
||||
case 'TM' :
|
||||
if(mci.args.length > 0) {
|
||||
var styleSG1 = { fg : parseInt(mci.args[0], 10) };
|
||||
if(mci.args.length > 1) {
|
||||
styleSG1.bg = parseInt(mci.args[1], 10);
|
||||
}
|
||||
options.styleSG1 = ansi.getSGRFromGraphicRendition(styleSG1, true);
|
||||
}
|
||||
case 'TM' :
|
||||
if(mci.args.length > 0) {
|
||||
var styleSG1 = { fg : parseInt(mci.args[0], 10) };
|
||||
if(mci.args.length > 1) {
|
||||
styleSG1.bg = parseInt(mci.args[1], 10);
|
||||
}
|
||||
options.styleSG1 = ansi.getSGRFromGraphicRendition(styleSG1, true);
|
||||
}
|
||||
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
setFocusOption(0, 'focusTextStyle');
|
||||
|
||||
view = new ToggleMenuView(options);
|
||||
break;
|
||||
view = new ToggleMenuView(options);
|
||||
break;
|
||||
|
||||
case 'KE' :
|
||||
view = new KeyEntryView(options);
|
||||
break;
|
||||
case 'KE' :
|
||||
view = new KeyEntryView(options);
|
||||
break;
|
||||
|
||||
default :
|
||||
options.text = getPredefinedMCIValue(this.client, mci.code);
|
||||
if(_.isString(options.text)) {
|
||||
setWidth(0);
|
||||
default :
|
||||
options.text = getPredefinedMCIValue(this.client, mci.code);
|
||||
if(_.isString(options.text)) {
|
||||
setWidth(0);
|
||||
|
||||
setOption(1, 'textStyle');
|
||||
setOption(2, 'justify');
|
||||
setOption(1, 'textStyle');
|
||||
setOption(2, 'justify');
|
||||
|
||||
view = new TextView(options);
|
||||
}
|
||||
break;
|
||||
}
|
||||
view = new TextView(options);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(view) {
|
||||
view.mciCode = mci.code;
|
||||
}
|
||||
if(view) {
|
||||
view.mciCode = mci.code;
|
||||
}
|
||||
|
||||
return view;
|
||||
return view;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user