summaryrefslogtreecommitdiff
path: root/gtk/gtkaction.c
diff options
context:
space:
mode:
authorMatthias Clasen <maclas@gmx.de>2003-09-30 20:55:24 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2003-09-30 20:55:24 +0000
commit57f13d815ddbdb0d001fa92c823d44744b3577e4 (patch)
tree132e7f9da4eaa9e59fb3443c548db4b714192871 /gtk/gtkaction.c
parent039c6b3bb16343428708ef827a937a7ac64a44a0 (diff)
downloadgdk-pixbuf-57f13d815ddbdb0d001fa92c823d44744b3577e4.tar.gz
Test handling of empty menus.
2003-09-30 Matthias Clasen <maclas@gmx.de> * tests/merge-*.ui: * tests/testmerge.c: Test handling of empty menus. * gtk/gtkuimanager.c (_gtk_menu_is_empty): New function to determine whether a menu is empty. Used in gtkaction.c. (update_smart_separators): Also update the visibility of empty menus. (update_node): When creating a new menu proxy, insert an "Empty" menu item which only gets shown if the menu is empty. * gtk/gtkaction.c (gtk_action_class_init): Document the meaning of "is_important" for menu proxies. (_gtk_action_sync_menu_visible): New function to sync the visibility of menu proxies. Used in gtkuimanager.c. (gtk_action_sync_visible): New function to sync the visibility of proxies.
Diffstat (limited to 'gtk/gtkaction.c')
-rw-r--r--gtk/gtkaction.c65
1 files changed, 61 insertions, 4 deletions
diff --git a/gtk/gtkaction.c b/gtk/gtkaction.c
index 50bc3c4f0..33bacf738 100644
--- a/gtk/gtkaction.c
+++ b/gtk/gtkaction.c
@@ -40,6 +40,7 @@
#include "gtkmarshalers.h"
#include "gtkmenuitem.h"
#include "gtkstock.h"
+#include "gtktearoffmenuitem.h"
#include "gtktoolbutton.h"
#include "gtktoolbar.h"
@@ -88,7 +89,7 @@ enum
PROP_STOCK_ID,
PROP_IS_IMPORTANT,
PROP_SENSITIVE,
- PROP_VISIBLE,
+ PROP_VISIBLE
};
static void gtk_action_init (GtkAction *action);
@@ -216,7 +217,7 @@ gtk_action_class_init (GtkActionClass *klass)
PROP_IS_IMPORTANT,
g_param_spec_boolean ("is_important",
_("Is important"),
- _("Whether the action is considered important. When TRUE, toolitem proxies for this action show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
+ _("Whether the action is considered important. When TRUE, toolitem proxies for this action show text in GTK_TOOLBAR_BOTH_HORIZ mode, and empty menu proxies for this action are not hidden."),
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
@@ -234,7 +235,6 @@ gtk_action_class_init (GtkActionClass *klass)
TRUE,
G_PARAM_READWRITE));
-
/**
* GtkAction::activate:
* @action: the #GtkAction
@@ -530,6 +530,63 @@ gtk_action_sync_property (GtkAction *action,
g_value_unset (&value);
}
+/**
+ * _gtk_action_sync_menu_visible:
+ * @action: a #GtkAction, or %NULL to determine the action from @proxy
+ * @proxy: a proxy menu item
+ * @empty: whether the submenu attached to @proxy is empty
+ *
+ * Updates the visibility of @proxy from the visibility of @action
+ * according to the following rules:
+ * <itemizedlist>
+ * <listitem><para>if @action is invisible, @proxy is too
+ * </para></listitem>
+ * <listitem><para>if @empty is %TRUE, hide @proxy unless @action is important
+ * </para></listitem>
+ * </itemizedlist>
+ *
+ * This function is used in the implementation of #GtkUIManager.
+ **/
+void
+_gtk_action_sync_menu_visible (GtkAction *action,
+ GtkWidget *proxy,
+ gboolean empty)
+{
+ gboolean visible, important;
+
+ g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
+ g_return_if_fail (action == NULL || GTK_IS_ACTION (action));
+
+ if (action == NULL)
+ action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
+
+ g_object_get (G_OBJECT (action),
+ "visible", &visible,
+ "is_important", &important,
+ NULL);
+
+ g_object_set (G_OBJECT (proxy),
+ "visible", visible && (important || !empty),
+ NULL);
+}
+
+gboolean _gtk_menu_is_empty (GtkWidget *menu);
+
+static void
+gtk_action_sync_visible (GtkAction *action,
+ GParamSpec *pspec,
+ GtkWidget *proxy)
+{
+ if (GTK_IS_MENU_ITEM (proxy))
+ {
+ GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy));
+
+ _gtk_action_sync_menu_visible (action, proxy, _gtk_menu_is_empty (menu));
+ }
+ else
+ gtk_action_sync_property (action, pspec, proxy);
+}
+
static void
gtk_action_sync_label (GtkAction *action,
GParamSpec *pspec,
@@ -627,7 +684,7 @@ connect_proxy (GtkAction *action,
gtk_widget_set_sensitive (proxy, action->private_data->sensitive);
g_signal_connect_object (action, "notify::visible",
- G_CALLBACK (gtk_action_sync_property), proxy, 0);
+ G_CALLBACK (gtk_action_sync_visible), proxy, 0);
if (action->private_data->visible)
gtk_widget_show (proxy);
else