new function as workaround for missing GTK+ API (see bug #141750).

2005-01-21  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpwidgets-utils.[ch] (gimp_action_get_accel_closure):
	new function as workaround for missing GTK+ API	(see bug #141750).

	* app/widgets/gimpactionview.[ch]: use the function instead of
	having this ugly hack here. Store the accel_closure instead of the
	hackish menu_item in the tree store. Removed cruft and cleaned up
	a bit.
This commit is contained in:
Michael Natterer 2005-01-21 14:58:03 +00:00 committed by Michael Natterer
parent f6801672a8
commit a17f8e56d0
5 changed files with 171 additions and 169 deletions

View File

@ -1,3 +1,13 @@
2005-01-21 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpwidgets-utils.[ch] (gimp_action_get_accel_closure):
new function as workaround for missing GTK+ API (see bug #141750).
* app/widgets/gimpactionview.[ch]: use the function instead of
having this ugly hack here. Store the accel_closure instead of the
hackish menu_item in the tree store. Removed cruft and cleaned up
a bit.
2005-01-21 Sven Neumann <sven@gimp.org> 2005-01-21 Sven Neumann <sven@gimp.org>
* app/core/gimpdrawable-transform.c: applied a patch from Geert * app/core/gimpdrawable-transform.c: applied a patch from Geert

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis * Copyright (C) 1995 Spencer Kimball and Peter Mattis
* *
* gimpactionview.c * gimpactionview.c
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org> * Copyright (C) 2004-2005 Michael Natterer <mitch@gimp.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -220,7 +220,7 @@ gimp_action_view_new (GimpUIManager *manager,
G_TYPE_STRING, /* COLUMN_NAME */ G_TYPE_STRING, /* COLUMN_NAME */
G_TYPE_UINT, /* COLUMN_ACCEL_KEY */ G_TYPE_UINT, /* COLUMN_ACCEL_KEY */
GDK_TYPE_MODIFIER_TYPE, /* COLUMN_ACCEL_MASK */ GDK_TYPE_MODIFIER_TYPE, /* COLUMN_ACCEL_MASK */
GTK_TYPE_MENU_ITEM); /* COLUMN_MENU_ITEM */ G_TYPE_CLOSURE); /* COLUMN_ACCEL_CLOSURE */
accel_group = gtk_ui_manager_get_accel_group (GTK_UI_MANAGER (manager)); accel_group = gtk_ui_manager_get_accel_group (GTK_UI_MANAGER (manager));
@ -248,38 +248,28 @@ gimp_action_view_new (GimpUIManager *manager,
{ {
GtkAction *action = list2->data; GtkAction *action = list2->data;
const gchar *name = gtk_action_get_name (action); const gchar *name = gtk_action_get_name (action);
if (! strstr (name, "-menu") &&
! strstr (name, "-popup"))
{
GtkTreeIter action_iter;
gchar *stock_id; gchar *stock_id;
gchar *label; gchar *label;
gchar *stripped; gchar *tmp;
guint accel_key = 0; guint accel_key = 0;
GdkModifierType accel_mask = 0; GdkModifierType accel_mask = 0;
GtkWidget *menu_item = NULL; GClosure *accel_closure = NULL;
GtkTreeIter action_iter;
if (strstr (name, "-menu") || strstr (name, "-popup"))
continue;
g_object_get (action, g_object_get (action,
"stock-id", &stock_id, "stock-id", &stock_id,
"label", &label, "label", &tmp,
NULL); NULL);
stripped = gimp_strip_uline (label); label = gimp_strip_uline (tmp);
g_free (tmp);
if (show_shortcuts) if (show_shortcuts)
{ {
menu_item = gtk_action_create_menu_item (action); accel_closure = gimp_action_get_accel_closure (action);
if (GTK_IS_MENU_ITEM (menu_item) &&
GTK_IS_ACCEL_LABEL (GTK_BIN (menu_item)->child))
{
GtkWidget *accel_label = GTK_BIN (menu_item)->child;
GClosure *accel_closure;
g_object_get (accel_label,
"accel-closure", &accel_closure,
NULL);
if (accel_closure) if (accel_closure)
{ {
@ -296,17 +286,6 @@ gimp_action_view_new (GimpUIManager *manager,
accel_key = key->accel_key; accel_key = key->accel_key;
accel_mask = key->accel_mods; accel_mask = key->accel_mods;
} }
g_closure_unref (accel_closure);
}
g_object_ref (menu_item);
gtk_object_sink (GTK_OBJECT (menu_item));
}
else if (menu_item)
{
gtk_object_sink (GTK_OBJECT (menu_item));
menu_item = NULL;
} }
} }
@ -315,19 +294,15 @@ gimp_action_view_new (GimpUIManager *manager,
gtk_tree_store_set (store, &action_iter, gtk_tree_store_set (store, &action_iter,
GIMP_ACTION_VIEW_COLUMN_ACTION, action, GIMP_ACTION_VIEW_COLUMN_ACTION, action,
GIMP_ACTION_VIEW_COLUMN_STOCK_ID, stock_id, GIMP_ACTION_VIEW_COLUMN_STOCK_ID, stock_id,
GIMP_ACTION_VIEW_COLUMN_LABEL, stripped, GIMP_ACTION_VIEW_COLUMN_LABEL, label,
GIMP_ACTION_VIEW_COLUMN_NAME, name, GIMP_ACTION_VIEW_COLUMN_NAME, name,
GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY, accel_key, GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY, accel_key,
GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK, accel_mask, GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK, accel_mask,
GIMP_ACTION_VIEW_COLUMN_MENU_ITEM, menu_item, GIMP_ACTION_VIEW_COLUMN_ACCEL_CLOSURE, accel_closure,
-1); -1);
g_free (stock_id); g_free (stock_id);
g_free (label); g_free (label);
g_free (stripped);
if (menu_item)
g_object_unref (menu_item);
if (select_action && ! strcmp (select_action, name)) if (select_action && ! strcmp (select_action, name))
{ {
@ -335,7 +310,6 @@ gimp_action_view_new (GimpUIManager *manager,
&action_iter); &action_iter);
} }
} }
}
g_list_free (actions); g_list_free (actions);
} }
@ -473,23 +447,16 @@ gimp_action_view_accel_changed (GtkAccelGroup *accel_group,
child_valid; child_valid;
child_valid = gtk_tree_model_iter_next (model, &child_iter)) child_valid = gtk_tree_model_iter_next (model, &child_iter))
{ {
GtkWidget *menu_item; GClosure *closure;
gtk_tree_model_get (model, &child_iter, gtk_tree_model_get (model, &child_iter,
GIMP_ACTION_VIEW_COLUMN_MENU_ITEM, &menu_item, GIMP_ACTION_VIEW_COLUMN_ACCEL_CLOSURE, &closure,
-1); -1);
if (menu_item) if (closure)
{ g_closure_unref (closure);
GClosure *item_closure;
g_object_get (GTK_BIN (menu_item)->child, if (accel_closure == closure)
"accel-closure", &item_closure,
NULL);
g_object_unref (menu_item);
if (accel_closure == item_closure)
{ {
GtkAccelKey *key; GtkAccelKey *key;
guint accel_key = 0; guint accel_key = 0;
@ -508,10 +475,8 @@ gimp_action_view_accel_changed (GtkAccelGroup *accel_group,
} }
gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter, gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter,
GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY, GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY, accel_key,
accel_key, GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK, accel_mask,
GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK,
accel_mask,
-1); -1);
return; return;
@ -519,7 +484,6 @@ gimp_action_view_accel_changed (GtkAccelGroup *accel_group,
} }
} }
} }
}
typedef struct typedef struct
{ {
@ -558,20 +522,20 @@ gimp_action_view_conflict_confirm (GimpActionView *view,
const gchar *accel_path) const gchar *accel_path)
{ {
GimpActionGroup *group; GimpActionGroup *group;
GimpMessageBox *box;
gchar *label; gchar *label;
gchar *stripped; gchar *tmp;
gchar *accel_string; gchar *accel_string;
ConfirmData *confirm_data; ConfirmData *confirm_data;
GtkWidget *dialog; GtkWidget *dialog;
GimpMessageBox *box;
g_object_get (action, g_object_get (action,
"action-group", &group, "action-group", &group,
"label", &label, "label", &tmp,
NULL); NULL);
stripped = gimp_strip_uline (label); label = gimp_strip_uline (tmp);
g_free (label); g_free (tmp);
accel_string = gimp_get_accel_string (accel_key, accel_mask); accel_string = gimp_get_accel_string (accel_key, accel_mask);
@ -601,13 +565,13 @@ gimp_action_view_conflict_confirm (GimpActionView *view,
gimp_message_box_set_primary_text (box, gimp_message_box_set_primary_text (box,
_("Shortcut \"%s\" is already taken " _("Shortcut \"%s\" is already taken "
"by \"%s\" from the \"%s\" group."), "by \"%s\" from the \"%s\" group."),
accel_string, stripped, group->label); accel_string, label, group->label);
gimp_message_box_set_text (box, gimp_message_box_set_text (box,
_("Reassigning the shortcut will cause it " _("Reassigning the shortcut will cause it "
"to be removed from \"%s\"."), "to be removed from \"%s\"."),
stripped); label);
g_free (stripped); g_free (label);
g_free (accel_string); g_free (accel_string);
g_object_unref (group); g_object_unref (group);
@ -677,9 +641,7 @@ gimp_action_view_accel_edited (GimpCellRendererAccel *accel,
{ {
g_message (_("Invalid shortcut.")); g_message (_("Invalid shortcut."));
} }
else else if (! gtk_accel_map_change_entry (accel_path,
{
if (! gtk_accel_map_change_entry (accel_path,
accel_key, accel_mask, FALSE)) accel_key, accel_mask, FALSE))
{ {
GtkAction *conflict_action = NULL; GtkAction *conflict_action = NULL;
@ -697,8 +659,7 @@ gimp_action_view_accel_edited (GimpCellRendererAccel *accel,
&child_iter, &child_iter,
&iter); &iter);
child_valid; child_valid;
child_valid = gtk_tree_model_iter_next (model, child_valid = gtk_tree_model_iter_next (model, &child_iter))
&child_iter))
{ {
guint child_accel_key; guint child_accel_key;
GdkModifierType child_accel_mask; GdkModifierType child_accel_mask;
@ -725,7 +686,9 @@ gimp_action_view_accel_edited (GimpCellRendererAccel *accel,
break; break;
} }
if (conflict_action && conflict_action != action) if (conflict_action != action)
{
if (conflict_action)
{ {
gimp_action_view_conflict_confirm (view, conflict_action, gimp_action_view_conflict_confirm (view, conflict_action,
accel_key, accel_key,
@ -733,7 +696,7 @@ gimp_action_view_accel_edited (GimpCellRendererAccel *accel,
accel_path); accel_path);
g_object_unref (conflict_action); g_object_unref (conflict_action);
} }
else if (conflict_action != action) else
{ {
g_message (_("Changing shortcut failed.")); g_message (_("Changing shortcut failed."));
} }

View File

@ -2,7 +2,7 @@
* Copyright (C) 1995 Spencer Kimball and Peter Mattis * Copyright (C) 1995 Spencer Kimball and Peter Mattis
* *
* gimpactionview.h * gimpactionview.h
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org> * Copyright (C) 2004-2005 Michael Natterer <mitch@gimp.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -34,7 +34,7 @@ enum
GIMP_ACTION_VIEW_COLUMN_NAME, GIMP_ACTION_VIEW_COLUMN_NAME,
GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY, GIMP_ACTION_VIEW_COLUMN_ACCEL_KEY,
GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK, GIMP_ACTION_VIEW_COLUMN_ACCEL_MASK,
GIMP_ACTION_VIEW_COLUMN_MENU_ITEM, GIMP_ACTION_VIEW_COLUMN_ACCEL_CLOSURE,
GIMP_ACTION_VIEW_NUM_COLUMNS GIMP_ACTION_VIEW_NUM_COLUMNS
}; };
@ -60,8 +60,6 @@ struct _GimpActionView
struct _GimpActionViewClass struct _GimpActionViewClass
{ {
GtkTreeViewClass parent_class; GtkTreeViewClass parent_class;
void (* changed) (GimpActionView *view);
}; };

View File

@ -871,3 +871,32 @@ gimp_toggle_button_set_visible (GtkToggleButton *toggle,
gtk_widget_hide (widget); gtk_widget_hide (widget);
} }
#ifdef __GNUC__
#warning FIXME: remove this function as soon as bug #141750 is fixed.
#endif
GClosure *
gimp_action_get_accel_closure (GtkAction *action)
{
GtkWidget *menu_item;
GClosure *closure = NULL;
g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
menu_item = gtk_action_create_menu_item (action);
if (GTK_IS_MENU_ITEM (menu_item) &&
GTK_IS_ACCEL_LABEL (GTK_BIN (menu_item)->child))
{
GtkWidget *accel_label = GTK_BIN (menu_item)->child;
g_object_get (accel_label, "accel-closure", &closure, NULL);
}
if (menu_item)
gtk_object_sink (GTK_OBJECT (menu_item));
if (closure)
g_closure_unref (closure);
return closure;
}

View File

@ -83,5 +83,7 @@ gboolean gimp_text_buffer_save (GtkTextBuffer *buffer,
void gimp_toggle_button_set_visible (GtkToggleButton *toggle, void gimp_toggle_button_set_visible (GtkToggleButton *toggle,
GtkWidget *widget); GtkWidget *widget);
GClosure * gimp_action_get_accel_closure (GtkAction *action);
#endif /* __GIMP_WIDGETS_UTILS_H__ */ #endif /* __GIMP_WIDGETS_UTILS_H__ */