mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 827608 - Use html context menus for about:apps. r=mfinkle
This commit is contained in:
parent
ac6f7b2501
commit
82e3ed418c
@ -37,6 +37,45 @@ function openLink(aElement) {
|
||||
} catch (ex) {}
|
||||
}
|
||||
|
||||
var ContextMenus = {
|
||||
target: null,
|
||||
|
||||
init: function() {
|
||||
document.addEventListener("contextmenu", ContextMenus, false);
|
||||
},
|
||||
|
||||
handleEvent: function(event) {
|
||||
// store the target of context menu events so that we know which app to act on
|
||||
this.target = event.target;
|
||||
while (!this.target.hasAttribute("contextmenu")) {
|
||||
this.target = this.target.parentNode;
|
||||
}
|
||||
},
|
||||
|
||||
addToHomescreen: function() {
|
||||
let manifest = this.target.manifest;
|
||||
let origin = Services.io.newURI(this.target.app.origin, null, null);
|
||||
gChromeWin.WebappsUI.createShortcut(manifest.name, manifest.fullLaunchPath(), gChromeWin.WebappsUI.getBiggestIcon(manifest.icons, origin), "webapp");
|
||||
this.target = null;
|
||||
},
|
||||
|
||||
uninstall: function() {
|
||||
this.target.app.uninstall();
|
||||
|
||||
let manifest = this.target.manifest;
|
||||
gChromeWin.sendMessageToJava({
|
||||
gecko: {
|
||||
type: "Shortcut:Remove",
|
||||
title: manifest.name,
|
||||
url: manifest.fullLaunchPath(),
|
||||
origin: this.target.app.origin,
|
||||
shortcutType: "webapp"
|
||||
}
|
||||
});
|
||||
this.target = null;
|
||||
}
|
||||
}
|
||||
|
||||
function onLoad(aEvent) {
|
||||
try {
|
||||
let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
|
||||
@ -49,36 +88,7 @@ function onLoad(aEvent) {
|
||||
navigator.mozApps.mgmt.onuninstall = onUninstall;
|
||||
updateList();
|
||||
|
||||
let contextmenus = gChromeWin.NativeWindow.contextmenus;
|
||||
AppsUI.shortcut = contextmenus.add(gStrings.GetStringFromName("appsContext.shortcut"), contextmenus.SelectorContext("div[mozApp]"),
|
||||
function(aTarget) {
|
||||
let manifest = aTarget.manifest;
|
||||
let origin = Services.io.newURI(aTarget.app.origin, null, null);
|
||||
gChromeWin.WebappsUI.createShortcut(manifest.name, manifest.fullLaunchPath(), gChromeWin.WebappsUI.getBiggestIcon(manifest.icons, origin), "webapp");
|
||||
});
|
||||
AppsUI.uninstall = contextmenus.add(gStrings.GetStringFromName("appsContext.uninstall"), contextmenus.SelectorContext("div[mozApp]"),
|
||||
function(aTarget) {
|
||||
aTarget.app.uninstall();
|
||||
|
||||
let manifest = aTarget.manifest;
|
||||
gChromeWin.sendMessageToJava({
|
||||
gecko: {
|
||||
type: "Shortcut:Remove",
|
||||
title: manifest.name,
|
||||
url: manifest.fullLaunchPath(),
|
||||
origin: aTarget.app.origin,
|
||||
shortcutType: "webapp"
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onUnload(aEvent) {
|
||||
let contextmenus = gChromeWin.NativeWindow.contextmenus;
|
||||
if (AppsUI.shortcut)
|
||||
contextmenus.remove(AppsUI.shortcut);
|
||||
if (AppsUI.uninstall)
|
||||
contextmenus.remove(AppsUI.uninstall);
|
||||
ContextMenus.init();
|
||||
}
|
||||
|
||||
function updateList() {
|
||||
@ -102,6 +112,7 @@ function addApplication(aApp) {
|
||||
|
||||
let container = document.createElement("div");
|
||||
container.className = "app";
|
||||
container.setAttribute("contextmenu", "appmenu");
|
||||
container.setAttribute("id", "app-" + aApp.origin);
|
||||
container.setAttribute("mozApp", aApp.origin);
|
||||
container.setAttribute("title", manifest.name);
|
||||
|
@ -27,6 +27,12 @@
|
||||
</head>
|
||||
|
||||
<body dir="&locale.dir;" onload="onLoad(event)" onunload="onUnload(event)">
|
||||
|
||||
<menu type="context" id="appmenu">
|
||||
<menuitem label="&aboutApps.addToHomescreen;" onclick="ContextMenus.addToHomescreen();"></menuitem>
|
||||
<menuitem label="&aboutApps.uninstall;" onclick="ContextMenus.uninstall();"></menuitem>
|
||||
</menu>
|
||||
|
||||
<div class="header">
|
||||
<div>&aboutApps.header;</div>
|
||||
<img src="chrome://browser/skin/images/addons-amo-hdpi.png" class="icon" pref="app.marketplaceURL" onclick="openLink(this);"/>
|
||||
|
@ -11,3 +11,5 @@
|
||||
<!ENTITY aboutApps.noApps.pre "No web apps installed. Get some from the ">
|
||||
<!ENTITY aboutApps.noApps.middle3 "Firefox Marketplace">
|
||||
<!ENTITY aboutApps.noApps.post ".">
|
||||
<!ENTITY aboutApps.uninstall "Uninstall">
|
||||
<!ENTITY aboutApps.addToHomescreen "Add to Home Screen">
|
||||
|
@ -1,6 +0,0 @@
|
||||
# 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/.
|
||||
|
||||
appsContext.uninstall=Uninstall
|
||||
appsContext.shortcut=Add to Home Screen
|
@ -10,7 +10,6 @@
|
||||
locale/@AB_CD@/browser/aboutAddons.dtd (%chrome/aboutAddons.dtd)
|
||||
locale/@AB_CD@/browser/aboutAddons.properties (%chrome/aboutAddons.properties)
|
||||
locale/@AB_CD@/browser/aboutApps.dtd (%chrome/aboutApps.dtd)
|
||||
locale/@AB_CD@/browser/aboutApps.properties (%chrome/aboutApps.properties)
|
||||
locale/@AB_CD@/browser/aboutCertError.dtd (%chrome/aboutCertError.dtd)
|
||||
locale/@AB_CD@/browser/aboutDownloads.dtd (%chrome/aboutDownloads.dtd)
|
||||
locale/@AB_CD@/browser/aboutDownloads.properties (%chrome/aboutDownloads.properties)
|
||||
|
Loading…
Reference in New Issue
Block a user