Deprecate and ignore gtk-can-change-accels

It is disabled by default
This commit is contained in:
William Jon McCann 2013-06-26 12:00:42 -04:00
parent 7cfa7e6b72
commit 2d79334bb0
5 changed files with 9 additions and 163 deletions

View File

@ -307,7 +307,6 @@ _gdk_win32_window_delete_property (GdkWindow *window,
"Net/CursorBlinkTime\0" "gtk-cursor-blink-time\0"
"Net/ThemeName\0" "gtk-theme-name\0"
"Net/IconThemeName\0" "gtk-icon-theme-name\0"
"Gtk/CanChangeAccels\0" "gtk-can-change-accels\0"
"Gtk/ColorPalette\0" "gtk-color-palette\0"
"Gtk/FontName\0" "gtk-font-name\0"
"Gtk/IconSizes\0" "gtk-icon-sizes\0"

View File

@ -32,7 +32,6 @@ static const struct {
{"Net/CursorBlinkTime", "gtk-cursor-blink-time"},
{"Net/ThemeName", "gtk-theme-name"},
{"Net/IconThemeName", "gtk-icon-theme-name"},
{"Gtk/CanChangeAccels", "gtk-can-change-accels"},
{"Gtk/ColorPalette", "gtk-color-palette"},
{"Gtk/FontName", "gtk-font-name"},
{"Gtk/IconSizes", "gtk-icon-sizes"},

View File

@ -40,7 +40,7 @@
* SECTION:gtkaccelmap
* @Short_description: Loadable keyboard accelerator specifications
* @Title: Accelerator Maps
* @See_also: #GtkAccelGroup, #GtkAccelKey, #GtkUIManager, gtk_widget_set_accel_path(), gtk_menu_item_set_accel_path(), #GtkSettings:gtk-can-change-accels
* @See_also: #GtkAccelGroup, #GtkAccelKey, #GtkUIManager, gtk_widget_set_accel_path(), gtk_menu_item_set_accel_path()
*
* Accelerator maps are used to define runtime configurable accelerators.
* Functions for manipulating them are are usually used by higher level

View File

@ -3391,179 +3391,20 @@ gtk_menu_button_release (GtkWidget *widget,
return GTK_WIDGET_CLASS (gtk_menu_parent_class)->button_release_event (widget, event);
}
static const gchar *
get_accel_path (GtkWidget *menu_item,
gboolean *locked)
{
const gchar *path;
GtkWidget *label;
GClosure *accel_closure;
GtkAccelGroup *accel_group;
path = _gtk_widget_get_accel_path (menu_item, locked);
if (!path)
{
path = GTK_MENU_ITEM (menu_item)->priv->accel_path;
if (locked)
{
*locked = TRUE;
label = gtk_bin_get_child (GTK_BIN (menu_item));
if (GTK_IS_ACCEL_LABEL (label))
{
g_object_get (label,
"accel-closure", &accel_closure,
NULL);
if (accel_closure)
{
accel_group = gtk_accel_group_from_accel_closure (accel_closure);
*locked = gtk_accel_group_get_is_locked (accel_group);
}
}
}
}
return path;
}
static gboolean
gtk_menu_key_press (GtkWidget *widget,
GdkEventKey *event)
{
GtkMenuShell *menu_shell;
GtkMenu *menu;
gboolean delete = FALSE;
gboolean can_change_accels;
gchar *accel = NULL;
guint accel_key, accel_mods;
GdkModifierType consumed_modifiers;
GdkDisplay *display;
g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
menu_shell = GTK_MENU_SHELL (widget);
menu = GTK_MENU (widget);
gtk_menu_stop_navigating_submenu (menu);
if (GTK_WIDGET_CLASS (gtk_menu_parent_class)->key_press_event (widget, event))
return TRUE;
display = gtk_widget_get_display (widget);
g_object_get (gtk_widget_get_settings (widget),
"gtk-menu-bar-accel", &accel,
"gtk-can-change-accels", &can_change_accels,
NULL);
if (accel && *accel)
{
guint keyval = 0;
GdkModifierType mods = 0;
gtk_accelerator_parse (accel, &keyval, &mods);
if (keyval == 0)
g_warning ("Failed to parse menu bar accelerator '%s'\n", accel);
/* FIXME this is wrong, needs to be in the global accel resolution
* thing, to properly consider i18n etc., but that probably requires
* AccelGroup changes etc.
*/
if (event->keyval == keyval && (mods & event->state) == mods)
{
gtk_menu_shell_cancel (menu_shell);
g_free (accel);
return TRUE;
}
}
g_free (accel);
switch (event->keyval)
{
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
case GDK_KEY_BackSpace:
delete = TRUE;
break;
default:
break;
}
/* Figure out what modifiers went into determining the key symbol */
_gtk_translate_keyboard_accel_state (gdk_keymap_get_for_display (display),
event->hardware_keycode,
event->state,
gtk_accelerator_get_default_mod_mask (),
event->group,
&accel_key, NULL, NULL, &consumed_modifiers);
accel_key = gdk_keyval_to_lower (accel_key);
accel_mods = event->state & gtk_accelerator_get_default_mod_mask () & ~consumed_modifiers;
/* If lowercasing affects the keysym, then we need to include SHIFT
* in the modifiers, We re-upper case when we match against the
* keyval, but display and save in caseless form.
*/
if (accel_key != event->keyval)
accel_mods |= GDK_SHIFT_MASK;
/* Modify the accelerators */
if (can_change_accels &&
menu_shell->priv->active_menu_item &&
gtk_bin_get_child (GTK_BIN (menu_shell->priv->active_menu_item)) && /* no separators */
GTK_MENU_ITEM (menu_shell->priv->active_menu_item)->priv->submenu == NULL && /* no submenus */
(delete || gtk_accelerator_valid (accel_key, accel_mods)))
{
GtkWidget *menu_item = menu_shell->priv->active_menu_item;
gboolean locked, replace_accels = TRUE;
const gchar *path;
path = get_accel_path (menu_item, &locked);
if (!path || locked)
{
/* Can't change accelerators on menu_items without paths
* (basically, those items are accelerator-locked).
*/
gtk_widget_error_bell (widget);
}
else
{
gboolean changed;
/* For the keys that act to delete the current setting,
* we delete the current setting if there is one, otherwise,
* we set the key as the accelerator.
*/
if (delete)
{
GtkAccelKey key;
if (gtk_accel_map_lookup_entry (path, &key) &&
(key.accel_key || key.accel_mods))
{
accel_key = 0;
accel_mods = 0;
}
}
changed = gtk_accel_map_change_entry (path, accel_key, accel_mods, replace_accels);
if (!changed)
{
/* We failed, probably because this key is in use
* and locked already.
*/
gtk_widget_error_bell (widget);
}
}
}
return TRUE;
return GTK_WIDGET_CLASS (gtk_menu_parent_class)->key_press_event (widget, event);
}
static gboolean

View File

@ -1324,6 +1324,13 @@ gtk_settings_class_init (GtkSettingsClass *class)
gtk_rc_property_parse_enum);
g_assert (result == PROP_SCROLLED_WINDOW_PLACEMENT);
/**
* GtkSettings:gtk-can-change-accels:
*
* Whether menu accelerators can be changed by pressing a key over the menu item.
*
* Deprecated: 3.10: This setting is ignored.
*/
result = settings_install_property_parser (class,
g_param_spec_boolean ("gtk-can-change-accels",
P_("Can change accelerators"),