From cf9a2563c5d4e5642a457e9b2acdc62c336175e5 Mon Sep 17 00:00:00 2001 From: Raphael Groner Date: Mon, 6 Jan 2014 16:35:35 +0100 Subject: [PATCH] scroll the items list automatically to keep the moved item visible at the new position --- panel/panel-preferences-dialog.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/panel/panel-preferences-dialog.c b/panel/panel-preferences-dialog.c index 865d7f3..17266cd 100644 --- a/panel/panel-preferences-dialog.c +++ b/panel/panel-preferences-dialog.c @@ -1025,6 +1025,7 @@ panel_preferences_dialog_item_move (GtkWidget *button, itembar = gtk_bin_get_child (GTK_BIN (dialog->active)); position = panel_itembar_get_child_index (PANEL_ITEMBAR (itembar), GTK_WIDGET (provider)); + path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->store), &iter_a); if (G_LIKELY (position != -1)) { @@ -1051,19 +1052,19 @@ panel_preferences_dialog_item_move (GtkWidget *button, iter_b = iter_a; if (gtk_tree_model_iter_next (GTK_TREE_MODEL (dialog->store), &iter_b)) gtk_list_store_swap (dialog->store, &iter_a, &iter_b); + + /* keep new position */ + gtk_tree_path_next (path); } else { /* get the previous item in the list */ - path = gtk_tree_model_get_path (GTK_TREE_MODEL (dialog->store), &iter_a); if (gtk_tree_path_prev (path)) { /* swap the items in the list */ gtk_tree_model_get_iter (GTK_TREE_MODEL (dialog->store), &iter_b, path); gtk_list_store_swap (dialog->store, &iter_a, &iter_b); } - - gtk_tree_path_free (path); } /* fake update the selection */ @@ -1071,6 +1072,12 @@ panel_preferences_dialog_item_move (GtkWidget *button, panel_return_if_fail (GTK_IS_WIDGET (treeview)); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); panel_preferences_dialog_item_selection_changed (selection, dialog); + + /* make the new selected position visible if moved out of area */ + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (treeview), path, NULL, FALSE, 0, 0); + gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview), path, NULL, FALSE); + + gtk_tree_path_free (path); } } } -- 1.8.3.1