[gnome-control-center/wip/input-sources: 11/14] region: Improved keynav and selection handling on the input chooser
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/input-sources: 11/14] region: Improved keynav and selection handling on the input chooser
- Date: Mon, 23 Apr 2012 21:12:14 +0000 (UTC)
commit 4cca78bc0679a1a28c72ffed28fba8e41780cbc4
Author: Rui Matos <tiagomatos gmail com>
Date: Wed Apr 18 17:11:08 2012 +0200
region: Improved keynav and selection handling on the input chooser
panels/region/gnome-region-panel-input.c | 61 +++++++++++++++++++++++-------
1 files changed, 47 insertions(+), 14 deletions(-)
---
diff --git a/panels/region/gnome-region-panel-input.c b/panels/region/gnome-region-panel-input.c
index d7b327c..c4b48b5 100644
--- a/panels/region/gnome-region-panel-input.c
+++ b/panels/region/gnome-region-panel-input.c
@@ -607,12 +607,13 @@ static void
filter_changed (GtkBuilder *builder)
{
GtkTreeModelFilter *filtered_model;
+ GtkTreeView *tree_view;
+ GtkTreeSelection *selection;
+ GtkTreeIter selected_iter;
GtkWidget *filter_entry;
const gchar *pattern;
gchar *upattern;
- filtered_model = GTK_TREE_MODEL_FILTER (gtk_builder_get_object (builder,
- "filtered_input_source_model"));
filter_entry = WID ("input_source_filter");
pattern = gtk_entry_get_text (GTK_ENTRY (filter_entry));
upattern = g_utf8_strup (pattern, -1);
@@ -635,7 +636,25 @@ filter_changed (GtkBuilder *builder)
search_pattern_list = g_strsplit (upattern, " ", -1);
g_free (upattern);
+ filtered_model =
+ GTK_TREE_MODEL_FILTER (gtk_builder_get_object (builder, "filtered_input_source_model"));
gtk_tree_model_filter_refilter (filtered_model);
+
+ tree_view = GTK_TREE_VIEW (WID ("filtered_input_source_list"));
+ selection = gtk_tree_view_get_selection (tree_view);
+ if (gtk_tree_selection_get_selected (selection, NULL, &selected_iter))
+ {
+ GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (filtered_model),
+ &selected_iter);
+ gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 0.5, 0.5);
+ gtk_tree_path_free (path);
+ }
+ else
+ {
+ GtkTreeIter iter;
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (filtered_model), &iter))
+ gtk_tree_selection_select_iter (selection, &iter);
+ }
}
static void
@@ -663,6 +682,13 @@ row_activated (GtkTreeView *tree_view,
gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
}
+static void
+entry_activated (GtkBuilder *builder,
+ gpointer data)
+{
+ row_activated (NULL, NULL, NULL, builder);
+}
+
static gboolean
filter_func (GtkTreeModel *model,
GtkTreeIter *iter,
@@ -713,6 +739,7 @@ input_chooser_new (GtkBuilder *main_builder)
GtkTreeSelection *selection;
GtkListStore *model;
GtkTreeModelFilter *filtered_model;
+ GtkTreeIter iter;
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder,
@@ -735,23 +762,17 @@ input_chooser_new (GtkBuilder *main_builder)
gtk_tree_view_append_column (GTK_TREE_VIEW (filtered_list),
visible_column);
+ /* We handle searching ourselves, thank you. */
+ gtk_tree_view_set_enable_search (GTK_TREE_VIEW (filtered_list), FALSE);
+ gtk_tree_view_set_search_column (GTK_TREE_VIEW (filtered_list), -1);
+
+ g_signal_connect_swapped (G_OBJECT (filter_entry), "activate",
+ G_CALLBACK (entry_activated), builder);
g_signal_connect_swapped (G_OBJECT (filter_entry), "notify::text",
G_CALLBACK (filter_changed), builder);
-
g_signal_connect (G_OBJECT (filter_entry), "icon-release",
G_CALLBACK (filter_clear), NULL);
- selection =
- gtk_tree_view_get_selection (GTK_TREE_VIEW (filtered_list));
-
- g_signal_connect (G_OBJECT (selection), "changed",
- G_CALLBACK (selection_changed), builder);
-
- selection_changed (selection, builder);
-
- g_signal_connect (G_OBJECT (filtered_list), "row-activated",
- G_CALLBACK (row_activated), builder);
-
filtered_model =
GTK_TREE_MODEL_FILTER (gtk_builder_get_object (builder, "filtered_input_source_model"));
model =
@@ -766,6 +787,18 @@ input_chooser_new (GtkBuilder *main_builder)
filter_func,
NULL, NULL);
+ selection =
+ gtk_tree_view_get_selection (GTK_TREE_VIEW (filtered_list));
+
+ g_signal_connect (G_OBJECT (selection), "changed",
+ G_CALLBACK (selection_changed), builder);
+
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (filtered_model), &iter))
+ gtk_tree_selection_select_iter (selection, &iter);
+
+ g_signal_connect (G_OBJECT (filtered_list), "row-activated",
+ G_CALLBACK (row_activated), builder);
+
gtk_widget_grab_focus (filter_entry);
gtk_widget_show (chooser);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]