[epiphany] WebExtension: Check that accelerator does not already exist before setting
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] WebExtension: Check that accelerator does not already exist before setting
- Date: Mon, 11 Jul 2022 23:34:02 +0000 (UTC)
commit c02462537affa4117b59731de141e14da32b415f
Author: Jamie Murphy <hello itsjamie dev>
Date: Mon Jul 11 00:53:38 2022 -0700
WebExtension: Check that accelerator does not already exist before setting
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1171>
src/webextension/api/commands.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
---
diff --git a/src/webextension/api/commands.c b/src/webextension/api/commands.c
index 56dfb94ba..bc7dd7f9a 100644
--- a/src/webextension/api/commands.c
+++ b/src/webextension/api/commands.c
@@ -77,9 +77,16 @@ setup_action (EphyWebExtension *self,
g_autofree char *action_name = get_action_name (self, command);
g_autofree char *accel_action_name = get_accel_action_name (self, command);
g_autoptr (GSimpleAction) action = g_simple_action_new (action_name, NULL);
+ g_autofree char **current_actions = gtk_application_get_actions_for_accel (GTK_APPLICATION
(ephy_shell_get_default ()),
+ accels[0]);
g_action_map_add_action (G_ACTION_MAP (ephy_shell_get_default ()), G_ACTION (action));
+ if (current_actions[0] != NULL) {
+ g_warning ("Accelerator %s already set, not overriding", command->accelerator);
+ return;
+ }
+
gtk_application_set_accels_for_action (GTK_APPLICATION (ephy_shell_get_default ()),
accel_action_name,
accels);
@@ -233,10 +240,17 @@ commands_handler_update (EphyWebExtensionSender *sender,
}
if (shortcut) {
+ g_autofree char **current_accels = gtk_application_get_actions_for_accel (GTK_APPLICATION
(ephy_shell_get_default ()),
+ command->accelerator);
action_name = get_accel_action_name (sender->extension, command);
- gtk_application_set_accels_for_action (GTK_APPLICATION (ephy_shell_get_default ()),
- action_name,
- (const char *[]) { command->accelerator, NULL });
+
+ if (current_accels[0] != NULL) {
+ g_warning ("Accelerator %s already set, not overriding", command->accelerator);
+ } else {
+ gtk_application_set_accels_for_action (GTK_APPLICATION (ephy_shell_get_default ()),
+ action_name,
+ (const char *[]) { command->accelerator, NULL });
+ }
}
g_task_return_pointer (task, NULL, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]