* Fixes to actionKeys with new focus changes

* Various fixes, minor changes
This commit is contained in:
Bryan Ashby 2015-09-20 19:10:09 -06:00
parent b15d9a0bf8
commit b2592d0e71
8 changed files with 63 additions and 84 deletions

View File

@ -195,10 +195,9 @@ function FullScreenEditorModule(options) {
};
if(self.isReply()) {
msgOpts.replyToMsgId = self.replyToMessageId;
msgOpts.replyToMsgId = self.replyToMessage.messageId;
}
self.message = new Message(msgOpts);
};
@ -218,12 +217,29 @@ function FullScreenEditorModule(options) {
};
this.getMessage = function() {
if(self.isEditMode()) {
self.buildMessage();
}
this.getMessage = function(cb) {
async.series(
[
function buildIfNecessary(callback) {
if(self.isEditMode()) {
self.buildMessage(); // creates initial self.message
}
callback(null);
},
function populateLocalUserInfo(callback) {
if(self.isLocalEmail()) {
msg.setLocalFromUserId(self.client.user.userId);
msg.setLocalToUserId(self.toUserId);
}
return self.message;
// :TODO: DO THAT!
callback(null);
}
],
function complete(err) {
cb(err, self.message);
}
);
};
this.redrawFooter = function(options, cb) {
@ -720,7 +736,6 @@ function FullScreenEditorModule(options) {
}
this.menuMethods = {
// :TODO: rename to editModeHeaderSubmit
headerSubmit : function(formData, extraArgs) {
self.switchToBody();
},
@ -735,7 +750,8 @@ function FullScreenEditorModule(options) {
switch(self.footerMode) {
case 'editor' :
if(!_.isUndefined(self.viewControllers.footerEditorMenu)) {
self.viewControllers.footerEditorMenu.setFocus(false);
//self.viewControllers.footerEditorMenu.setFocus(false);
self.viewControllers.footerEditorMenu.detachClientEvents();
}
self.viewControllers.body.switchFocus(1);
self.observeEditorEvents();
@ -782,14 +798,11 @@ function FullScreenEditorModule(options) {
var quoteMsgView = self.viewControllers.quoteBuilder.getView(1);
var msgView = self.viewControllers.body.getView(1);
//msgView.addText(_.trim(quoteMsgView.getData(), '\n'));
//msgView.addText(new Array(msgView.dimens.width - 1).join('-') + '\n');
msgView.addText(quoteMsgView.getData() + '\n');
quoteMsgView.setText('');
var footerName = self.getFooterName();
//self.redrawFooter( { clear : true, footerName : footerName }, function footerDisplayed(err) {
self.footerMode = 'editor';
self.switchFooter(function switched(err) {

View File

@ -10,10 +10,13 @@ var binary = require('binary');
var fs = require('fs');
var util = require('util');
// :TODO: Remove "Ftn" from most of these -- it's implied in the module
exports.stringFromFTN = stringFromFTN;
exports.getFormattedFTNAddress = getFormattedFTNAddress;
exports.getDateFromFtnDateTime = getDateFromFtnDateTime;
exports.getQuotePrefix = getQuotePrefix;
// See list here: https://github.com/Mithgol/node-fidonet-jam
// :TODO: proably move this elsewhere as a general method
@ -81,6 +84,12 @@ function getFTNMessageID(messageId, areaId) {
return messageId + '.' + areaId + '@' + getFTNAddress() + ' ' + getFTNMessageSerialNumber(messageId)
}
// Get a FSC-0032 style quote prefixes
function getQuotePrefix(name) {
// :TODO: Add support for real names (e.g. with spaces) -> initials
return ' ' + name[0].toUpperCase() + name[1].toLowerCase() + '> ';
}
//
// Specs:

View File

@ -3,6 +3,7 @@
var msgDb = require('./database.js').dbs.message;
var wordWrapText = require('./word_wrap.js').wordWrapText;
var ftnUtil = require('./ftn_util.js');
var uuid = require('node-uuid');
var async = require('async');
@ -244,19 +245,10 @@ Message.prototype.persist = function(cb) {
);
};
// :TODO: Update this to use a FTN module, e.g. ftn.getQuotePrefix(name)
Message.prototype.getFTNQuotePrefix = function(source) {
source = source || 'fromUserName';
switch(source) {
case 'fromUserName' :
return this.fromUserName[0].toUpperCase() + this.fromUserName[1].toLowerCase();
case 'toUserName' :
return this.toUserName[0].toUpperCase() + this.toUserName[1].toLowerCase();
// :TODO: real names
}
return ftnUtil.getQuotePrefix(this[source]);
};
Message.prototype.getQuoteLines = function(width, options) {
@ -282,7 +274,7 @@ Message.prototype.getQuoteLines = function(width, options) {
var quotePrefix = ''; // we need this init even if blank
if(options.includePrefix) {
quotePrefix = ' ' + this.getFTNQuotePrefix(options.prefixSource || 'fromUserName') + '> ';
quotePrefix = this.getFTNQuotePrefix(options.prefixSource || 'fromUserName');
}
var wrapOpts = {

View File

@ -149,53 +149,11 @@ VerticalMenuView.prototype.setFocus = function(focused) {
VerticalMenuView.prototype.onKeyPress = function(ch, key) {
if(key) {
var prevFocusedItemIndex = this.focusedItemIndex;
if(this.isKeyMapped('up', key.name)) {
this.focusPrevious();
/*
if(0 === this.focusedItemIndex) {
this.focusedItemIndex = this.items.length - 1;
this.viewWindow = {
//top : this.items.length - this.maxVisibleItems,
top : Math.max(this.items.length - this.maxVisibleItems, 0),
bottom : this.items.length - 1
};
} else {
this.focusedItemIndex--;
if(this.focusedItemIndex < this.viewWindow.top) {
this.viewWindow.top--;
this.viewWindow.bottom--;
}
}
*/
} else if(this.isKeyMapped('down', key.name)) {
/*if(this.items.length - 1 === this.focusedItemIndex) {
this.focusedItemIndex = 0;
this.viewWindow = {
top : 0,
bottom : Math.min(this.focusedItemIndex + this.maxVisibleItems, this.items.length) - 1
};
} else {
this.focusedItemIndex++;
if(this.focusedItemIndex > this.viewWindow.bottom) {
this.viewWindow.top++;
this.viewWindow.bottom++;
}
}
*/
this.focusNext();
}
if(prevFocusedItemIndex !== this.focusedItemIndex) {
// :TODO: Optimize this for cases where no scrolling occured & only two items need updated
// this.redraw();
}
}
VerticalMenuView.super_.prototype.onKeyPress.call(this, ch, key);
@ -211,6 +169,7 @@ VerticalMenuView.prototype.setItems = function(items) {
this.positionCacheExpired = true;
};
// :TODO: Apply draw optimizaitons when only two items need drawn vs entire view!
VerticalMenuView.prototype.focusNext = function() {
VerticalMenuView.super_.prototype.focusNext.call(this);

View File

@ -247,6 +247,9 @@ View.prototype.setFocus = function(focused) {
};
View.prototype.onKeyPress = function(ch, key) {
if(false === this.hasFocus) {
console.log('doh!');
}
assert(this.hasFocus, 'View does not have focus');
assert(this.acceptsInput, 'View does not accept input');

View File

@ -57,11 +57,11 @@ function ViewController(options) {
{ ch : ch, key : key }, // formData
actionForKey); // action block
}
} else {
if(self.focusedView && self.focusedView.acceptsInput) {
self.focusedView.onKeyPress(ch, key);
}
}
if(self.focusedView && self.focusedView.acceptsInput) {
self.focusedView.onKeyPress(ch, key);
}
};
this.viewActionListener = function(action, key) {
@ -373,12 +373,12 @@ ViewController.prototype.setFocus = function(focused) {
this.detachClientEvents();
}
// :TODO: without this, setFocus(false) is broken (doens't call focus events); with it, FSE menus break!!
// this.setViewFocusWithEvents(this.focusedView, focused);
this.setViewFocusWithEvents(this.focusedView, focused);
};
ViewController.prototype.switchFocus = function(id) {
this.setFocus(true); // ensure events are attached
//this.setFocus(true); // ensure events are attached
this.attachClientEvents();
// remove from old
this.setViewFocusWithEvents(this.focusedView, false);

View File

@ -774,6 +774,7 @@
width: 27
argName: to
focus: true
text: All
}
"ET3" : {
"width" : 27,
@ -855,10 +856,14 @@
}
]
},
"actionKeys" : [ // :TODO: Need better name
actionKeys: [ // :TODO: Need better name
{
"keys" : [ "escape" ],
"action" : "@method:editModeEscPressed"
keys: [ "escape" ]
action: @method:editModeEscPressed
}
{
keys: [ "?" ]
action: @method:editModeMenuHelp
}
]
// :TODO: something like the following for overriding keymap

View File

@ -25,17 +25,15 @@ function AreaPostFSEModule(options) {
this.editorMode = 'edit';
this.menuMethods.editModeMenuSave = function(formData, extraArgs) {
var msg = self.getMessage();
var msg;
async.series(
[
function prepareMessage(callback) {
if(self.isLocalEmail()) {
msg.setLocalFromUserId(self.client.user.userId);
msg.setLocalToUserId(self.toUserId);
}
callback(null);
function getMessageObject(callback) {
self.getMessage(function gotMsg(err, msgObj) {
msg = msgObj;
callback(err);
});
},
function saveMessage(callback) {
msg.persist(function persisted(err) {