[gnome-control-center/wip/feborges/new-search-panel: 13/14] search: Introduce reordering keyboard shortcut
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/feborges/new-search-panel: 13/14] search: Introduce reordering keyboard shortcut
- Date: Mon, 2 Oct 2017 09:29:06 +0000 (UTC)
commit 820d1d938329eb218cf596bad50a530a33f61d9d
Author: Felipe Borges <felipeborges gnome org>
Date: Wed Aug 9 15:49:46 2017 +0200
search: Introduce reordering keyboard shortcut
Alt + UP/DOWN
https://bugzilla.gnome.org/show_bug.cgi?id=775958
panels/search/cc-search-panel.c | 52 +++++++++++++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/panels/search/cc-search-panel.c b/panels/search/cc-search-panel.c
index b67c67a..85c71a3 100644
--- a/panels/search/cc-search-panel.c
+++ b/panels/search/cc-search-panel.c
@@ -545,6 +545,57 @@ drag_leave (GtkWidget *widget,
}
static void
+swap_rows (GtkWidget *source,
+ GtkWidget *target,
+ GtkWidget *list_box)
+{
+ int index;
+
+ index = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (target));
+
+ g_object_ref (source);
+ gtk_container_remove (GTK_CONTAINER (list_box), source);
+ gtk_list_box_insert (GTK_LIST_BOX (list_box), source, index);
+ g_object_unref (source);
+
+ gtk_list_box_select_row (GTK_LIST_BOX (list_box), GTK_LIST_BOX_ROW (source));
+ gtk_widget_grab_focus (source);
+}
+
+static gboolean
+drag_key_press (GtkListBoxRow *row,
+ GdkEventKey *event,
+ CcSearchPanel *self)
+{
+ GtkWidget *target;
+ guint index;
+
+ index = gtk_list_box_row_get_index (row);
+
+ if ((event->state & GDK_MOD1_MASK) != 0 && event->keyval == GDK_KEY_Up)
+ index--;
+ else if ((event->state & GDK_MOD1_MASK) != 0 && event->keyval == GDK_KEY_Down)
+ index++;
+ else
+ return GDK_EVENT_PROPAGATE;
+
+ target = GTK_WIDGET (gtk_list_box_get_row_at_index (GTK_LIST_BOX (self->priv->list_box), index));
+ if (target) {
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (self->priv->list_box), NULL, NULL, NULL);
+
+ swap_rows (GTK_WIDGET (row), target, self->priv->list_box);
+
+ gtk_container_foreach (GTK_CONTAINER (self->priv->list_box), update_row_position, self);
+ search_panel_propagate_sort_order (self);
+
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (self->priv->list_box),
+ (GtkListBoxSortFunc)list_sort_func, self, NULL);
+ }
+
+ return GDK_EVENT_STOP;
+}
+
+static void
search_panel_add_one_app_info (CcSearchPanel *self,
GAppInfo *app_info,
gboolean default_enabled)
@@ -571,6 +622,7 @@ search_panel_add_one_app_info (CcSearchPanel *self,
g_object_ref (app_info), g_object_unref);
g_object_set_data (G_OBJECT (row), "self", self);
gtk_container_add (GTK_CONTAINER (self->priv->list_box), row);
+ g_signal_connect (row, "key-press-event", G_CALLBACK (drag_key_press), self);
/* Drag and Drop */
handle = gtk_event_box_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]