Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Bug 720641 (toolbar): Be more helpful about when to show the panels.
Browse files Browse the repository at this point in the history
  • Loading branch information
joewalker committed Mar 1, 2012
1 parent 73e556f commit 861ddaa
Showing 1 changed file with 67 additions and 12 deletions.
79 changes: 67 additions & 12 deletions lib/gcli/ui/focus.js
Expand Up @@ -10,6 +10,7 @@ define(function(require, exports, module) {
var util = require('gcli/util');
var settings = require('gcli/settings');
var l10n = require('gcli/l10n');
var canon = require('gcli/canon');

/**
* Record how much help the user wants from the tooltip
Expand Down Expand Up @@ -56,10 +57,10 @@ exports.shutdown = function() {
* It does this simply by postponing the hide events by 250ms to see if
* something else takes focus.
* @param options Object containing user customization properties, including:
* - blurDelay
* - slowTypingDelay
* - debug
* - initialFocus
* - blurDelay (default=150ms)
* - slowTypingDelay (default=3000ms)
* - debug (default=false)
* - commandOutputManager (default=canon.commandOutputManager)
* @param components Object that links to other UI components. GCLI provided:
* - document
*/
Expand All @@ -71,12 +72,17 @@ function FocusManager(options, components) {
this._blurDelay = options.blurDelay || 150;
this._window = this._document.defaultView;

this._commandOutputManager = options.commandOutputManager ||
canon.commandOutputManager;
this._commandOutputManager.onOutput.add(this._outputted, this);

this._blurDelayTimeout = null; // Result of setTimeout in delaying a blur
this._monitoredElements = []; // See addMonitoredElement()

this._isError = false;
this._hasFocus = false;
this._helpRequested = false;
this._recentOutput = false;

// Be more helpful if the user pauses
// this._slowTyping = false;
Expand All @@ -91,7 +97,8 @@ function FocusManager(options, components) {

eagerHelper.onChange.add(this._eagerHelperChanged, this);

this._isShowing = undefined;
this._isTooltipVisible = undefined;
this._isOutputVisible = undefined;
this._checkShow();
}

Expand All @@ -108,6 +115,9 @@ FocusManager.prototype.destroy = function() {

// delete this._onSlowTyping;

this._commandOutputManager.onOutput.remove(this._outputted, this);
delete this._commandOutputManager;

for (var i = 0; i < this._monitoredElements.length; i++) {
var monitor = this._monitoredElements[i];
console.error('Hanging monitored element: ', monitor.element);
Expand Down Expand Up @@ -173,6 +183,13 @@ FocusManager.prototype.removeMonitoredElement = function(element) {
element.removeEventListener('blur', monitor.onBlur, true);
};

/**
* Monitor for new command executions
*/
FocusManager.prototype._outputted = function(ev) {
this._recentOutput = true;
};

/**
* We take a focus event anywhere to be an indication that we might be about
* to lose focus
Expand Down Expand Up @@ -282,17 +299,23 @@ FocusManager.prototype._eagerHelperChanged = function() {
FocusManager.prototype.onKeyUp = function(ev) {
// this._resetSlowTypingAlarm();
// this._slowTyping = false;
// this._checkShow();
this._recentOutput = false;
this._checkShow();
};

/**
* Generally called for something like a F1 key press, when the user explicitly
* wants help
*/
FocusManager.prototype.helpRequest = function() {
if (this._debug) {
console.log('FocusManager.helpRequest');
}

// this._cancelSlowTypingAlarm();
// this._slowTyping = true;
this._helpRequested = true;
this._recentOutput = false;
this._checkShow();
};

Expand All @@ -301,11 +324,16 @@ FocusManager.prototype.helpRequest = function() {
* wants to get rid of the help
*/
FocusManager.prototype.removeHelp = function() {
if (this._debug) {
console.log('FocusManager.removeHelp');
}

// this._cancelSlowTypingAlarm();
// this._slowTyping = false;
this._importantFieldFlag = false;
this._isError = false;
this._helpRequested = false;
this._recentOutput = false;
this._checkShow();
};

Expand Down Expand Up @@ -336,22 +364,37 @@ FocusManager.prototype.setError = function(isError) {
* _shouldShow() and take appropriate action
*/
FocusManager.prototype._checkShow = function() {
var shouldShow = this._shouldShow();
var fire = false;
var ev = {
tooltipVisible: this._isTooltipVisible,
outputVisible: this._isOutputVisible
};

var showTooltip = this._shouldShowTooltip();
if (this._isTooltipVisible !== showTooltip.visible) {
ev.tooltipVisible = this._isTooltipVisible = showTooltip.visible;
fire = true;
}

if (this._isShowing !== shouldShow.visible) {
var showOutput = this._shouldShowOutput();
if (this._isOutputVisible !== showOutput.visible) {
ev.outputVisible = this._isOutputVisible = showOutput.visible;
fire = true;
}

if (fire) {
if (this._debug) {
console.log('FocusManager._checkShow visible=', shouldShow.visible, shouldShow.reason);
console.debug('FocusManager.onVisibilityChange', ev);
}
this.onVisibilityChange({ visible: shouldShow.visible });
this._isShowing = shouldShow.visible;
this.onVisibilityChange(ev);
}
};

/**
* Calculate if we should be showing or hidden taking into account all the
* available inputs
*/
FocusManager.prototype._shouldShow = function() {
FocusManager.prototype._shouldShowTooltip = function() {
if (eagerHelper.value === Eagerness.NEVER) {
return { visible: false, reason: 'eagerHelper !== NEVER' };
}
Expand Down Expand Up @@ -379,6 +422,18 @@ FocusManager.prototype._shouldShow = function() {
return { visible: false, reason: 'default' };
};

/**
* Calculate if we should be showing or hidden taking into account all the
* available inputs
*/
FocusManager.prototype._shouldShowOutput = function() {
if (this._recentOutput) {
return { visible: true, reason: 'recentOutput' };
}

return { visible: false, reason: 'default' };
};

exports.FocusManager = FocusManager;


Expand Down

0 comments on commit 861ddaa

Please sign in to comment.