Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #479 from adobe/jason-sanjose/issue427
Browse files Browse the repository at this point in the history
Temporary fix for global key bindings and dialogs
  • Loading branch information
tvoliter committed Mar 22, 2012
2 parents e33361b + 94612ab commit bdbbf48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Dialogs.js
Expand Up @@ -10,6 +10,8 @@
*/
define(function (require, exports, module) {
'use strict';

var KeyBindingManager = require("KeyBindingManager");

var DIALOG_BTN_CANCEL = "cancel",
DIALOG_BTN_OK = "ok",
Expand Down Expand Up @@ -128,6 +130,7 @@ define(function (require, exports, module) {

// Remove keydown event handler
document.body.removeEventListener("keydown", handleKeyDown, true);
KeyBindingManager.setEnabled(true);
}).one("shown", function () {
// Set focus to the default button
var primaryBtn = dlg.find(".primary");
Expand All @@ -138,6 +141,7 @@ define(function (require, exports, module) {

// Listen for dialog keyboard shortcuts
document.body.addEventListener("keydown", handleKeyDown, true);
KeyBindingManager.setEnabled(false);
});

// Click handler for buttons
Expand Down
21 changes: 20 additions & 1 deletion src/KeyBindingManager.js
Expand Up @@ -17,6 +17,11 @@ define(function (require, exports, module) {
* The currently installed keymap.
*/
var _keymap = null;

/**
* Allow clients to toggle key binding
*/
var _enabled = true;

/**
* Install the specified keymap as the current keymap, overwriting the existing keymap.
Expand All @@ -34,15 +39,29 @@ define(function (require, exports, module) {
* @return {boolean} true if the key was processed, false otherwise
*/
function handleKey(key) {
if (_keymap && _keymap.map[key]) {
if (_enabled && _keymap && _keymap.map[key]) {
CommandManager.execute(_keymap.map[key]);
return true;
}
return false;
}


// TODO (issue #414): Replace this temporary fix with a more robust solution to handle focus and modality
/**
* Enable or disable key bindings. Clients such as dialogs may wish to disable
* global key bindings temporarily.
*
* @param {string} A key-description string.
* @return {boolean} true if the key was processed, false otherwise
*/
function setEnabled(value) {
_enabled = value;
}


// Define public API
exports.installKeymap = installKeymap;
exports.handleKey = handleKey;
exports.setEnabled = setEnabled;
});

0 comments on commit bdbbf48

Please sign in to comment.