mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 488846, use a custom controller finding method which checks for open context menus for places, r=mak (CLOSED TREE)
This commit is contained in:
parent
abc7a6bc3e
commit
6bae8f2ecb
@ -127,6 +127,7 @@ PlacesController.prototype = {
|
||||
case "cmd_redo":
|
||||
return PlacesUIUtils.ptm.numberOfRedoItems > 0;
|
||||
case "cmd_cut":
|
||||
case "placesCmd_cut":
|
||||
var nodes = this._view.getSelectionNodes();
|
||||
// If selection includes history nodes there's no reason to allow cut.
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
@ -135,6 +136,7 @@ PlacesController.prototype = {
|
||||
}
|
||||
// Otherwise fallback to cmd_delete check.
|
||||
case "cmd_delete":
|
||||
case "placesCmd_delete":
|
||||
return this._hasRemovableSelection(false);
|
||||
case "placesCmd_deleteDataHost":
|
||||
return this._hasRemovableSelection(false) &&
|
||||
@ -142,8 +144,10 @@ PlacesController.prototype = {
|
||||
case "placesCmd_moveBookmarks":
|
||||
return this._hasRemovableSelection(true);
|
||||
case "cmd_copy":
|
||||
case "placesCmd_copy":
|
||||
return this._view.hasSelection;
|
||||
case "cmd_paste":
|
||||
case "placesCmd_paste":
|
||||
return this._canInsert(true) && this._isClipboardDataPasteable();
|
||||
case "cmd_selectAll":
|
||||
if (this._view.selType != "single") {
|
||||
@ -229,15 +233,19 @@ PlacesController.prototype = {
|
||||
PlacesUIUtils.ptm.redoTransaction();
|
||||
break;
|
||||
case "cmd_cut":
|
||||
case "placesCmd_cut":
|
||||
this.cut();
|
||||
break;
|
||||
case "cmd_copy":
|
||||
case "placesCmd_copy":
|
||||
this.copy();
|
||||
break;
|
||||
case "cmd_paste":
|
||||
case "placesCmd_paste":
|
||||
this.paste();
|
||||
break;
|
||||
case "cmd_delete":
|
||||
case "placesCmd_delete":
|
||||
this.remove("Remove Selection");
|
||||
break;
|
||||
case "placesCmd_deleteDataHost":
|
||||
@ -1604,19 +1612,13 @@ var PlacesControllerDragHelper = {
|
||||
};
|
||||
|
||||
function goUpdatePlacesCommands() {
|
||||
var placesController;
|
||||
try {
|
||||
// Or any other command...
|
||||
placesController = top.document.commandDispatcher
|
||||
.getControllerForCommand("placesCmd_open");
|
||||
}
|
||||
catch(ex) { return; }
|
||||
// Get the controller for one of the places commands.
|
||||
var placesController = doGetPlacesControllerForCommand("placesCmd_open");
|
||||
if (!placesController)
|
||||
return;
|
||||
|
||||
function updatePlacesCommand(aCommand) {
|
||||
var enabled = false;
|
||||
if (placesController)
|
||||
enabled = placesController.isCommandEnabled(aCommand);
|
||||
goSetCommandEnabled(aCommand, enabled);
|
||||
goSetCommandEnabled(aCommand, placesController.isCommandEnabled(aCommand));
|
||||
}
|
||||
|
||||
updatePlacesCommand("placesCmd_open");
|
||||
@ -1631,4 +1633,39 @@ function goUpdatePlacesCommands() {
|
||||
updatePlacesCommand("placesCmd_reload");
|
||||
updatePlacesCommand("placesCmd_reloadMicrosummary");
|
||||
updatePlacesCommand("placesCmd_sortBy:name");
|
||||
updatePlacesCommand("placesCmd_cut");
|
||||
updatePlacesCommand("placesCmd_copy");
|
||||
updatePlacesCommand("placesCmd_paste");
|
||||
updatePlacesCommand("placesCmd_delete");
|
||||
}
|
||||
|
||||
function doGetPlacesControllerForCommand(aCommand)
|
||||
{
|
||||
var placesController = top.document.commandDispatcher
|
||||
.getControllerForCommand(aCommand);
|
||||
if (!placesController) {
|
||||
// If building commands for a context menu, look for an element in the
|
||||
// current popup.
|
||||
var element = document.popupNode;
|
||||
while (element) {
|
||||
var isContextMenuShown = ("_contextMenuShown" in element) && element._contextMenuShown;
|
||||
// Check for the parent menupopup or the hbox used for toolbars
|
||||
if ((element.localName == "menupopup" || element.localName == "hbox") &&
|
||||
isContextMenuShown) {
|
||||
placesController = element.controllers.getControllerForCommand(aCommand);
|
||||
break;
|
||||
}
|
||||
element = element.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
return placesController;
|
||||
}
|
||||
|
||||
function goDoPlacesCommand(aCommand)
|
||||
{
|
||||
var controller = doGetPlacesControllerForCommand(aCommand);
|
||||
if (controller && controller.isCommandEnabled(aCommand))
|
||||
controller.doCommand(aCommand);
|
||||
}
|
||||
|
||||
|
@ -1024,11 +1024,7 @@
|
||||
<body><![CDATA[
|
||||
this._ensureInitialized();
|
||||
this._contextMenuShown = true;
|
||||
// Activate the controller
|
||||
this.focus();
|
||||
// The above call may not always fire a consumable event for
|
||||
// commandUpdater, so we force a command update.
|
||||
window.updateCommands("focus");
|
||||
window.updateCommands("places");
|
||||
return this.controller.buildContextMenu(aPopup);
|
||||
]]></body>
|
||||
</method>
|
||||
|
@ -62,40 +62,50 @@
|
||||
|
||||
<commandset id="placesCommands"
|
||||
commandupdater="true"
|
||||
events="focus,sort"
|
||||
events="focus,sort,places"
|
||||
oncommandupdate="goUpdatePlacesCommands();">
|
||||
<command id="placesCmd_open"
|
||||
oncommand="goDoCommand('placesCmd_open');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_open');"/>
|
||||
<command id="placesCmd_open:window"
|
||||
oncommand="goDoCommand('placesCmd_open:window');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_open:window');"/>
|
||||
<command id="placesCmd_open:tab"
|
||||
oncommand="goDoCommand('placesCmd_open:tab');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_open:tab');"/>
|
||||
|
||||
<command id="placesCmd_new:bookmark"
|
||||
oncommand="goDoCommand('placesCmd_new:bookmark');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_new:bookmark');"/>
|
||||
<command id="placesCmd_new:livemark"
|
||||
oncommand="goDoCommand('placesCmd_new:livemark');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_new:livemark');"/>
|
||||
<command id="placesCmd_new:folder"
|
||||
oncommand="goDoCommand('placesCmd_new:folder');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_new:folder');"/>
|
||||
<command id="placesCmd_new:separator"
|
||||
oncommand="goDoCommand('placesCmd_new:separator');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_new:separator');"/>
|
||||
<command id="placesCmd_show:info"
|
||||
oncommand="goDoCommand('placesCmd_show:info');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_show:info');"/>
|
||||
<command id="placesCmd_rename"
|
||||
oncommand="goDoCommand('placesCmd_show:info');"
|
||||
oncommand="goDoPlacesCommand('placesCmd_show:info');"
|
||||
observes="placesCmd_show:info"/>
|
||||
<command id="placesCmd_reload"
|
||||
oncommand="goDoCommand('placesCmd_reload');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_reload');"/>
|
||||
<command id="placesCmd_reloadMicrosummary"
|
||||
oncommand="goDoCommand('placesCmd_reloadMicrosummary');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_reloadMicrosummary');"/>
|
||||
<command id="placesCmd_sortBy:name"
|
||||
oncommand="goDoCommand('placesCmd_sortBy:name');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_sortBy:name');"/>
|
||||
<command id="placesCmd_moveBookmarks"
|
||||
oncommand="goDoCommand('placesCmd_moveBookmarks');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_moveBookmarks');"/>
|
||||
<command id="placesCmd_deleteDataHost"
|
||||
oncommand="goDoCommand('placesCmd_deleteDataHost');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_deleteDataHost');"/>
|
||||
<command id="placesCmd_createBookmark"
|
||||
oncommand="goDoCommand('placesCmd_createBookmark');"/>
|
||||
oncommand="goDoPlacesCommand('placesCmd_createBookmark');"/>
|
||||
|
||||
<!-- Special versions of cut/copy/paste/delete which check for an open context menu. -->
|
||||
<command id="placesCmd_cut"
|
||||
oncommand="goDoPlacesCommand('placesCmd_cut');"/>
|
||||
<command id="placesCmd_copy"
|
||||
oncommand="goDoPlacesCommand('placesCmd_copy');"/>
|
||||
<command id="placesCmd_paste"
|
||||
oncommand="goDoPlacesCommand('placesCmd_paste');"/>
|
||||
<command id="placesCmd_delete"
|
||||
oncommand="goDoPlacesCommand('placesCmd_delete');"/>
|
||||
</commandset>
|
||||
|
||||
<popup id="placesContext"
|
||||
@ -165,20 +175,20 @@
|
||||
selection="link"
|
||||
forcehideselection="bookmark|tagChild"/>
|
||||
<menuitem id="placesContext_cut"
|
||||
command="cmd_cut"
|
||||
command="placesCmd_cut"
|
||||
label="&cutCmd.label;"
|
||||
accesskey="&cutCmd.accesskey;"
|
||||
closemenu="single"
|
||||
selection="bookmark|folder|separator|query"
|
||||
forcehideselection="tagChild|livemarkChild"/>
|
||||
<menuitem id="placesContext_copy"
|
||||
command="cmd_copy"
|
||||
command="placesCmd_copy"
|
||||
label="©Cmd.label;"
|
||||
closemenu="single"
|
||||
accesskey="©Cmd.accesskey;"
|
||||
selection="any"/>
|
||||
<menuitem id="placesContext_paste"
|
||||
command="cmd_paste"
|
||||
command="placesCmd_paste"
|
||||
label="&pasteCmd.label;"
|
||||
closemenu="single"
|
||||
accesskey="&pasteCmd.accesskey;"
|
||||
@ -186,13 +196,13 @@
|
||||
hideifnoinsertionpoint="true"/>
|
||||
<menuseparator id="placesContext_editSeparator"/>
|
||||
<menuitem id="placesContext_delete"
|
||||
command="cmd_delete"
|
||||
command="placesCmd_delete"
|
||||
label="&deleteCmd.label;"
|
||||
accesskey="&deleteCmd.accesskey;"
|
||||
closemenu="single"
|
||||
selection="bookmark|tagChild|folder|query|dynamiccontainer|separator|host"/>
|
||||
<menuitem id="placesContext_delete_history"
|
||||
command="cmd_delete"
|
||||
command="placesCmd_delete"
|
||||
label="&cmd.delete.label;"
|
||||
accesskey="&cmd.delete.accesskey;"
|
||||
closemenu="single"
|
||||
|
@ -725,11 +725,7 @@
|
||||
<parameter name="aPopup"/>
|
||||
<body><![CDATA[
|
||||
this._contextMenuShown = true;
|
||||
// Activate the controller
|
||||
this.focus();
|
||||
// The above call may not always fire a consumable event for
|
||||
// commandUpdater, so we force a command update.
|
||||
window.updateCommands("focus");
|
||||
window.updateCommands("places");
|
||||
return this.controller.buildContextMenu(aPopup);
|
||||
]]></body>
|
||||
</method>
|
||||
|
Loading…
Reference in New Issue
Block a user