summaryrefslogtreecommitdiff
path: root/gtk/gtkshortcutswindow.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2016-04-17 13:38:51 -0400
committerMatthias Clasen <mclasen@redhat.com>2016-04-17 13:42:14 -0400
commit50f041bc5750e615aef8ba81ecc7614542989143 (patch)
treece215e035f0247d14ab05b9cecc4a2d8e3f01ce0 /gtk/gtkshortcutswindow.c
parent268243834a002ee406ecd846fa66ceac42d68699 (diff)
downloadgtk+-50f041bc5750e615aef8ba81ecc7614542989143.tar.gz
shortcuts: Follow changes of accels
Add a way to associate a detailed action name with a shortcut. If the action name is set, update the accelerator whenever accels change on the window that the shortcuts window is associated with. https://bugzilla.gnome.org/show_bug.cgi?id=764975
Diffstat (limited to 'gtk/gtkshortcutswindow.c')
-rw-r--r--gtk/gtkshortcutswindow.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/gtk/gtkshortcutswindow.c b/gtk/gtkshortcutswindow.c
index 0bea2ce98f..3fdaf78a23 100644
--- a/gtk/gtkshortcutswindow.c
+++ b/gtk/gtkshortcutswindow.c
@@ -22,7 +22,7 @@
#include "gtkscrolledwindow.h"
#include "gtkshortcutssection.h"
#include "gtkshortcutsgroup.h"
-#include "gtkshortcutsshortcut.h"
+#include "gtkshortcutsshortcutprivate.h"
#include "gtksearchbar.h"
#include "gtksearchentry.h"
#include "gtkwidgetprivate.h"
@@ -98,6 +98,9 @@ typedef struct
GtkListBox *list_box;
GtkBox *search_gestures;
GtkBox *search_shortcuts;
+
+ GtkWindow *window;
+ gulong keys_changed_id;
} GtkShortcutsWindowPrivate;
typedef struct
@@ -187,6 +190,7 @@ gtk_shortcuts_window_add_search_item (GtkWidget *child, gpointer data)
gboolean subtitle_set = FALSE;
GtkTextDirection direction;
GtkShortcutType shortcut_type;
+ gchar *action_name = NULL;
gchar *subtitle;
gchar *str;
gchar *keywords;
@@ -200,6 +204,7 @@ gtk_shortcuts_window_add_search_item (GtkWidget *child, gpointer data)
"icon-set", &icon_set,
"subtitle-set", &subtitle_set,
"shortcut-type", &shortcut_type,
+ "action-name", &action_name,
NULL);
hash_key = g_strdup_printf ("%s-%s", title, accelerator);
@@ -220,6 +225,7 @@ gtk_shortcuts_window_add_search_item (GtkWidget *child, gpointer data)
"shortcut-type", shortcut_type,
"accel-size-group", priv->search_image_group,
"title-size-group", priv->search_text_group,
+ "action-name", action_name,
NULL);
if (icon_set)
{
@@ -245,6 +251,7 @@ gtk_shortcuts_window_add_search_item (GtkWidget *child, gpointer data)
g_free (title);
g_free (accelerator);
g_free (str);
+ g_free (action_name);
}
else if (GTK_IS_CONTAINER (child))
{
@@ -435,6 +442,57 @@ gtk_shortcuts_window_set_section_name (GtkShortcutsWindow *self,
}
static void
+update_accels_cb (GtkWidget *widget,
+ gpointer data)
+{
+ GtkShortcutsWindow *self = data;
+ GtkShortcutsWindowPrivate *priv = gtk_shortcuts_window_get_instance_private (self);
+
+ if (GTK_IS_SHORTCUTS_SHORTCUT (widget))
+ gtk_shortcuts_shortcut_update_accel (GTK_SHORTCUTS_SHORTCUT (widget), priv->window);
+ else if (GTK_IS_CONTAINER (widget))
+ gtk_container_foreach (GTK_CONTAINER (widget), update_accels_cb, self);
+}
+
+static void
+update_accels_for_actions (GtkShortcutsWindow *self)
+{
+ GtkShortcutsWindowPrivate *priv = gtk_shortcuts_window_get_instance_private (self);
+
+ if (priv->window)
+ gtk_container_forall (GTK_CONTAINER (self), update_accels_cb, self);
+}
+
+static void
+keys_changed_handler (GtkWindow *window,
+ GtkShortcutsWindow *self)
+{
+ update_accels_for_actions (self);
+}
+
+void
+gtk_shortcuts_window_set_window (GtkShortcutsWindow *self,
+ GtkWindow *window)
+{
+ GtkShortcutsWindowPrivate *priv = gtk_shortcuts_window_get_instance_private (self);
+
+ if (priv->keys_changed_id)
+ {
+ g_signal_handler_disconnect (priv->window, priv->keys_changed_id);
+ priv->keys_changed_id = 0;
+ }
+
+ priv->window = window;
+
+ if (priv->window)
+ priv->keys_changed_id = g_signal_connect (window, "keys-changed",
+ G_CALLBACK (keys_changed_handler),
+ self);
+
+ update_accels_for_actions (self);
+}
+
+static void
gtk_shortcuts_window__list_box__row_activated (GtkShortcutsWindow *self,
GtkListBoxRow *row,
GtkListBox *list_box)
@@ -589,6 +647,8 @@ gtk_shortcuts_window_dispose (GObject *object)
g_signal_handlers_disconnect_by_func (priv->stack, G_CALLBACK (update_title_stack), self);
+ gtk_shortcuts_window_set_window (self, NULL);
+
if (priv->header_bar)
{
gtk_widget_destroy (GTK_WIDGET (priv->header_bar));