* VC.setFocus(): Attaches/detaches events/etc.

This commit is contained in:
Bryan Ashby 2015-07-08 22:34:40 -06:00
parent f348e06d86
commit 65ad2ffdd1
3 changed files with 13 additions and 15 deletions

View file

@ -426,7 +426,6 @@ function display(options, cb) {
var generatedId = 100; var generatedId = 100;
var cprListener = function(pos) { var cprListener = function(pos) {
console.log(pos)
if(mciPosQueue.length > 0) { if(mciPosQueue.length > 0) {
var forMapItem = mciPosQueue.shift(); var forMapItem = mciPosQueue.shift();
mciMap[forMapItem].position = pos; mciMap[forMapItem].position = pos;
@ -438,7 +437,6 @@ function display(options, cb) {
}; };
function completed() { function completed() {
console.log('completed')
options.client.removeListener('cursor position report', cprListener); options.client.removeListener('cursor position report', cprListener);
parser.removeAllListeners(); // :TODO: Necessary??? parser.removeAllListeners(); // :TODO: Necessary???
@ -509,7 +507,6 @@ function display(options, cb) {
mciPosQueue.push(mapKey); mciPosQueue.push(mapKey);
console.log('querying pos...')
options.client.term.rawWrite(ansi.queryPos()); options.client.term.rawWrite(ansi.queryPos());
} }
}); });

View file

@ -37,9 +37,8 @@ function ViewController(options) {
this.clientKeyPressHandler = function(ch, key) { this.clientKeyPressHandler = function(ch, key) {
// //
// Process key presses treating form submit mapped // Process key presses treating form submit mapped keys special.
// keys special. Everything else is forwarded on to // Everything else is forwarded on to the focused View, if any.
// the focused View, if any.
// //
if(key) { if(key) {
var submitViewId = self.submitKeyMap[key.name]; var submitViewId = self.submitKeyMap[key.name];
@ -244,15 +243,17 @@ ViewController.prototype.getFocusedView = function() {
return this.focusedView; return this.focusedView;
}; };
ViewController.prototype.removeFocus = function() { ViewController.prototype.setFocus = function(focused) {
var v = this.getFocusedView(); if(focused) {
if(v) { this.attachClientEvents();
v.setFocus(false); } else {
this.focusedView = null; this.detachClientEvents();
} }
}; };
ViewController.prototype.switchFocus = function(id) { ViewController.prototype.switchFocus = function(id) {
this.setFocus(true); // ensure events are attached
if(this.focusedView && this.focusedView.acceptsFocus) { if(this.focusedView && this.focusedView.acceptsFocus) {
this.switchFocusEvent('leave', this.focusedView); this.switchFocusEvent('leave', this.focusedView);
this.focusedView.setFocus(false); this.focusedView.setFocus(false);
@ -488,7 +489,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
confForFormId = formConfig.submit['*']; confForFormId = formConfig.submit['*'];
} else { } else {
// no configuration for this submitId // no configuration for this submitId
delf.client.log.debug( { formId : formData.submitId }, 'No configuration for form ID'); self.client.log.debug( { formId : formData.submitId }, 'No configuration for form ID');
return; return;
} }

View file

@ -199,7 +199,7 @@ function FullScreenEditorModule(options) {
self.updateTextEditMode(bodyView.getTextEditMode()); self.updateTextEditMode(bodyView.getTextEditMode());
self.updateEditModePosition(bodyView.getEditPosition()); self.updateEditModePosition(bodyView.getEditPosition());
self.viewControllers.body.removeFocus(); // :TODO: Change vc to allow *not* setting focus @ create self.viewControllers.body.setFocus(false);
self.viewControllers.header.switchFocus(1); self.viewControllers.header.switchFocus(1);
} }
); );
@ -234,7 +234,7 @@ function FullScreenEditorModule(options) {
this.menuMethods = { this.menuMethods = {
headerSubmit : function(formData, extraArgs) { headerSubmit : function(formData, extraArgs) {
self.viewControllers.header.removeFocus(); self.viewControllers.header.setFocus(false);
self.viewControllers.body.switchFocus(1); self.viewControllers.body.switchFocus(1);
self.getBodyView().on('edit position', function cursorPosUpdate(pos) { self.getBodyView().on('edit position', function cursorPosUpdate(pos) {
@ -253,7 +253,7 @@ function FullScreenEditorModule(options) {
// :TODO:... what now? // :TODO:... what now?
console.log(err) console.log(err)
} else { } else {
self.viewControllers.body.removeFocus(); self.viewControllers.body.setFocus(false);
self.viewControllers.footerEditMenu.switchFocus(1); self.viewControllers.footerEditMenu.switchFocus(1);
} }
}); });