patch for menu accelerator bug
- From: "John Sullivan" <sullivan eazel com>
- To: gnome-components-list <gnome-components-list gnome org>
- Subject: patch for menu accelerator bug
- Date: Thu, 31 Aug 2000 11:23:50 -0700
I discovered that changing the label of a menu item does not remove the old
accelerator. The code to do so was present in
menu_toplevel_set_label_internal, but it was broken. It was determining the
accelerator to remove from the new label, after the old one had been freed.
The fix is simple: keep the old label around in a local variable and
determine the accelerator from it, then free the old label. The patch looks
more complicated because there was an early return that I restructured away
so the old label would be freed in all cases.
I'll commit this soon unless someone hollers.
John
Index: bonobo/bonobo-uih-menu.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-uih-menu.c,v
retrieving revision 1.22
diff -u -p -u -r1.22 bonobo-uih-menu.c
--- bonobo/bonobo-uih-menu.c 2000/08/18 00:25:31 1.22
+++ bonobo/bonobo-uih-menu.c 2000/08/31 18:13:50
@@ -2964,55 +2964,57 @@ menu_toplevel_set_label_internal (Bonobo
GtkWidget *menu_widget;
GtkWidget *child;
char *parent_path;
- guint keyval;
+ char *old_label;
+ guint old_keyval;
/*
* Modify the internal data.
*/
- g_free (internal->item->label);
+ old_label = internal->item->label;
internal->item->label = g_strdup (label_text);
/*
* Now modify the widget.
*/
- if (! menu_toplevel_item_is_head (uih, internal))
- return;
+ if (menu_toplevel_item_is_head (uih, internal)) {
+ menu_widget = menu_toplevel_get_widget (uih, internal->item->path);
- menu_widget = menu_toplevel_get_widget (uih, internal->item->path);
+ parent_path = bonobo_ui_handler_path_get_parent
(internal->item->path);
+ parent_shell = menu_toplevel_get_shell (uih, parent_path);
+ g_free (parent_path);
- parent_path = bonobo_ui_handler_path_get_parent (internal->item->path);
- parent_shell = menu_toplevel_get_shell (uih, parent_path);
- g_free (parent_path);
-
- /*
- * Remove the old label widget.
- */
- child = GTK_BIN (menu_widget)->child;
-
- if (child != NULL) {
/*
- * Grab the keyval for the label, if appropriate, so the
- * corresponding accelerator can be removed.
+ * Remove the old label widget.
*/
- keyval = gtk_label_parse_uline (GTK_LABEL (child),
internal->item->label);
- if (uih->top->accelgroup != NULL) {
- if (parent_shell != uih->top->menubar)
- gtk_widget_remove_accelerator (GTK_WIDGET (menu_widget),
uih->top->accelgroup, keyval, 0);
- else
- gtk_widget_remove_accelerator (GTK_WIDGET (menu_widget),
uih->top->accelgroup,
- keyval, GDK_MOD1_MASK);
+ child = GTK_BIN (menu_widget)->child;
+
+ if (child != NULL) {
+ /*
+ * Grab the keyval for the label, if appropriate, so the
+ * corresponding accelerator can be removed.
+ */
+ old_keyval = gtk_label_parse_uline (GTK_LABEL (child),
old_label);
+ if (uih->top->accelgroup != NULL) {
+ if (parent_shell != uih->top->menubar)
+ gtk_widget_remove_accelerator (GTK_WIDGET
(menu_widget), uih->top->accelgroup, old_keyval, 0);
+ else
+ gtk_widget_remove_accelerator (GTK_WIDGET
(menu_widget), uih->top->accelgroup,
+ old_keyval, GDK_MOD1_MASK);
+ }
+
+ /*
+ * Now remove the old label widget.
+ */
+ gtk_container_remove (GTK_CONTAINER (menu_widget), child);
}
/*
- * Now remove the old label widget.
+ * Create the new label widget.
*/
- gtk_container_remove (GTK_CONTAINER (menu_widget), child);
+ menu_toplevel_create_label (uih, internal->item, parent_shell,
menu_widget);
}
-
- /*
- * Create the new label widget.
- */
- menu_toplevel_create_label (uih, internal->item, parent_shell,
menu_widget);
+
+ g_free (old_label);
}
static void
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]