mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
accelerators: Make gtk_accelerator_parse() return TRUE/FALSE
A parse function should return success or not. So do that.
This commit is contained in:
parent
673a0463e0
commit
87df17e4ce
@ -932,8 +932,10 @@ is_keycode (const gchar *string)
|
||||
*
|
||||
* If the parse fails, @accelerator_key, @accelerator_mods and
|
||||
* @accelerator_codes will be set to 0 (zero).
|
||||
*
|
||||
* Returns: %TRUE if parsing succeeded
|
||||
*/
|
||||
void
|
||||
gboolean
|
||||
gtk_accelerator_parse_with_keycode (const gchar *accelerator,
|
||||
guint *accelerator_key,
|
||||
guint **accelerator_codes,
|
||||
@ -950,7 +952,8 @@ gtk_accelerator_parse_with_keycode (const gchar *accelerator,
|
||||
*accelerator_mods = 0;
|
||||
if (accelerator_codes)
|
||||
*accelerator_codes = NULL;
|
||||
g_return_if_fail (accelerator != NULL);
|
||||
|
||||
g_return_val_if_fail (accelerator != NULL, FALSE);
|
||||
|
||||
error = FALSE;
|
||||
keyval = 0;
|
||||
@ -1160,6 +1163,8 @@ out:
|
||||
*accelerator_key = gdk_keyval_to_lower (keyval);
|
||||
if (accelerator_mods)
|
||||
*accelerator_mods = mods;
|
||||
|
||||
return !error;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1183,12 +1188,12 @@ out:
|
||||
* If the parse fails, @accelerator_key and @accelerator_mods will
|
||||
* be set to 0 (zero).
|
||||
*/
|
||||
void
|
||||
gboolean
|
||||
gtk_accelerator_parse (const gchar *accelerator,
|
||||
guint *accelerator_key,
|
||||
GdkModifierType *accelerator_mods)
|
||||
{
|
||||
gtk_accelerator_parse_with_keycode (accelerator, accelerator_key, NULL, accelerator_mods);
|
||||
return gtk_accelerator_parse_with_keycode (accelerator, accelerator_key, NULL, accelerator_mods);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,11 +184,11 @@ GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_accelerator_valid (guint keyval,
|
||||
GdkModifierType modifiers) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_accelerator_parse (const gchar *accelerator,
|
||||
gboolean gtk_accelerator_parse (const gchar *accelerator,
|
||||
guint *accelerator_key,
|
||||
GdkModifierType *accelerator_mods);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_accelerator_parse_with_keycode (const gchar *accelerator,
|
||||
gboolean gtk_accelerator_parse_with_keycode (const gchar *accelerator,
|
||||
guint *accelerator_key,
|
||||
guint **accelerator_codes,
|
||||
GdkModifierType *accelerator_mods);
|
||||
|
@ -195,9 +195,7 @@ gtk_application_accels_set_accels_for_action (GtkApplicationAccels *accels,
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
gtk_accelerator_parse (accelerators[i], &keys[i].key, &keys[i].modifier);
|
||||
|
||||
if (keys[i].key == 0)
|
||||
if (!gtk_accelerator_parse (accelerators[i], &keys[i].key, &keys[i].modifier))
|
||||
{
|
||||
g_warning ("Unable to parse accelerator '%s': ignored request to install %d accelerators",
|
||||
accelerators[i], n);
|
||||
@ -271,12 +269,10 @@ gtk_application_accels_get_actions_for_accel (GtkApplicationAccels *accels,
|
||||
AccelKey accel_key;
|
||||
guint i, n;
|
||||
|
||||
gtk_accelerator_parse (accel, &accel_key.key, &accel_key.modifier);
|
||||
|
||||
if (accel_key.key == 0)
|
||||
if (!gtk_accelerator_parse (accel, &accel_key.key, &accel_key.modifier))
|
||||
{
|
||||
g_critical ("invalid accelerator string '%s'", accel);
|
||||
g_return_val_if_fail (accel_key.key != 0, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
actions_and_targets = g_hash_table_lookup (accels->accel_to_actions, &accel_key);
|
||||
|
@ -303,8 +303,7 @@ parse_combination (GtkShortcutLabel *self,
|
||||
accels = g_strsplit (str, "&", 0);
|
||||
for (k = 0; accels[k]; k++)
|
||||
{
|
||||
gtk_accelerator_parse (accels[k], &key, &modifier);
|
||||
if (key == 0 && modifier == 0)
|
||||
if (!gtk_accelerator_parse (accels[k], &key, &modifier))
|
||||
{
|
||||
retval = FALSE;
|
||||
break;
|
||||
|
@ -1612,8 +1612,10 @@ accel_button_new (GtkAccelGroup *accel_group,
|
||||
GtkWidget *button;
|
||||
GtkWidget *label;
|
||||
|
||||
gtk_accelerator_parse (accel, &keyval, &modifiers);
|
||||
g_assert (keyval);
|
||||
if (!gtk_accelerator_parse (accel, &keyval, &modifiers))
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
button = gtk_button_new ();
|
||||
gtk_widget_add_accelerator (button, "activate", accel_group,
|
||||
|
@ -28,19 +28,19 @@ test_one_accel (const char *accel,
|
||||
char *label, *name;
|
||||
|
||||
accel_key = 0;
|
||||
gtk_accelerator_parse_with_keycode (accel,
|
||||
&accel_key,
|
||||
&keycodes,
|
||||
&mods);
|
||||
g_assert (gtk_accelerator_parse_with_keycode (accel,
|
||||
&accel_key,
|
||||
&keycodes,
|
||||
&mods));
|
||||
|
||||
if (has_keysym)
|
||||
{
|
||||
guint accel_key_2;
|
||||
GdkModifierType mods_2;
|
||||
|
||||
gtk_accelerator_parse (accel,
|
||||
&accel_key_2,
|
||||
&mods_2);
|
||||
g_assert (gtk_accelerator_parse (accel,
|
||||
&accel_key_2,
|
||||
&mods_2));
|
||||
g_assert (accel_key == accel_key_2);
|
||||
g_assert (mods == mods_2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user