Permalink
Browse files

Replace toaster style with PopupNotifications.

Fixes #1563
  • Loading branch information...
1 parent 488ada4 commit d95713077e552bb8cefd56b3681d6b46ebbf4f29 @arantius arantius committed Sep 27, 2012
View
@@ -12,7 +12,6 @@ content greasemonkey content/
skin greasemonkey classic/1.0 skin/
overlay chrome://browser/content/browser.xul chrome://greasemonkey/content/browser.xul
-style chrome://global/content/alerts/alert.xul chrome://greasemonkey/skin/third-party/alert.css os=Darwin
style chrome://global/content/customizeToolbar.xul chrome://greasemonkey/skin/browser.css
resource greasemonkey modules/
@@ -4,8 +4,8 @@ menuitem.install=Install This User Script...
tooltip.disabled=Greasemonkey is disabled.
tooltip.enabled=Greasemonkey is enabled.
tooltip.loading=Loading...
-script.installed=installed successfully
-script.updated=updated successfully
+script.installed=installed successfully.
+script.updated=updated successfully.
install.msg=You are about to install the following Greasemonkey user script:
greeting.msg=This is a Greasemonkey user script. Click install to start using it.
greeting.btn=Install
@@ -8,6 +8,10 @@ error.parsingScript=Could not parse script:
error.scriptCharset=Error reading script: All Greasemonkey scripts MUST be encoded with UTF-8.
error.serverReturned=Server returned
error.unknown=Unknown error.
+notification.neveragain.label=Never show this again
+notification.neveragain.accesskey=N
+notification.ok.label=Ok
+notification.ok.accesskey=O
return-not-in-func-deprecated=Warning: use of return outside of functions is deprecated and may cause failures in future versions of Greasemonkey.
warning.scripts-should-grant=Warning: All scripts should specify @grant metadata.
warning.scripts-should-grant.read-docs=Read documentation
View
@@ -1,33 +1,38 @@
+Components.utils.import("resource://gre/modules/PopupNotifications.jsm");
+Components.utils.import("resource://greasemonkey/prefmanager.js");
+Components.utils.import('resource://greasemonkey/util.js');
+
var EXPORTED_SYMBOLS = ["GM_notification"];
var Cc = Components.classes;
var Ci = Components.interfaces;
-// The first time this runs, we check if nsIAlertsService is installed and
-// works. If it fails, we re-define notify to use a chrome window.
-// We check to see if nsIAlertsService works because of the case where Growl
-// is not installed. See also https://bugzilla.mozilla.org/show_bug.cgi?id=597165
-function notify() {
- try {
- Cc["@mozilla.org/alerts-service;1"]
- .getService(Ci.nsIAlertsService)
- .showAlertNotification.apply(null, arguments);
- } catch (e) {
- notify = function() {
- Cc['@mozilla.org/embedcomp/window-watcher;1']
- .getService(Ci.nsIWindowWatcher)
- .openWindow(null, 'chrome://global/content/alerts/alert.xul',
- '_blank', 'chrome,titlebar=no,popup=yes', null)
- .arguments = arguments;
- };
- notify.apply(null, arguments);
- }
+var gStringBundle = Components
+ .classes["@mozilla.org/intl/stringbundle;1"]
+ .getService(Components.interfaces.nsIStringBundleService)
+ .createBundle("chrome://greasemonkey/locale/greasemonkey.properties");
+
+function mute(aTopic) {
+ GM_prefRoot.setValue('notification.muted.' + aTopic, true);
}
-function GM_notification(aMsg, aTitle) {
- var title = aTitle ? "" + aTitle : "Greasemonkey";
- var message = aMsg ? "" + aMsg : "";
- notify(
- "chrome://greasemonkey/skin/icon32.png",
- title, message, false, "", null);
+function GM_notification(
+ aMsg, aTopic) {
+ var muted = GM_prefRoot.getValue('notification.muted.' + aTopic, false);
+ if (muted) return;
+
+ var action = {
+ 'label': gStringBundle.GetStringFromName('notification.ok.label'),
+ 'accessKey': gStringBundle.GetStringFromName('notification.ok.accesskey'),
+ 'callback': function() { },
+ }
+ var muteAction = {
+ 'label': gStringBundle.GetStringFromName('notification.neveragain.label'),
+ 'accessKey': gStringBundle.GetStringFromName('notification.neveragain.accesskey'),
+ 'callback': function() { mute(aTopic); },
+ };
+ var win = GM_util.getBrowserWindow();
+ win.PopupNotifications.show(
+ win.gBrowser.selectedBrowser, 'greasemonkey-notification',
+ aMsg, null, action, [muteAction]);
};
View
@@ -339,7 +339,8 @@ RemoteScript.prototype.install = function(aOldScript, aOnlyDependencies) {
// Let the user know we're all done.
GM_notification(
"'" + this.script.name + "' "
- + stringBundleBrowser.GetStringFromName(this.messageName));
+ + stringBundleBrowser.GetStringFromName(this.messageName),
+ this.messageName);
}
};
View
@@ -20,6 +20,8 @@ toolbar[iconsize="small"] #greasemonkey-tbb {
-moz-binding: url('chrome://greasemonkey/content/bindings.xml#greasemonkey-tbb')/**/
}
-.popup-notification-icon[popupid="greasemonkey-grants"] {
+.popup-notification-icon[popupid="greasemonkey-grants"],
+.popup-notification-icon[popupid="greasemonkey-notification"]
+{
list-style-image: url("chrome://greasemonkey/skin/icon32.png");
}
View
@@ -1,99 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Scott MacGregor <mscott@netscape.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/* ===== alert.css =====================================================
- == Styles specific to the alerts dialog.
- ======================================================================= */
-
-@import url("chrome://global/skin/");
-
-@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
-
-.alertBox {
- border: 2px solid #7B969C;
- background-color: -moz-Dialog;
- min-height: 50px;
-}
-
-.alertBox[orient="horizontal"] > .alertImageBox {
- -moz-margin-start: 4px;
- -moz-margin-end: 6px;
- min-height: 46px;
-}
-
-.alertBox[orient="vertical"] > .alertImageBox {
- margin-top: 6px;
- margin-bottom: 4px;
- min-width: 46px;
-}
-
-.alertTitle {
- font-weight: bold;
-}
-
-.alertText {
- -moz-margin-end: 6px;
-}
-
-#alertNotification[clickable="true"] {
- cursor: pointer;
-}
-
-label {
- cursor: inherit;
-}
-
-.alertText[clickable="true"] {
- color: -moz-nativehyperlinktext;
- text-decoration: underline;
-}
-
-.alertText[clickable="true"]:hover:active {
- color: #424F63;
-}
-
-.alertBox[orient="horizontal"] > .alertTextBox {
- -moz-padding-end: 10px;
- padding-top: 5px;
-}
-
-.alertBox[orient="vertical"] > .alertTextBox {
- -moz-padding-start: 5px;
- -moz-padding-end: 5px;
- margin-bottom: 8px;
- -moz-box-align: center; /* also hard-coded in alert.js, see bug 311557 */
-}

0 comments on commit d957130

Please sign in to comment.