From 0f7229d8813cd0281c5fd172f89eb36991e07c7f Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 8 Mar 2018 14:07:26 +0000 Subject: [PATCH 2/2] Improve default selection in pidgin_notify_searchresults_new_rows() If there's only one row in the results, select it so that the user can just click one of the action buttons without having to select it first. Also, on updates make an attempt to keep the "same" row selected by using the first column as a 'key'. It won't always be perfect but that's fine. Worst case, the user will have to select the one they want manually. Which is what they have to do after an update now anyway, since we clear the selection and leave *nothing* selected. --- pidgin/gtknotify.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pidgin/gtknotify.c b/pidgin/gtknotify.c index 462c168..831b2dc 100644 --- a/pidgin/gtknotify.c +++ b/pidgin/gtknotify.c @@ -907,12 +907,18 @@ pidgin_notify_searchresults_new_rows(PurpleConnection *gc, PurpleNotifySearchRes void *data_) { PidginNotifySearchResultsData *data = data_; + GtkTreeSelection *selection; GtkListStore *model = data->model; GtkTreeIter iter; GdkPixbuf *pixbuf; GList *row, *column; + gchar *previous_selection = NULL; guint n; + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->treeview)); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, 1, &previous_selection, -1); + gtk_list_store_clear(data->model); pixbuf = pidgin_create_prpl_icon(purple_connection_get_account(gc), PIDGIN_PRPL_ICON_SMALL); @@ -923,11 +929,19 @@ pidgin_notify_searchresults_new_rows(PurpleConnection *gc, PurpleNotifySearchRes gtk_list_store_set(model, &iter, 0, pixbuf, -1); n = 1; - for (column = row->data; column != NULL; column = column->next) { + column = row->data; + /* Select this row, if the first column matches the previously + * selected row OR if there is only one row in the results. */ + if (!g_strcmp0(previous_selection, column->data) || + (row == results->rows && !row->next)) + gtk_tree_selection_select_iter(selection, &iter); + + for (; column != NULL; column = column->next) { GValue v; v.g_type = 0; g_value_init(&v, G_TYPE_STRING); + g_value_set_static_string(&v, column->data); gtk_list_store_set_value(model, &iter, n, &v); n++; @@ -940,6 +954,8 @@ pidgin_notify_searchresults_new_rows(PurpleConnection *gc, PurpleNotifySearchRes if (results != data->results) purple_notify_searchresults_free(results); + g_free(previous_selection); + if (pixbuf != NULL) g_object_unref(pixbuf); } -- 2.7.4