* Fix TextEditView when 'text' set by default

* Fix TextEditView row vs col
* Start skeleton on HorizontalMenuView
This commit is contained in:
Bryan Ashby 2015-06-28 22:31:12 -06:00
parent 670bf0fd6e
commit 541be2d65a
8 changed files with 79 additions and 74 deletions

View File

@ -72,16 +72,18 @@ function createUserTables() {
function createMessageBaseTables() { function createMessageBaseTables() {
dbs.message.run( dbs.message.run(
'CREATE TABLE IF NOT EXISTS message (' + 'CREATE TABLE IF NOT EXISTS message (' +
' message_id INTEGER PRIMARY KEY,' + ' message_id INTEGER PRIMARY KEY,' +
' area_id INTEGER NOT NULL,' + ' area_id INTEGER NOT NULL,' +
' message_uuid VARCHAR(36) NOT NULL,' + ' message_uuid VARCHAR(36) NOT NULL,' +
' reply_to_id INTEGER,' + ' reply_to_id INTEGER,' +
' to_user_name VARCHAR NOT NULL,' + ' to_user_name VARCHAR NOT NULL,' +
' from_user_name VARCHAR NOT NULL,' + ' from_user_name VARCHAR NOT NULL,' +
' subject,' + // FTS ' subject,' + // FTS @ message_fts
' message,' + // FTS ' message,' + // FTS @ message_fts
' modified_timestamp DATETIME' + ' modified_timestamp DATETIME NOT NULL,' +
' UNIQUE(message_id, area_id),' +
' UNIQUE(message_uuid)' +
');' ');'
); );

View File

@ -39,8 +39,8 @@ EditTextView.prototype.onKeyPress = function(ch, key) {
if(this.text.length >= this.dimens.width) { if(this.text.length >= this.dimens.width) {
this.redraw(); this.redraw();
} else { } else {
this.cursorPos.row -= 1; this.cursorPos.col -= 1;
if(this.cursorPos.row >= 0) { if(this.cursorPos.col >= 0) {
this.clientBackspace(); this.clientBackspace();
} }
} }
@ -49,7 +49,7 @@ EditTextView.prototype.onKeyPress = function(ch, key) {
return; return;
} else if(this.isSpecialKeyMapped('clearLine', key.name)) { } else if(this.isSpecialKeyMapped('clearLine', key.name)) {
this.text = ''; this.text = '';
this.cursorPos.row = 0; this.cursorPos.col = 0;
this.setFocus(true); // resetting focus will redraw & adjust cursor this.setFocus(true); // resetting focus will redraw & adjust cursor
return; return;
@ -66,7 +66,7 @@ EditTextView.prototype.onKeyPress = function(ch, key) {
// no shortcuts - redraw the view // no shortcuts - redraw the view
this.redraw(); this.redraw();
} else { } else {
this.cursorPos.row += 1; this.cursorPos.col += 1;
if(this.textMaskChar) { if(this.textMaskChar) {
this.client.term.write(this.textMaskChar); this.client.term.write(this.textMaskChar);
@ -80,57 +80,10 @@ EditTextView.prototype.onKeyPress = function(ch, key) {
EditTextView.super_.prototype.onKeyPress.call(this, ch, key); EditTextView.super_.prototype.onKeyPress.call(this, ch, key);
}; };
/* EditTextView.prototype.setText = function(text) {
EditTextView.prototype.onKeyPress = function(key, isSpecial) { // draw & set |text|
if(isSpecial) { EditTextView.super_.prototype.setText.call(this, text);
return;
}
assert(1 === key.length); // adjust local cursor tracking
this.cursorPos = { row : 0, col : text.length };
if(this.text.length < this.maxLength) {
key = strUtil.stylizeString(key, this.textStyle);
this.text += key;
if(this.text.length > this.dimens.width) {
// no shortcuts - redraw the view
this.redraw();
} else {
this.cursorPos.row += 1;
if(this.textMaskChar) {
this.client.term.write(this.textMaskChar);
} else {
this.client.term.write(key);
}
}
}
EditTextView.super_.prototype.onKeyPress.call(this, key, isSpecial);
}; };
EditTextView.prototype.onSpecialKeyPress = function(keyName) {
if(this.isSpecialKeyMapped('backspace', keyName)) {
if(this.text.length > 0) {
this.text = this.text.substr(0, this.text.length - 1);
if(this.text.length >= this.dimens.width) {
this.redraw();
} else {
this.cursorPos.row -= 1;
if(this.cursorPos.row >= 0) {
this.clientBackspace();
}
}
}
} else if(this.isSpecialKeyMapped('clearLine', keyName)) {
this.text = '';
this.cursorPos.row = 0;
this.setFocus(true); // resetting focus will redraw & adjust cursor
}
EditTextView.super_.prototype.onSpecialKeyPress.call(this, keyName);
};
*/

View File

@ -0,0 +1,50 @@
/* jslint node: true */
'use strict';
var MenuView = require('./menu_view.js').MenuView;
var ansi = require('./ansi_term.js');
var strUtil = require('./string_util.js');
function HorizontalMenuView = function(options) {
options.cursor = options.cursor || 'hide';
MenuView.call(this, options);
var self = this;
}
require('util').inherits(HorizontalMenuView, MenuView);
HorizontalMenuView.prototype.redraw = function() {
HorizontalMenuView.super_.prototype.redraw.call(this);
};
HorizontalMenuView.prototype.setPosition = function(pos) {
HorizontalMenuView.super_.prototype.setPosition.call(this, pos);
};
HorizontalMenuView.prototype.setFocus = function(focused) {
HorizontalMenuView.super_.prototype.setFocus.call(this, focused);
this.redraw();
};
HorizontalMenuView.prototype.setItems = function(items) {
HorizontalMenuView.super_.prototype.setItems.call(this, items);
//
// Styles:
// * itemPadding: n
// *
//
//
// item1 item2 itemThree itemfour!!!!!
// ^^^^^^^^^
//
// item1 item2 itemThree item!!!!!
// ^^^^^^^
};

View File

@ -115,6 +115,7 @@ function stylizeString(s, style) {
} }
// Based on http://www.webtoolkit.info/ // Based on http://www.webtoolkit.info/
// :TODO: Look into lodash padLeft, padRight, etc.
function pad(s, len, padChar, dir, stringSGR, padSGR) { function pad(s, len, padChar, dir, stringSGR, padSGR) {
len = miscUtil.valueWithDefault(len, 0); len = miscUtil.valueWithDefault(len, 0);
padChar = miscUtil.valueWithDefault(padChar, ' '); padChar = miscUtil.valueWithDefault(padChar, ' ');

View File

@ -24,7 +24,7 @@ function TextView(options) {
if(options.maxLength) { if(options.maxLength) {
this.maxLength = options.maxLength; this.maxLength = options.maxLength;
} else { } else {
this.maxLength = this.client.term.termWidth - this.position.row; this.maxLength = this.client.term.termWidth - this.position.col;
} }
this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1); this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1);

View File

@ -14,7 +14,7 @@ exports.VerticalMenuView = VerticalMenuView;
function VerticalMenuView(options) { function VerticalMenuView(options) {
options.cursor = options.cursor || 'hide'; options.cursor = options.cursor || 'hide';
options.justify = options.justify || 'right'; options.justify = options.justify || 'right'; // :TODO: default to center
MenuView.call(this, options); MenuView.call(this, options);

View File

@ -68,7 +68,7 @@ function FullScreenEditorModule(options) {
this.menuMethods = { this.menuMethods = {
editorEscPressed : function(formData, extraArgs) { editorEscPressed : function(formData, extraArgs) {
} }
}; };
} }

View File

@ -442,17 +442,16 @@
"ET1ET2MT3" : { "ET1ET2MT3" : {
"mci" : { "mci" : {
"ET1" : { "ET1" : {
"width" : 20, "width" : 20,
"text" : "FIXME: to" "placeholder" : "TODO support this",
"focus" : true
}, },
"ET2" : { "ET2" : {
"width" : 20, "width" : 20
"text" : "FIXME: from"
}, },
"MT3" : { "MT3" : {
"width" : 79, "width" : 79,
"height" : 17, "height" : 17,
"focus" : true,
"text" : "", "text" : "",
"submit" : [ "escape" ] "submit" : [ "escape" ]
} }