2 * GTK - The GIMP Toolkit
3 * Copyright (C) 1998, 1999 Red Hat, Inc.
6 * This Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with the Gnome Library; see the file COPYING.LIB. If not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * Author: James Henstridge <james@daa.com.au>
25 * Modified by the GTK+ Team and others 2003. See the AUTHORS
26 * file for a list of people on the GTK+ Team. See the ChangeLog
27 * files for a list of changes. These files are distributed with
28 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include "gtkaction.h"
34 #include "gtkbutton.h"
35 #include "gtktoolbutton.h"
36 #include "gtkmenuitem.h"
37 #include "gtkimagemenuitem.h"
41 #include "gtkaccellabel.h"
45 #define GTK_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION, GtkActionPrivate))
47 struct _GtkActionPrivate
53 gchar *stock_id; /* icon */
57 guint label_set : 1; /* these two used so we can set label */
58 guint short_label_set : 1; /* based on stock id */
59 guint is_important : 1;
63 GtkAccelGroup *accel_group;
64 GClosure *accel_closure;
67 /* list of proxy widgets */
90 static void gtk_action_init (GtkAction *action);
91 static void gtk_action_class_init (GtkActionClass *class);
93 static GQuark accel_path_id = 0;
94 static const gchar *accel_path_key = "GtkAction::accel_path";
97 gtk_action_get_type (void)
99 static GtkType type = 0;
103 static const GTypeInfo type_info =
105 sizeof (GtkActionClass),
106 (GBaseInitFunc) NULL,
107 (GBaseFinalizeFunc) NULL,
108 (GClassInitFunc) gtk_action_class_init,
109 (GClassFinalizeFunc) NULL,
114 (GInstanceInitFunc) gtk_action_init,
117 type = g_type_register_static (G_TYPE_OBJECT,
124 static void gtk_action_finalize (GObject *object);
125 static void gtk_action_set_property (GObject *object,
129 static void gtk_action_get_property (GObject *object,
134 static GtkWidget *create_menu_item (GtkAction *action);
135 static GtkWidget *create_tool_item (GtkAction *action);
136 static void connect_proxy (GtkAction *action,
138 static void disconnect_proxy (GtkAction *action,
140 static void closure_accel_activate (GClosure *closure,
141 GValue *return_value,
142 guint n_param_values,
143 const GValue *param_values,
144 gpointer invocation_hint,
145 gpointer marshal_data);
147 static GObjectClass *parent_class = NULL;
148 static guint action_signals[LAST_SIGNAL] = { 0 };
152 gtk_action_class_init (GtkActionClass *klass)
154 GObjectClass *gobject_class;
156 accel_path_id = g_quark_from_static_string (accel_path_key);
158 parent_class = g_type_class_peek_parent (klass);
159 gobject_class = G_OBJECT_CLASS (klass);
161 gobject_class->finalize = gtk_action_finalize;
162 gobject_class->set_property = gtk_action_set_property;
163 gobject_class->get_property = gtk_action_get_property;
165 klass->activate = NULL;
167 klass->create_menu_item = create_menu_item;
168 klass->create_tool_item = create_tool_item;
169 klass->connect_proxy = connect_proxy;
170 klass->disconnect_proxy = disconnect_proxy;
172 klass->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
173 klass->toolbar_item_type = GTK_TYPE_TOOL_BUTTON;
175 g_object_class_install_property (gobject_class,
177 g_param_spec_string ("name",
179 _("A unique name for the action."),
182 G_PARAM_CONSTRUCT_ONLY));
183 g_object_class_install_property (gobject_class,
185 g_param_spec_string ("label",
187 _("The label used for menu items and buttons that activate this action."),
190 g_object_class_install_property (gobject_class,
192 g_param_spec_string ("short_label",
194 _("A shorter label that may be used on toolbar buttons."),
197 g_object_class_install_property (gobject_class,
199 g_param_spec_string ("tooltip",
201 _("A tooltip for this action."),
204 g_object_class_install_property (gobject_class,
206 g_param_spec_string ("stock_id",
208 _("The stock icon displayed in widgets representing this action."),
211 g_object_class_install_property (gobject_class,
213 g_param_spec_boolean ("is_important",
215 _("Whether the action is considered important. When TRUE, toolitem proxies for this action show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
218 g_object_class_install_property (gobject_class,
220 g_param_spec_boolean ("sensitive",
222 _("Whether the action is enabled."),
225 g_object_class_install_property (gobject_class,
227 g_param_spec_boolean ("visible",
229 _("Whether the action is visible."),
235 * GtkAction::activate:
236 * @action: the #GtkAction
238 * The "activate" signal is emitted when the action is activated.
242 action_signals[ACTIVATE] =
243 g_signal_new ("activate",
244 G_OBJECT_CLASS_TYPE (klass),
245 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
246 G_STRUCT_OFFSET (GtkActionClass, activate), NULL, NULL,
247 g_cclosure_marshal_VOID__VOID,
250 g_type_class_add_private (gobject_class, sizeof (GtkActionPrivate));
255 gtk_action_init (GtkAction *action)
257 action->private_data = GTK_ACTION_GET_PRIVATE (action);
259 action->private_data->name = NULL;
260 action->private_data->label = NULL;
261 action->private_data->short_label = NULL;
262 action->private_data->tooltip = NULL;
263 action->private_data->stock_id = NULL;
264 action->private_data->is_important = FALSE;
266 action->private_data->sensitive = TRUE;
267 action->private_data->visible = TRUE;
269 action->private_data->label_set = FALSE;
270 action->private_data->short_label_set = FALSE;
272 action->private_data->accel_count = 0;
273 action->private_data->accel_closure =
274 g_closure_new_object (sizeof (GClosure), G_OBJECT (action));
275 g_closure_set_marshal (action->private_data->accel_closure,
276 closure_accel_activate);
277 g_closure_ref (action->private_data->accel_closure);
278 g_closure_sink (action->private_data->accel_closure);
280 action->private_data->accel_quark = 0;
281 action->private_data->accel_count = 0;
282 action->private_data->accel_group = NULL;
284 action->private_data->proxies = NULL;
288 gtk_action_finalize (GObject *object)
291 action = GTK_ACTION (object);
293 g_free (action->private_data->name);
294 g_free (action->private_data->label);
295 g_free (action->private_data->short_label);
296 g_free (action->private_data->tooltip);
297 g_free (action->private_data->stock_id);
299 g_closure_unref (action->private_data->accel_closure);
300 if (action->private_data->accel_group)
301 g_object_unref (action->private_data->accel_group);
305 gtk_action_set_property (GObject *object,
313 action = GTK_ACTION (object);
318 tmp = action->private_data->name;
319 action->private_data->name = g_value_dup_string (value);
323 tmp = action->private_data->label;
324 action->private_data->label = g_value_dup_string (value);
326 action->private_data->label_set = (action->private_data->label != NULL);
327 /* if label is unset, then use the label from the stock item */
328 if (!action->private_data->label_set && action->private_data->stock_id)
330 GtkStockItem stock_item;
332 if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
333 action->private_data->label = g_strdup (stock_item.label);
335 /* if short_label is unset, set short_label=label */
336 if (!action->private_data->short_label_set)
338 tmp = action->private_data->short_label;
339 action->private_data->short_label = g_strdup (action->private_data->label);
341 g_object_notify (object, "short_label");
344 case PROP_SHORT_LABEL:
345 tmp = action->private_data->short_label;
346 action->private_data->short_label = g_value_dup_string (value);
348 action->private_data->short_label_set = (action->private_data->short_label != NULL);
349 /* if short_label is unset, then use the value of label */
350 if (!action->private_data->short_label_set)
352 action->private_data->short_label = g_strdup (action->private_data->label);
356 tmp = action->private_data->tooltip;
357 action->private_data->tooltip = g_value_dup_string (value);
361 tmp = action->private_data->stock_id;
362 action->private_data->stock_id = g_value_dup_string (value);
364 /* update label and short_label if appropriate */
365 if (!action->private_data->label_set)
367 GtkStockItem stock_item;
369 g_free (action->private_data->label);
370 if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
371 action->private_data->label = g_strdup (stock_item.label);
373 action->private_data->label = NULL;
374 g_object_notify (object, "label");
376 if (!action->private_data->short_label_set)
378 tmp = action->private_data->short_label;
379 action->private_data->short_label = g_strdup (action->private_data->label);
381 g_object_notify (object, "short_label");
384 case PROP_IS_IMPORTANT:
385 action->private_data->is_important = g_value_get_boolean (value);
388 action->private_data->sensitive = g_value_get_boolean (value);
391 action->private_data->visible = g_value_get_boolean (value);
394 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
400 gtk_action_get_property (GObject *object,
407 action = GTK_ACTION (object);
412 g_value_set_string (value, action->private_data->name);
415 g_value_set_string (value, action->private_data->label);
417 case PROP_SHORT_LABEL:
418 g_value_set_string (value, action->private_data->short_label);
421 g_value_set_string (value, action->private_data->tooltip);
424 g_value_set_string (value, action->private_data->stock_id);
426 case PROP_IS_IMPORTANT:
427 g_value_set_boolean (value, action->private_data->is_important);
430 g_value_set_boolean (value, action->private_data->sensitive);
433 g_value_set_boolean (value, action->private_data->visible);
436 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
442 create_menu_item (GtkAction *action)
444 GType menu_item_type;
446 menu_item_type = GTK_ACTION_GET_CLASS (action)->menu_item_type;
448 return g_object_new (menu_item_type, NULL);
452 create_tool_item (GtkAction *action)
454 GType toolbar_item_type;
456 toolbar_item_type = GTK_ACTION_GET_CLASS (action)->toolbar_item_type;
458 return g_object_new (toolbar_item_type, NULL);
462 remove_proxy (GtkWidget *proxy,
465 if (GTK_IS_MENU_ITEM (proxy))
466 gtk_action_disconnect_accelerator (action);
468 action->private_data->proxies = g_slist_remove (action->private_data->proxies, proxy);
472 gtk_action_sync_property (GtkAction *action,
476 const gchar *property;
477 GValue value = { 0, };
479 property = g_param_spec_get_name (pspec);
481 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
482 g_object_get_property (G_OBJECT (action), property, &value);
484 g_object_set_property (G_OBJECT (proxy), property, &value);
485 g_value_unset (&value);
489 gtk_action_sync_label (GtkAction *action,
493 GtkWidget *label = NULL;
495 g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
496 label = GTK_BIN (proxy)->child;
498 if (GTK_IS_LABEL (label))
499 gtk_label_set_label (GTK_LABEL (label), action->private_data->label);
503 gtk_action_sync_short_label (GtkAction *action,
507 GValue value = { 0, };
509 g_value_init (&value, G_TYPE_STRING);
510 g_object_get_property (G_OBJECT (action), "short_label", &value);
512 g_object_set_property (G_OBJECT (proxy), "label", &value);
513 g_value_unset (&value);
517 gtk_action_sync_stock_id (GtkAction *action,
521 GtkWidget *image = NULL;
523 if (GTK_IS_IMAGE_MENU_ITEM (proxy))
525 image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
527 if (GTK_IS_IMAGE (image))
528 gtk_image_set_from_stock (GTK_IMAGE (image),
529 action->private_data->stock_id, GTK_ICON_SIZE_MENU);
534 gtk_action_create_menu_proxy (GtkToolItem *tool_item,
537 GtkWidget *menu_item = gtk_action_create_menu_item (action);
539 g_object_ref (menu_item);
540 gtk_object_sink (GTK_OBJECT (menu_item));
542 gtk_tool_item_set_proxy_menu_item (tool_item, "gtk-action-menu-item", menu_item);
543 g_object_unref (menu_item);
549 connect_proxy (GtkAction *action,
552 g_object_ref (action);
553 g_object_set_data_full (G_OBJECT (proxy), "gtk-action", action,
556 /* add this widget to the list of proxies */
557 action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy);
558 g_signal_connect (proxy, "destroy",
559 G_CALLBACK (remove_proxy), action);
561 g_signal_connect_object (action, "notify::sensitive",
562 G_CALLBACK (gtk_action_sync_property), proxy, 0);
563 gtk_widget_set_sensitive (proxy, action->private_data->sensitive);
565 g_signal_connect_object (action, "notify::visible",
566 G_CALLBACK (gtk_action_sync_property), proxy, 0);
567 if (action->private_data->visible)
568 gtk_widget_show (proxy);
570 gtk_widget_hide (proxy);
571 gtk_widget_set_no_show_all (proxy, TRUE);
573 if (GTK_IS_MENU_ITEM (proxy))
576 /* menu item specific synchronisers ... */
578 if (action->private_data->accel_quark)
580 gtk_action_connect_accelerator (action);
581 gtk_menu_item_set_accel_path (GTK_MENU_ITEM (proxy),
582 g_quark_to_string (action->private_data->accel_quark));
585 label = GTK_BIN (proxy)->child;
587 /* make sure label is a label */
588 if (label && !GTK_IS_LABEL (label))
590 gtk_container_remove (GTK_CONTAINER (proxy), label);
595 label = g_object_new (GTK_TYPE_ACCEL_LABEL,
596 "use_underline", TRUE,
602 if (GTK_IS_ACCEL_LABEL (label) && action->private_data->accel_quark)
603 g_object_set (G_OBJECT (label),
604 "accel_closure", action->private_data->accel_closure,
607 gtk_label_set_label (GTK_LABEL (label), action->private_data->label);
608 g_signal_connect_object (action, "notify::label",
609 G_CALLBACK (gtk_action_sync_label), proxy, 0);
611 if (GTK_IS_IMAGE_MENU_ITEM (proxy))
615 image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
616 if (image && !GTK_IS_IMAGE (image))
618 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), NULL);
623 image = gtk_image_new_from_stock (NULL,
625 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy),
627 gtk_widget_show (image);
629 gtk_image_set_from_stock (GTK_IMAGE (image),
630 action->private_data->stock_id, GTK_ICON_SIZE_MENU);
631 g_signal_connect_object (action, "notify::stock_id",
632 G_CALLBACK (gtk_action_sync_stock_id),
636 g_signal_connect_object (proxy, "activate",
637 G_CALLBACK (gtk_action_activate), action,
641 else if (GTK_IS_TOOL_BUTTON (proxy))
643 /* toolbar button specific synchronisers ... */
645 g_object_set (G_OBJECT (proxy),
646 "label", action->private_data->short_label,
647 "use_underline", TRUE,
648 "stock_id", action->private_data->stock_id,
649 "is_important", action->private_data->is_important,
651 g_signal_connect_object (action, "notify::short_label",
652 G_CALLBACK (gtk_action_sync_short_label),
654 g_signal_connect_object (action, "notify::stock_id",
655 G_CALLBACK (gtk_action_sync_property),
657 g_signal_connect_object (action, "notify::is_important",
658 G_CALLBACK (gtk_action_sync_property),
661 g_signal_connect_object (proxy, "create_menu_proxy",
662 G_CALLBACK (gtk_action_create_menu_proxy),
665 g_signal_connect_object (proxy, "clicked",
666 G_CALLBACK (gtk_action_activate), action,
669 else if (GTK_IS_BUTTON (proxy))
671 /* button specific synchronisers ... */
673 /* synchronise the label */
674 g_object_set (G_OBJECT (proxy),
675 "label", action->private_data->short_label,
676 "use_underline", TRUE,
678 g_signal_connect_object (action, "notify::short_label",
679 G_CALLBACK (gtk_action_sync_short_label),
682 g_signal_connect_object (proxy, "clicked",
683 G_CALLBACK (gtk_action_activate), action,
689 disconnect_proxy (GtkAction *action,
692 g_object_set_data (G_OBJECT (proxy), "gtk-action", NULL);
694 /* remove proxy from list of proxies */
695 g_signal_handlers_disconnect_by_func (proxy,
696 G_CALLBACK (remove_proxy),
698 remove_proxy (proxy, action);
700 /* disconnect the activate handler */
701 g_signal_handlers_disconnect_by_func (proxy,
702 G_CALLBACK (gtk_action_activate),
705 /* disconnect handlers for notify::* signals */
706 g_signal_handlers_disconnect_by_func (proxy,
707 G_CALLBACK (gtk_action_sync_property),
710 g_signal_handlers_disconnect_by_func (action,
711 G_CALLBACK (gtk_action_sync_stock_id), proxy);
713 /* menu item specific synchronisers ... */
714 g_signal_handlers_disconnect_by_func (action,
715 G_CALLBACK (gtk_action_sync_label),
718 /* toolbar button specific synchronisers ... */
719 g_signal_handlers_disconnect_by_func (action,
720 G_CALLBACK (gtk_action_sync_short_label),
723 g_signal_handlers_disconnect_by_func (proxy,
724 G_CALLBACK (gtk_action_create_menu_proxy),
729 * gtk_action_activate:
730 * @action: the action object
732 * Emits the "activate" signal on the specified action.
733 * This gets called by the proxy widgets when they get activated.
735 * It can also be used to manually activate an action.
740 gtk_action_activate (GtkAction *action)
742 g_signal_emit (action, action_signals[ACTIVATE], 0);
746 * gtk_action_create_icon:
747 * @action: the action object
748 * @icon_size: the size of the icon that should be created.
750 * This function is intended for use by action implementations to
751 * create icons displayed in the proxy widgets.
753 * Returns: a widget that displays the icon for this action.
758 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
760 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
762 if (action->private_data->stock_id)
763 return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
769 * gtk_action_create_menu_item:
770 * @action: the action object
772 * Creates a menu item widget that proxies for the given action.
774 * Returns: a menu item connected to the action.
779 gtk_action_create_menu_item (GtkAction *action)
781 GtkWidget *menu_item;
783 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
785 menu_item = (* GTK_ACTION_GET_CLASS (action)->create_menu_item) (action);
787 (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, menu_item);
793 * gtk_action_create_tool_item:
794 * @action: the action object
796 * Creates a toolbar item widget that proxies for the given action.
798 * Returns: a toolbar item connected to the action.
803 gtk_action_create_tool_item (GtkAction *action)
807 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
809 button = (* GTK_ACTION_GET_CLASS (action)->create_tool_item) (action);
811 (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, button);
817 * gtk_action_connect_proxy:
818 * @action: the action object
819 * @proxy: the proxy widget
821 * Connects a widget to an action object as a proxy. Synchronises
822 * various properties of the action with the widget (such as label
823 * text, icon, tooltip, etc), and attaches a callback so that the
824 * action gets activated when the proxy widget does.
826 * If the widget is already connected to an action, it is disconnected
832 gtk_action_connect_proxy (GtkAction *action,
835 GtkAction *prev_action;
837 g_return_if_fail (GTK_IS_ACTION (action));
838 g_return_if_fail (GTK_IS_WIDGET (proxy));
840 prev_action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
843 (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (prev_action, proxy);
845 (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, proxy);
849 * gtk_action_disconnect_proxy:
850 * @action: the action object
851 * @proxy: the proxy widget
853 * Disconnects a proxy widget from an action.
854 * Does <emphasis>not</emphasis> destroy the widget, however.
859 gtk_action_disconnect_proxy (GtkAction *action,
862 g_return_if_fail (GTK_IS_ACTION (action));
863 g_return_if_fail (GTK_IS_WIDGET (proxy));
865 g_return_if_fail (g_object_get_data (G_OBJECT (proxy), "gtk-action") == action);
867 (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (action, proxy);
871 * gtk_action_get_proxies:
872 * @action: the action object
874 * Returns the proxy widgets for an action.
876 * Return value: a #GSList of proxy widgets. The list is owned by the action and
877 * must not be modified.
882 gtk_action_get_proxies (GtkAction *action)
884 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
886 return action->private_data->proxies;
891 * gtk_action_get_name:
892 * @action: the action object
894 * Returns the name of the action.
896 * Return value: the name of the action. The string belongs to GTK+ and should not
902 gtk_action_get_name (GtkAction *action)
904 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
906 return action->private_data->name;
910 * gtk_action_block_activate_from:
911 * @action: the action object
912 * @proxy: a proxy widget
914 * Disables calls to the gtk_action_activate()
915 * function by signals on the given proxy widget. This is used to
916 * break notification loops for things like check or radio actions.
918 * This function is intended for use by action implementations.
923 gtk_action_block_activate_from (GtkAction *action,
926 g_return_if_fail (GTK_IS_ACTION (action));
928 g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
933 * gtk_action_unblock_activate_from:
934 * @action: the action object
935 * @proxy: a proxy widget
937 * Re-enables calls to the gtk_action_activate()
938 * function by signals on the given proxy widget. This undoes the
939 * blocking done by gtk_action_block_activate_from().
941 * This function is intended for use by action implementations.
946 gtk_action_unblock_activate_from (GtkAction *action,
949 g_return_if_fail (GTK_IS_ACTION (action));
951 g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
956 closure_accel_activate (GClosure *closure,
957 GValue *return_value,
958 guint n_param_values,
959 const GValue *param_values,
960 gpointer invocation_hint,
961 gpointer marshal_data)
963 if (GTK_ACTION (closure->data)->private_data->sensitive)
964 g_signal_emit (closure->data, action_signals[ACTIVATE], 0);
966 /* we handled the accelerator */
967 g_value_set_boolean (return_value, TRUE);
971 * gtk_action_set_accel_path:
972 * @action: the action object
973 * @accel_path: the accelerator path
975 * Sets the accel path for this action. All proxy widgets associated
976 * with the action will have this accel path, so that their
977 * accelerators are consistent.
982 gtk_action_set_accel_path (GtkAction *action,
983 const gchar *accel_path)
985 g_return_if_fail (GTK_IS_ACTION (action));
987 action->private_data->accel_quark = g_quark_from_string (accel_path);
991 * gtk_action_set_accel_group:
992 * @action: the action object
993 * @accel_group: a #GtkAccelGroup or %NULL
995 * Sets the #GtkAccelGroup in which the accelerator for this action
1001 gtk_action_set_accel_group (GtkAction *action,
1002 GtkAccelGroup *accel_group)
1004 g_return_if_fail (GTK_IS_ACTION (action));
1005 g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
1008 g_object_ref (accel_group);
1009 if (action->private_data->accel_group)
1010 g_object_unref (action->private_data->accel_group);
1012 action->private_data->accel_group = accel_group;
1016 * gtk_action_connect_accelerator:
1017 * @action: a #GtkAction
1019 * Installs the accelerator for @action if @action has an
1020 * accel path and group. See gtk_action_set_accel_path() and
1021 * gtk_action_set_accel_group()
1023 * Since multiple proxies may independently trigger the installation
1024 * of the accelerator, the @action counts the number of times this
1025 * function has been called and doesn't remove the accelerator until
1026 * gtk_action_disconnect_accelerator() has been called as many times.
1031 gtk_action_connect_accelerator (GtkAction *action)
1033 g_return_if_fail (GTK_IS_ACTION (action));
1035 if (!action->private_data->accel_quark ||
1036 !action->private_data->accel_group)
1039 if (action->private_data->accel_count == 0)
1041 const gchar *accel_path =
1042 g_quark_to_string (action->private_data->accel_quark);
1044 gtk_accel_group_connect_by_path (action->private_data->accel_group,
1046 action->private_data->accel_closure);
1049 action->private_data->accel_count++;
1053 * gtk_action_disconnect_accelerator:
1054 * @action: a #GtkAction
1056 * Undoes the effect of one call to gtk_action_connect_accelerator().
1061 gtk_action_disconnect_accelerator (GtkAction *action)
1063 g_return_if_fail (GTK_IS_ACTION (action));
1065 if (!action->private_data->accel_quark ||
1066 !action->private_data->accel_group)
1069 action->private_data->accel_count--;
1071 if (action->private_data->accel_count == 0)
1072 gtk_accel_group_disconnect (action->private_data->accel_group,
1073 action->private_data->accel_closure);