[Pkg-mozext-commits] [firetray] 135/399: attempt to add a popup menu item to open new browser window
David Prévot
taffit at alioth.debian.org
Tue Oct 29 18:23:28 UTC 2013
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch dfsg-clean
in repository firetray.
commit 24a5344bbf2cacf33fca0f920d8579a2c98fbafe
Author: foudfou <foudil.newbie+git at gmail.com>
Date: Sat Jan 14 03:55:25 2012 +0100
attempt to add a popup menu item to open new browser window
---
src/chrome/locale/en-US/overlay.properties | 1 +
src/modules/FiretrayHandler.jsm | 9 +++++
src/modules/ctypes/gtk.jsm | 42 ++++++++-------------
src/modules/gtk2/FiretrayStatusIcon.jsm | 55 ++++++++++++++++++++--------
4 files changed, 65 insertions(+), 42 deletions(-)
diff --git a/src/chrome/locale/en-US/overlay.properties b/src/chrome/locale/en-US/overlay.properties
index 3b00e64..53b2e35 100644
--- a/src/chrome/locale/en-US/overlay.properties
+++ b/src/chrome/locale/en-US/overlay.properties
@@ -1,3 +1,4 @@
extensions.{9533f794-00b4-4354-aa15-c2bbda6989f8}.description=A system tray extension for linux.
popupMenu.itemLabel.Quit=Quit
+popupMenu.itemLabel.NewWindow=New window
tooltip.unread_messages=#1 unread message;#1 unread messages
diff --git a/src/modules/FiretrayHandler.jsm b/src/modules/FiretrayHandler.jsm
index 5d03edc..d954bf9 100644
--- a/src/modules/FiretrayHandler.jsm
+++ b/src/modules/FiretrayHandler.jsm
@@ -154,6 +154,15 @@ firetray.Handler = {
return winOut;
},
+ openBrowserWindow: function() {
+ var handler = Components.classes["@mozilla.org/browser/clh;1"]
+ .getService(Components.interfaces.nsIBrowserHandler);
+ var homePage = handler.defaultArgs;
+ LOG("homePage="+homePage);
+ var win = Services.wm.getMostRecentWindow("navigator:browser"); // nsIDOMWindow=[object ChromeWindow]
+ win.open(homePage);
+ },
+
quitApplication: function() {
try {
let appStartup = Cc['@mozilla.org/toolkit/app-startup;1']
diff --git a/src/modules/ctypes/gtk.jsm b/src/modules/ctypes/gtk.jsm
index 71630b1..e64cceb 100644
--- a/src/modules/ctypes/gtk.jsm
+++ b/src/modules/ctypes/gtk.jsm
@@ -48,6 +48,7 @@ function gtk_defines(lib) {
this.GtkImageMenuItem = ctypes.StructType("GtkImageMenuItem");
this.GtkWindow = ctypes.StructType("GtkWindow");
this.GtkWindowType = ctypes.int; // enum
+ this.GtkSeparatorMenuItem = ctypes.StructType("GtkSeparatorMenuItem");
this.GtkMenuPositionFunc_t = ctypes.FunctionType(
ctypes.default_abi, ctypes.void_t,
@@ -68,43 +69,30 @@ function gtk_defines(lib) {
[this.GtkWidget.ptr, gdk.GdkEventWindowState.ptr, gobject.gpointer]).ptr;
lib.lazy_bind("gtk_status_icon_new", this.GtkStatusIcon.ptr);
- lib.lazy_bind("gtk_status_icon_set_from_file", ctypes.void_t,
- this.GtkStatusIcon.ptr, ctypes.char.ptr);
- lib.lazy_bind("gtk_status_icon_set_tooltip_text", ctypes.void_t,
- this.GtkStatusIcon.ptr, ctypes.char.ptr);
+ lib.lazy_bind("gtk_status_icon_set_from_file", ctypes.void_t, this.GtkStatusIcon.ptr, ctypes.char.ptr);
+ lib.lazy_bind("gtk_status_icon_set_tooltip_text", ctypes.void_t, this.GtkStatusIcon.ptr, ctypes.char.ptr);
lib.lazy_bind("gtk_menu_new", this.GtkMenu.ptr);
- lib.lazy_bind("gtk_image_menu_item_new_with_label", this.GtkImageMenuItem.ptr,
- gobject.gchar.ptr);
- lib.lazy_bind("gtk_image_new_from_stock", this.GtkWidget.ptr,
- gobject.gchar.ptr, ctypes.int); // enum
- lib.lazy_bind("gtk_image_menu_item_set_image", ctypes.void_t,
- this.GtkImageMenuItem.ptr, this.GtkWidget.ptr);
- lib.lazy_bind("gtk_menu_shell_append", ctypes.void_t,
- this.GtkMenuShell.ptr, this.GtkImageMenuItem.ptr);
+ lib.lazy_bind("gtk_image_menu_item_new_with_label", this.GtkImageMenuItem.ptr, gobject.gchar.ptr);
+ lib.lazy_bind("gtk_image_new_from_stock", this.GtkWidget.ptr, gobject.gchar.ptr, ctypes.int); // enum
+ lib.lazy_bind("gtk_image_menu_item_set_image", ctypes.void_t, this.GtkImageMenuItem.ptr, this.GtkWidget.ptr);
+ lib.lazy_bind("gtk_menu_shell_append", ctypes.void_t, this.GtkMenuShell.ptr, this.GtkWidget.ptr);
+ lib.lazy_bind("gtk_menu_shell_prepend", ctypes.void_t, this.GtkMenuShell.ptr, this.GtkWidget.ptr);
lib.lazy_bind("gtk_widget_show_all", ctypes.void_t, this.GtkWidget.ptr);
- lib.lazy_bind("gtk_menu_popup", ctypes.void_t,
- this.GtkMenu.ptr, this.GtkWidget.ptr, this.GtkWidget.ptr,
- this.GtkMenuPositionFunc_t, gobject.gpointer, gobject.guint,
- gobject.guint);
- lib.lazy_bind("gtk_status_icon_position_menu", ctypes.void_t,
- this.GtkMenu.ptr, gobject.gint.ptr, gobject.gint.ptr,
- gobject.gboolean.ptr, gobject.gpointer);
+ lib.lazy_bind("gtk_menu_popup", ctypes.void_t, this.GtkMenu.ptr, this.GtkWidget.ptr, this.GtkWidget.ptr, this.GtkMenuPositionFunc_t, gobject.gpointer, gobject.guint, gobject.guint);
+ lib.lazy_bind("gtk_status_icon_position_menu", ctypes.void_t, this.GtkMenu.ptr, gobject.gint.ptr, gobject.gint.ptr, gobject.gboolean.ptr, gobject.gpointer);
+ lib.lazy_bind("gtk_separator_menu_item_new", this.GtkWidget.ptr);
lib.lazy_bind("gtk_window_new", this.GtkWidget.ptr, this.GtkWindowType);
- lib.lazy_bind("gtk_widget_create_pango_layout", pango.PangoLayout.ptr,
- this.GtkWidget.ptr, gobject.gchar.ptr);
+ lib.lazy_bind("gtk_widget_create_pango_layout", pango.PangoLayout.ptr, this.GtkWidget.ptr, gobject.gchar.ptr);
lib.lazy_bind("gtk_widget_destroy", ctypes.void_t, this.GtkWidget.ptr);
- lib.lazy_bind("gtk_status_icon_set_from_pixbuf", ctypes.void_t,
- this.GtkStatusIcon.ptr, gdk.GdkPixbuf.ptr);
+ lib.lazy_bind("gtk_status_icon_set_from_pixbuf", ctypes.void_t, this.GtkStatusIcon.ptr, gdk.GdkPixbuf.ptr);
lib.lazy_bind("gtk_window_list_toplevels", gobject.GList.ptr);
lib.lazy_bind("gtk_window_get_title", gobject.gchar.ptr, this.GtkWindow.ptr);
- lib.lazy_bind("gtk_widget_get_has_window", gobject.gboolean,
- this.GtkWidget.ptr);
+ lib.lazy_bind("gtk_widget_get_has_window", gobject.gboolean, this.GtkWidget.ptr);
lib.lazy_bind("gtk_widget_get_window", gdk.GdkWindow.ptr, this.GtkWidget.ptr);
lib.lazy_bind("gtk_widget_get_parent_window", gdk.GdkWindow.ptr, this.GtkWidget.ptr);
- lib.lazy_bind("gtk_window_set_decorated", ctypes.void_t, this.GtkWindow.ptr,
- gobject.gboolean);
+ lib.lazy_bind("gtk_window_set_decorated", ctypes.void_t, this.GtkWindow.ptr, gobject.gboolean);
lib.lazy_bind("gtk_widget_hide_on_delete", gobject.gboolean, this.GtkWidget.ptr);
// lib.lazy_bind("gtk_widget_hide", ctypes.void_t, this.GtkWidget.ptr);
diff --git a/src/modules/gtk2/FiretrayStatusIcon.jsm b/src/modules/gtk2/FiretrayStatusIcon.jsm
index 704c5db..8a0ef3c 100644
--- a/src/modules/gtk2/FiretrayStatusIcon.jsm
+++ b/src/modules/gtk2/FiretrayStatusIcon.jsm
@@ -20,14 +20,10 @@ Cu.import("resource://firetray/commons.js");
if ("undefined" == typeof(firetray.Handler))
ERROR("This module MUST be imported from/after FiretrayHandler !");
-// pointers to JS functions. MUST LIVE DURING ALL THE EXECUTION
-var firetray_iconActivateCb;
-var firetray_popupMenuCb;
-var firetray_menuItemQuitActivateCb;
-
firetray.StatusIcon = {
initialized: false,
+ callbacks: {}, // pointers to JS functions. MUST LIVE DURING ALL THE EXECUTION
trayIcon: null,
menu: null,
MIN_FONT_SIZE: 4,
@@ -48,8 +44,10 @@ firetray.StatusIcon = {
firetray.Handler.setTooltipDefault();
LOG("showHideAllWindows: "+firetray.Handler.hasOwnProperty("showHideAllWindows"));
- firetray_iconActivateCb = gtk.GCallbackStatusIconActivate_t(firetray.Handler.showHideAllWindows);
- let handlerId = gobject.g_signal_connect(firetray.StatusIcon.trayIcon, "activate", firetray_iconActivateCb, null);
+ this.callbacks.iconActivate = gtk.GCallbackStatusIconActivate_t(
+ firetray.Handler.showHideAllWindows);
+ let handlerId = gobject.g_signal_connect(firetray.StatusIcon.trayIcon,
+ "activate", firetray.StatusIcon.callbacks.iconActivate, null);
LOG("g_connect activate="+handlerId);
this.initialized = true;
@@ -68,6 +66,34 @@ firetray.StatusIcon = {
_buildPopupMenu: function() {
this.menu = gtk.gtk_menu_new();
+ var menuShell = ctypes.cast(this.menu, gtk.GtkMenuShell.ptr);
+
+ /*
+ * FIXME: somehow a ctypes callback calling win.open() seems to break
+ * main-thread-only rule :-(
+ * https://developer.mozilla.org/en/js-ctypes/js-ctypes_reference/Callbacks
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=513778#c4
+ * https://wiki.mozilla.org/Jsctypes/api#Callbacks
+ * consider using nsIJetpackService
+ */
+/*
+ var mozAppId = Services.appinfo.ID;
+ if (mozAppId === FIREFOX_ID || mozAppId === SEAMONKEY_ID) { // browser
+ var menuItemNewWindowLabel = firetray.Utils.strings.GetStringFromName("popupMenu.itemLabel.NewWindow");
+ var menuItemNewWindow = gtk.gtk_image_menu_item_new_with_label(
+ menuItemNewWindowLabel);
+ gtk.gtk_menu_shell_append(menuShell, ctypes.cast(menuItemNewWindow, gtk.GtkWidget.ptr));
+
+ this.callbacks.menuItemNewWindowActivate = gobject.GCallback_t(
+ firetray.Handler.sendOpenBrowserWindowEvent);
+ gobject.g_signal_connect(menuItemNewWindow, "activate",
+ firetray.StatusIcon.callbacks.menuItemNewWindowActivate, null);
+
+ var menuSeparator = gtk.gtk_separator_menu_item_new();
+ gtk.gtk_menu_shell_append(menuShell, ctypes.cast(menuSeparator, gtk.GtkWidget.ptr));
+ }
+*/
+
// shouldn't need to convert to utf8 thank to js-ctypes
var menuItemQuitLabel = firetray.Utils.strings.GetStringFromName("popupMenu.itemLabel.Quit");
var menuItemQuit = gtk.gtk_image_menu_item_new_with_label(
@@ -75,13 +101,12 @@ firetray.StatusIcon = {
var menuItemQuitIcon = gtk.gtk_image_new_from_stock(
"gtk-quit", gtk.GTK_ICON_SIZE_MENU);
gtk.gtk_image_menu_item_set_image(menuItemQuit, menuItemQuitIcon);
- var menuShell = ctypes.cast(this.menu, gtk.GtkMenuShell.ptr);
- gtk.gtk_menu_shell_append(menuShell, menuItemQuit);
+ gtk.gtk_menu_shell_append(menuShell, ctypes.cast(menuItemQuit, gtk.GtkWidget.ptr));
- firetray_menuItemQuitActivateCb = gobject.GCallback_t(
- function(){firetray.Handler.quitApplication();});
+ this.callbacks.menuItemQuitActivate = gobject.GCallback_t(
+ firetray.Handler.quitApplication);
gobject.g_signal_connect(menuItemQuit, "activate",
- firetray_menuItemQuitActivateCb, null);
+ firetray.StatusIcon.callbacks.menuItemQuitActivate, null);
var menuWidget = ctypes.cast(this.menu, gtk.GtkWidget.ptr);
gtk.gtk_widget_show_all(menuWidget);
@@ -90,9 +115,9 @@ firetray.StatusIcon = {
definition) because we need the args passed to it ! As a consequence, we
need to abandon 'this' in popupMenu() */
let that = this;
- firetray_popupMenuCb = gtk.GCallbackMenuPopup_t(that.popupMenu);
+ this.callbacks.popupMenu = gtk.GCallbackMenuPopup_t(that.popupMenu);
gobject.g_signal_connect(this.trayIcon, "popup-menu",
- firetray_popupMenuCb, this.menu);
+ firetray.StatusIcon.callbacks.popupMenu, this.menu);
},
popupMenu: function(icon, button, activateTime, menu) {
@@ -106,7 +131,7 @@ firetray.StatusIcon = {
gtkMenuPtr, null, null, gtk.gtk_status_icon_position_menu,
iconGpointer, button, activateTime);
} catch (x) {
- LOG(x);
+ ERROR(x);
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firetray.git
More information about the Pkg-mozext-commits
mailing list