[gtk-mac-integration] Bug 707803: Suppress adjacent separators
- From: John Ralls <jralls src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-mac-integration] Bug 707803: Suppress adjacent separators
- Date: Fri, 27 Sep 2013 17:09:00 +0000 (UTC)
commit f29851117ee1dbf14e0c9cfcadccf41a06dedd00
Author: John Ralls <jralls ceridwen us>
Date: Thu Sep 26 13:46:40 2013 -0700
Bug 707803: Suppress adjacent separators
Also separators at the beginning or end of a menu, especially when
they result from moving an entry to a different menu.
src/cocoa_menu_item.c | 36 +++++++++++++++++++++++++++++++++---
src/test-integration.c | 11 ++++++++++-
2 files changed, 43 insertions(+), 4 deletions(-)
---
diff --git a/src/cocoa_menu_item.c b/src/cocoa_menu_item.c
index 30f77e4..4774f24 100644
--- a/src/cocoa_menu_item.c
+++ b/src/cocoa_menu_item.c
@@ -543,10 +543,22 @@ cocoa_menu_item_add_item (NSMenu* cocoa_menu, GtkWidget* menu_item, int index)
if (cocoa_item)
{
+ NSMenu *cocoa_menu = [cocoa_item menu];
+ NSInteger index = [cocoa_menu indexOfItem: cocoa_item];
DEBUG ("\tItem exists\n");
[cocoa_item retain];
- [[cocoa_item menu] removeItem: cocoa_item];
+ [cocoa_menu removeItem: cocoa_item];
[cocoa_item release];
+ /* Clean up adjacent separators: */
+ if ([cocoa_menu numberOfItems] > 0)
+ {
+ if (([cocoa_menu numberOfItems] == index ||
+ [[cocoa_menu itemAtIndex: index] isSeparatorItem]) &&
+ [[cocoa_menu itemAtIndex: index - 1] isSeparatorItem])
+ [cocoa_menu removeItemAtIndex: index - 1];
+ if (index == 0 && [[cocoa_menu itemAtIndex: index] isSeparatorItem])
+ [cocoa_menu removeItemAtIndex: index];
+ }
}
if (GTK_IS_SEPARATOR_MENU_ITEM (GTK_MENU_ITEM (menu_item)))
@@ -599,6 +611,8 @@ cocoa_menu_item_add_submenu (GtkMenuShell *menu_shell,
GList *children;
GList *l;
guint index = 0, count, loc;
+ GtkWidget *last_item = NULL;
+ NSMenuItem *last_cocoa_item = nil;
count = [cocoa_menu numberOfItems];
/* First go through the cocoa menu and mark all of the items unused. */
@@ -651,6 +665,13 @@ cocoa_menu_item_add_submenu (GtkMenuShell *menu_shell,
/* Don't want separators on the menubar */
continue;
+ if (GTK_IS_SEPARATOR_MENU_ITEM (menu_item) &&
+ (last_item == NULL || GTK_IS_SEPARATOR_MENU_ITEM (last_item)))
+ /* Don't put a separator at the top, nor make separators with
+ * nothing between them.
+ */
+ continue;
+
#ifndef HAVE_GTK_34
if (GTK_IS_TEAROFF_MENU_ITEM (menu_item))
/*Don't want tearoff items at all */
@@ -661,15 +682,24 @@ cocoa_menu_item_add_submenu (GtkMenuShell *menu_shell,
continue;
/*OK, this must be a new one. Add it. */
cocoa_menu_item_add_item (cocoa_menu, menu_item, index++);
-
+ last_item = menu_item;
}
- /* Iterate over the cocoa menu again removing anything that's still marked */
+ /* Iterate over the cocoa menu again removing anything that's still
+ marked, checking again for adjacent separators. */
for (index = 0; index < [cocoa_menu numberOfItems]; index++)
{
_GNSMenuItem *item = (_GNSMenuItem*)[cocoa_menu itemAtIndex: index];
+ if ([item isSeparatorItem] &&
+ (last_cocoa_item == nil || [last_cocoa_item isSeparatorItem]))
+ [cocoa_menu removeItem: item];
if (([item respondsToSelector: @selector (isMarked)]) && [item isMarked])
[cocoa_menu removeItem: item];
+ else if (![item isHidden])
+ last_cocoa_item = item;
}
+ /* Finally make sure that the last item isn't a separator. */
+ if ([last_cocoa_item isSeparatorItem])
+ [cocoa_menu removeItem: last_cocoa_item];
g_list_free (children);
}
diff --git a/src/test-integration.c b/src/test-integration.c
index a54f091..56f0575 100644
--- a/src/test-integration.c
+++ b/src/test-integration.c
@@ -60,7 +60,6 @@
//#define GTKMACINTEGRATION
#define GTKOSXAPPLICATION
/* These others are optional */
-#define BUILT_UI
#ifndef HAVE_GTK_310
//#define BUILT_UI //The built UI uses deprecated functions
#endif
@@ -332,6 +331,10 @@ test_setup_menu (MenuItems *items, GtkAccelGroup *accel)
gtk_menu_shell_append (GTK_MENU_SHELL (menubar), item);
menu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
+
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
item = gtk_menu_item_new_with_label ("Copy");
items->copy_item = item;
g_signal_connect_data (item, "activate", G_CALLBACK (menu_item_activate_cb),
@@ -339,12 +342,18 @@ test_setup_menu (MenuItems *items, GtkAccelGroup *accel)
(GClosureNotify) menu_cbdata_delete, 0);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
item = gtk_menu_item_new_with_label ("Paste");
g_signal_connect_data (item, "activate", G_CALLBACK (menu_item_activate_cb),
menu_cbdata_new ( "paste", items->window),
(GClosureNotify) menu_cbdata_delete, 0);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
items->preferences_item = gtk_menu_item_new_with_label ("Preferences");
g_signal_connect_data (items->preferences_item, "activate",
G_CALLBACK (menu_item_activate_cb),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]