[gtk-mac-integration] Bug 703781 - app menu item disappears when made insensitive
- From: John Ralls <jralls src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-mac-integration] Bug 703781 - app menu item disappears when made insensitive
- Date: Sat, 13 Jul 2013 23:40:15 +0000 (UTC)
commit 1278ca1aa2d9ae1c8a0ce9647f2b8f55e3c4a3dd
Author: John Ralls <jralls ceridwen us>
Date: Sat Jul 13 16:33:05 2013 -0700
Bug 703781 - app menu item disappears when made insensitive
Set the GtkMenuItem visible before calling cocoa_menu_item_add_item
in gtkosx_application_insert_app_menu_item instead of calling setHidden
on the resulting NSMenuItem, and
Override GNSMenuItem isEnabled/setEnabled to operate on the action
property instead of the enabled property. It seems that the enabled
property has no effect upon NSMenuItems in the application menu.
Provide a button to toggle the sensitivity of the preferences menu item
in test-integration.c to test the above changes.
src/GNSMenuItem.c | 13 +++++++++++++
src/GNSMenuItem.h | 2 ++
src/gtkosxapplication_quartz.c | 3 +--
src/test-integration.c | 18 ++++++++++++++++++
4 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/src/GNSMenuItem.c b/src/GNSMenuItem.c
index 0916406..f7b715a 100644
--- a/src/GNSMenuItem.c
+++ b/src/GNSMenuItem.c
@@ -105,6 +105,19 @@ idle_call_activate (ClosureData *action)
#endif
}
+-(BOOL) isEnabled
+{
+ return [self action] != nil;
+}
+
+-(void) setEnabled: (BOOL)shouldEnable
+{
+ if (shouldEnable)
+ [self setAction: @selector (activate:)];
+ else
+ [self setAction: nil];
+}
+
-(void) mark
{
notUsed = YES;
diff --git a/src/GNSMenuItem.h b/src/GNSMenuItem.h
index 299be33..9f946a8 100644
--- a/src/GNSMenuItem.h
+++ b/src/GNSMenuItem.h
@@ -87,6 +87,8 @@ typedef struct {
- (BOOL) isHidden;
- (void) setHidden: (BOOL) shouldHide;
+- (BOOL) isEnabled;
+- (void) setEnabled: (BOOL) shouldEnable;
- (void) mark;
- (void) unmark;
- (BOOL) isMarked;
diff --git a/src/gtkosxapplication_quartz.c b/src/gtkosxapplication_quartz.c
index 0386c39..656f79f 100644
--- a/src/gtkosxapplication_quartz.c
+++ b/src/gtkosxapplication_quartz.c
@@ -736,10 +736,9 @@ gtkosx_application_insert_app_menu_item (GtkosxApplication* self,
GtkWidget* item,
gint index)
{
+ gtk_widget_set_visible (item, TRUE);
cocoa_menu_item_add_item ([[[NSApp mainMenu] itemAtIndex: 0] submenu],
item, index);
- [(_GNSMenuItem*)[[[[NSApp mainMenu] itemAtIndex: 0] submenu]
- itemAtIndex: index] setHidden: NO];
}
/**
diff --git a/src/test-integration.c b/src/test-integration.c
index 0d6678b..225d92e 100644
--- a/src/test-integration.c
+++ b/src/test-integration.c
@@ -459,6 +459,17 @@ change_icon_cb (GtkWidget *button,
{
}
#endif //GTKMACINTEGRATION
+static void
+toggle_prefs_cb (GtkWidget *button,
+ gpointer user_data)
+{
+ GtkWidget *window = gtk_widget_get_toplevel (button);
+ MenuItems *items = g_object_get_qdata (G_OBJECT (window), menu_items_quark);
+ gboolean state = gtk_widget_get_sensitive (GTK_WIDGET (items->preferences_item));
+ g_print ("Setting Preferences Item sensitive to %s\n",
+ state ? "False" : "True");
+ gtk_widget_set_sensitive (GTK_WIDGET (items->preferences_item), !state);
+}
static void
change_menu_cb (GtkWidget *button,
@@ -706,6 +717,13 @@ create_window (const gchar *title)
button,
FALSE, FALSE, 0);
+ button = gtk_toggle_button_new_with_label ("Sensitive_Prefs");
+ g_signal_connect (button, "toggled", G_CALLBACK (toggle_prefs_cb), NULL);
+ gtk_box_pack_start (GTK_BOX (bbox),
+ button,
+ FALSE, FALSE, 0);
+
+
gtk_widget_show_all (window);
#if defined GTK_MAC_MENU || defined GTKOSXAPPLICATION
gtk_widget_hide (menubar);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]