pidgin: 181764ee: pounce dialog: Try to always have a row ...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Mon Aug 24 02:11:26 EDT 2009


-----------------------------------------------------------------
Revision: 181764ee5b9643826233ae4d6eefb5be194cca08
Ancestor: 3b7e2f38dc6152b559ddfe04b44fdf8310800237
Author: darkrain42 at pidgin.im
Date: 2009-08-24T06:04:16
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/181764ee5b9643826233ae4d6eefb5be194cca08

Modified files:
        pidgin/gtknotify.c

ChangeLog: 

pounce dialog: Try to always have a row selected. Fixes #10037.

When dismissing a row, this is used to determine what to select:
if (one selected)
	select next if possible, otherwise select previous
else
	select first element

-------------- next part --------------
============================================================
--- pidgin/gtknotify.c	b771a3451e7edb3232967b6233fab08cc5329709
+++ pidgin/gtknotify.c	f11c1e5cc3372a2ccad81d393e5936a050683918
@@ -211,25 +211,53 @@ pounce_response_dismiss()
 static void
 pounce_response_dismiss()
 {
+	GtkTreeModel *model = GTK_TREE_MODEL(pounce_dialog->treemodel);
 	GtkTreeSelection *selection;
 	GtkTreeIter iter;
+	GtkTreeIter new_selection;
 	GList *list = NULL;
+	gboolean found_selection = FALSE;
 
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pounce_dialog->treeview));
 	gtk_tree_selection_selected_foreach(selection, delete_foreach, pounce_dialog);
 	gtk_tree_selection_selected_foreach(selection, append_to_list, &list);
 
+	g_return_if_fail(list != NULL);
+
+	if (list->next == NULL) {
+		gtk_tree_model_get_iter(model, &new_selection, list->data);
+		if (gtk_tree_model_iter_next(model, &new_selection))
+			found_selection = TRUE;
+		else {
+			/* This is the last thing in the list */
+			GtkTreePath *path;
+
+			/* Because gtk_tree_model_iter_prev doesn't exist... */
+			gtk_tree_model_get_iter(model, &new_selection, list->data);
+			path = gtk_tree_model_get_path(model, &new_selection);
+			if (gtk_tree_path_prev(path)) {
+				gtk_tree_model_get_iter(model, &new_selection, path);
+				found_selection = TRUE;
+			}
+
+			gtk_tree_path_free(path);
+		}
+	}
+
 	while (list) {
-		GtkTreeIter iter;
-		if (gtk_tree_model_get_iter(GTK_TREE_MODEL(pounce_dialog->treemodel), &iter,
-					list->data)) {
+		if (gtk_tree_model_get_iter(model, &iter, list->data)) {
 			gtk_tree_store_remove(GTK_TREE_STORE(pounce_dialog->treemodel), &iter);
 		}
 		gtk_tree_path_free(list->data);
 		list = g_list_delete_link(list, list);
 	}
 
-	if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(pounce_dialog->treemodel), &iter))
+	if (gtk_tree_model_get_iter_first(model, &iter)) {
+		if (found_selection)
+			gtk_tree_selection_select_iter(selection, &new_selection);
+		else
+			gtk_tree_selection_select_iter(selection, &iter);
+	} else
 		pounce_response_close(pounce_dialog);
 }
 
@@ -240,7 +268,7 @@ pounce_response_open_ims()
 
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pounce_dialog->treeview));
 	gtk_tree_selection_selected_foreach(selection, open_im_foreach, pounce_dialog);
-	
+
 	pounce_response_dismiss();
 }
 
@@ -1400,6 +1428,7 @@ pidgin_notify_pounce_add(PurpleAccount *
 	GdkPixbuf *icon;
 	GtkTreeIter iter;
 	PidginNotifyPounceData *pounce_data;
+	gboolean first = (pounce_dialog == NULL);
 
 	if (pounce_dialog == NULL)
 		pounce_dialog = pidgin_create_notification_dialog(PIDGIN_NOTIFY_POUNCE);
@@ -1423,6 +1452,12 @@ pidgin_notify_pounce_add(PurpleAccount *
 			PIDGIN_POUNCE_DATA, pounce_data,
 			-1);
 
+	if (first) {
+		GtkTreeSelection *selection =
+				gtk_tree_view_get_selection(GTK_TREE_VIEW(pounce_dialog->treeview));
+		gtk_tree_selection_select_iter(selection, &iter);
+	}
+
 	if (icon)
 		g_object_unref(icon);
 


More information about the Commits mailing list