This repository has been archived by the owner on Nov 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1476097 - Use the Menu API's edit menu for all context menu textb…
…oxes within the toolbox; r=bgrins,flod Differential Revision: https://phabricator.services.mozilla.com/D6494
- Loading branch information
1 parent
2ac52f2
commit 44aa61a
Showing
15 changed files
with
301 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ | ||
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
"use strict"; | ||
|
||
const Menu = require("devtools/client/framework/menu"); | ||
const MenuItem = require("devtools/client/framework/menu-item"); | ||
|
||
var stringsLoaded = false; | ||
|
||
/** | ||
* Lazily load strings for the edit menu. | ||
*/ | ||
function loadEditMenuStrings(win) { | ||
if (stringsLoaded) { | ||
return; | ||
} | ||
|
||
if (win.MozXULElement) { | ||
stringsLoaded = true; | ||
win.MozXULElement.insertFTLIfNeeded("toolkit/main-window/editmenu.ftl"); | ||
} | ||
} | ||
|
||
/** | ||
* Return an 'edit' menu for a input field. This integrates directly | ||
* with docshell commands to provide the right enabled state and editor | ||
* functionality. | ||
* | ||
* You'll need to call menu.popup() yourself, this just returns the Menu instance. | ||
* | ||
* @param {Window} win parent window reference | ||
* @param {String} id menu ID | ||
* | ||
* @returns {Menu} | ||
*/ | ||
function createEditContextMenu(win, id) { | ||
// Localized strings for the menu are loaded lazily. | ||
loadEditMenuStrings(win); | ||
|
||
const docshell = win.docShell; | ||
const menu = new Menu({id}); | ||
menu.append(new MenuItem({ | ||
id: "editmenu-undo", | ||
l10nID: "editmenu-undo", | ||
disabled: !docshell.isCommandEnabled("cmd_undo"), | ||
click: () => { | ||
docshell.doCommand("cmd_undo"); | ||
}, | ||
})); | ||
menu.append(new MenuItem({ | ||
type: "separator", | ||
})); | ||
menu.append(new MenuItem({ | ||
id: "editmenu-cut", | ||
l10nID: "editmenu-cut", | ||
disabled: !docshell.isCommandEnabled("cmd_cut"), | ||
click: () => { | ||
docshell.doCommand("cmd_cut"); | ||
}, | ||
})); | ||
menu.append(new MenuItem({ | ||
id: "editmenu-copy", | ||
l10nID: "editmenu-copy", | ||
disabled: !docshell.isCommandEnabled("cmd_copy"), | ||
click: () => { | ||
docshell.doCommand("cmd_copy"); | ||
}, | ||
})); | ||
menu.append(new MenuItem({ | ||
id: "editmenu-paste", | ||
l10nID: "editmenu-paste", | ||
disabled: !docshell.isCommandEnabled("cmd_paste"), | ||
click: () => { | ||
docshell.doCommand("cmd_paste"); | ||
}, | ||
})); | ||
menu.append(new MenuItem({ | ||
id: "editmenu-delete", | ||
l10nID: "editmenu-delete", | ||
disabled: !docshell.isCommandEnabled("cmd_delete"), | ||
click: () => { | ||
docshell.doCommand("cmd_delete"); | ||
}, | ||
})); | ||
menu.append(new MenuItem({ | ||
type: "separator", | ||
})); | ||
menu.append(new MenuItem({ | ||
id: "editmenu-selectAll", | ||
l10nID: "editmenu-select-all", | ||
disabled: !docshell.isCommandEnabled("cmd_selectAll"), | ||
click: () => { | ||
docshell.doCommand("cmd_selectAll"); | ||
}, | ||
})); | ||
return menu; | ||
} | ||
|
||
module.exports.createEditContextMenu = createEditContextMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.