From 9865da34cc7fde4d73cad0ec2fd9a6e10c23f4b9 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 17 Sep 2015 22:53:19 -0600 Subject: [PATCH] * Quote builder very functional, some bugs * Work on fallback system (implicit); Added some notes... need saveState/restoreState type functionality as extraArgs may not be final args! --- core/client.js | 23 ++++++++------- core/fse.js | 30 +++++++++++++++---- core/menu_util.js | 2 +- core/menu_view.js | 8 ++++++ core/vertical_menu_view.js | 59 ++++++++++++++++++++++++++++++++++++-- mods/menu.hjson | 13 +++++++-- 6 files changed, 112 insertions(+), 23 deletions(-) diff --git a/core/client.js b/core/client.js index 9ed32132..c02944ea 100644 --- a/core/client.js +++ b/core/client.js @@ -395,6 +395,9 @@ function Client(input, output) { self.detachCurrentMenuModule = function() { if(self.currentMenuModule) { self.currentMenuModule.leave(); + + self.lastMenuModuleInfo = self.currentMenuModuleInfo; + self.currentMenuModule = null; } }; @@ -446,24 +449,22 @@ Client.prototype.gotoMenuModule = function(options, cb) { extraArgs : options.extraArgs, }; - menuUtil.loadMenu(loadOptions, function onMenuModuleLoaded(err, modInst) { + menuUtil.loadMenu(loadOptions, function menuModuleLoaded(err, modInst) { if(err) { cb(err); } else { self.log.debug( { menuName : options.name }, 'Goto menu module'); - if(self.currentMenuModule) { - self.lastMenuModuleInfo = { - name : self.currentMenuModule.modInfo.name, - extraArgs : self.currentMenuModuleExtraArgs, - }; + self.currentMenuModule = modInst; // :TODO: should probably be before enter() above + + self.currentMenuModuleInfo = { + // :TODO: This is quite the hack... doesn't seem right... + menuName : self.currentMenuModule.menuName, + extraArgs : options.extraArgs, } modInst.enter(self); - self.currentMenuModule = modInst; // :TODO: should probably be before enter() above - self.currentMenuModuleExtraArgs = options.extraArgs; - if(!callbackOnErrorOnly) { cb(null); } @@ -476,11 +477,13 @@ Client.prototype.fallbackMenuModule = function(cb) { if(self.lastMenuModuleInfo) { var modOpts = { - name : self.lastMenuModuleInfo.name, + name : self.lastMenuModuleInfo.menuName, extraArgs : self.lastMenuModuleInfo.extraArgs, }; self.gotoMenuModule(modOpts, cb); + } else { + cb(new Error('Nothing to fallback to!')); } }; diff --git a/core/fse.js b/core/fse.js index 598a1cd8..50755aae 100644 --- a/core/fse.js +++ b/core/fse.js @@ -655,6 +655,19 @@ function FullScreenEditorModule(options) { self.viewControllers[self.getFooterName()].switchFocus(1); // HM1 }; + this.switchFromQuoteBuilderToBody = function() { + self.viewControllers.quoteBuilder.setFocus(false); + var body = self.viewControllers.body.getView(1); + body.redraw(); + self.viewControllers.body.switchFocus(1); + + // :TODO: create method (DRY) + + self.updateTextEditMode(body.getTextEditMode()); + self.updateEditModePosition(body.getEditPosition()); + + self.observeEditorEvents(); + } this.menuMethods = { // :TODO: rename to editModeHeaderSubmit @@ -700,6 +713,7 @@ function FullScreenEditorModule(options) { if(self.newQuoteBlock) { self.newQuoteBlock = false; + // :TODO: Make date/time format avail as FSE config var dtFormat = self.client.currentTheme.helpers.getDateTimeFormat(); quoteMsgView.addText( 'On {0} {1} said...'.format( @@ -711,7 +725,7 @@ function FullScreenEditorModule(options) { var quoteText = self.viewControllers.quoteBuilder.getView(3).getItem(formData.value.quote); quoteMsgView.addText(quoteText); - // :TODO: Menus need a setFocusIndex() call -- move down to next item here + self.viewControllers.quoteBuilder.getView(3).focusNext(); }, quoteBuilderEscPressed : function(formData, extraArgs) { // :TODO: fix magic #'s @@ -727,12 +741,16 @@ function FullScreenEditorModule(options) { //self.redrawFooter( { clear : true, footerName : footerName }, function footerDisplayed(err) { self.footerMode = 'editor'; - + self.switchFooter(function switched(err) { - self.viewControllers.quoteBuilder.setFocus(false); - self.viewControllers.body.redrawAll(); - self.viewControllers[footerName].redrawAll(); - self.viewControllers.body.switchFocus(1); + self.switchFromQuoteBuilderToBody(); + }); + }, + replyDiscard : function(formData, extraArgs) { + // :TODO: need to prompt yes/no + // :TODO: @method for fallback would be better + self.client.fallbackMenuModule(function fallback(err) { + console.log(err) }); }, editModeMenuHelp : function(formData, extraArgs) { diff --git a/core/menu_util.js b/core/menu_util.js index c52f45ee..087af3b3 100644 --- a/core/menu_util.js +++ b/core/menu_util.js @@ -110,7 +110,7 @@ function loadMenu(options, cb) { { menuName : options.name, menuConfig : modData.config, - extraArgs : options.extraArgs, + extraArgs : options.extraArgs }); callback(null, moduleInstance); } catch(e) { diff --git a/core/menu_view.js b/core/menu_view.js index af5879c5..8d4e8308 100644 --- a/core/menu_view.js +++ b/core/menu_view.js @@ -62,6 +62,14 @@ MenuView.prototype.getItem = function(index) { return this.items[index].text; }; +MenuView.prototype.focusNext = function() { + // nothing @ base currently +}; + +MenuView.prototype.focusPrevious = function() { + // nothign @ base currently +}; + MenuView.prototype.setFocusItems = function(items) { var self = this; diff --git a/core/vertical_menu_view.js b/core/vertical_menu_view.js index e3222693..cbcac6a4 100644 --- a/core/vertical_menu_view.js +++ b/core/vertical_menu_view.js @@ -151,7 +151,9 @@ VerticalMenuView.prototype.onKeyPress = function(ch, key) { if(key) { var prevFocusedItemIndex = this.focusedItemIndex; - if(this.isKeyMapped('up', key.name)) { + if(this.isKeyMapped('up', key.name)) { + this.focusPrevious(); + /* if(0 === this.focusedItemIndex) { this.focusedItemIndex = this.items.length - 1; @@ -169,8 +171,9 @@ VerticalMenuView.prototype.onKeyPress = function(ch, key) { this.viewWindow.bottom--; } } + */ } else if(this.isKeyMapped('down', key.name)) { - if(this.items.length - 1 === this.focusedItemIndex) { + /*if(this.items.length - 1 === this.focusedItemIndex) { this.focusedItemIndex = 0; this.viewWindow = { @@ -185,11 +188,13 @@ VerticalMenuView.prototype.onKeyPress = function(ch, key) { 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(); + // this.redraw(); } } @@ -206,6 +211,54 @@ VerticalMenuView.prototype.setItems = function(items) { this.positionCacheExpired = true; }; + +VerticalMenuView.prototype.focusNext = function() { + VerticalMenuView.super_.prototype.focusNext.call(this); + + 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.redraw(); +}; + +VerticalMenuView.prototype.focusPrevious = function() { + VerticalMenuView.super_.prototype.focusPrevious.call(this); + + 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--; + } + } + + this.redraw(); +}; + + VerticalMenuView.prototype.setFocusItems = function(items) { VerticalMenuView.super_.prototype.setFocusItems.call(this, items); diff --git a/mods/menu.hjson b/mods/menu.hjson index 0aa86824..28e0e38a 100644 --- a/mods/menu.hjson +++ b/mods/menu.hjson @@ -570,7 +570,6 @@ } }, messageAreaReplyPost: { - //module: msg_area_reply_fse module: msg_area_post_fse config: { art: { @@ -579,7 +578,8 @@ quote: MSGQUOT footerEditor: MSGEFTR footerEditorMenu: MSGEMFT - // :TODO: help + // :TODO: fix help + help: demo_fse_netmail_help.ans } editorMode: edit editorType: area @@ -647,10 +647,18 @@ submit: { *: [ + { + value: { 1: 1 } + action: @method:replyDiscard + } { value: { 1: 2 }, action: @method:editModeMenuQuote } + { + value: { 1: 3 } + action: @method:editModeMenuHelp + } ] } @@ -670,7 +678,6 @@ height: 7 } VM3: { - //items: [ "just", "testing", "some", "things" ] width: 79 height: 4 argName: quote