Bug 392820 (Bookmarks 'star' panel should capture keyboard shortcuts) - * block accel+w/accel+shift+w within the panel. * close the panel on enter/esc. * focus the name-field/picker and select its contents when opening the panel. * focus the content-area when the panel is closed. r=dietrich.

This commit is contained in:
mozilla.mano@sent.com 2007-08-29 15:49:37 -07:00
parent 41d03dfc0f
commit d5ca3761ca

View File

@ -53,12 +53,48 @@ var PlacesCommandHook = {
return document.getElementById("editBookmarkPanel");
},
// list of command elements (by id) to disable when the panel is opened
_blockedCommands: ["cmd_close", "cmd_closeWindow"],
_blockCommands: function PCH__blockCommands() {
for each(var key in this._blockedCommands) {
var elt = document.getElementById(key);
if (elt.getAttribute("disabled") == "true")
elt.setAttribute("wasDisabled", "true");
else {
elt.setAttribute("wasDisabled", "false");
elt.setAttribute("disabled", "true");
}
}
},
_restoreCommandsState: function PCH__restoreCommandsState() {
for each(var key in this._blockedCommands) {
var elt = document.getElementById(key);
if (elt.getAttribute("wasDisabled") != "true")
elt.removeAttribute("disabled");
elt.removeAttribute("wasDisabled");
}
},
// nsIDOMEventListener
handleEvent: function PCH_handleEvent(aEvent) {
if (aEvent.originalTarget != this.panel)
return;
gEditItemOverlay.uninitPanel(true);
switch (aEvent.type) {
case "popuphiding":
if (aEvent.originalTarget == this.panel) {
gEditItemOverlay.uninitPanel(true);
this._restoreCommandsState();
}
break;
case "keypress":
if (aEvent.keyCode == KeyEvent.DOM_VK_ESCAPE ||
aEvent.keyCode == KeyEvent.DOM_VK_RETURN) {
// focus the content area and hide the panel
window.content.focus();
this.panel.hidePopup();
}
break;
}
},
_overlayLoaded: false,
@ -98,10 +134,17 @@ var PlacesCommandHook = {
_doShowEditBookmarkPanel:
function PCH__doShowEditBookmarkPanel(aItemId, aAnchorElement, aPosition) {
this.panel.addEventListener("keypress", this, true);
this._blockCommands(); // un-done in the popuphiding handler
this.panel.openPopup(aAnchorElement, aPosition, -1, -1);
gEditItemOverlay.initPanel(aItemId,
{ hiddenRows: ["description", "location"] });
setTimeout(function() {
var namePicker = document.getElementById("editBMPanel_namePicker");
namePicker.focus();
namePicker.editor.selectAll();
}, 0);
},
/**