[gthumb] grid view: update the selection after inserting or deleting a row
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] grid view: update the selection after inserting or deleting a row
- Date: Mon, 5 Dec 2011 19:59:37 +0000 (UTC)
commit fe6cc08f1fcc719c9d63c978cf5063018f94f552
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Dec 5 11:35:51 2011 +0100
grid view: update the selection after inserting or deleting a row
gthumb/gth-grid-view.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/gthumb/gth-grid-view.c b/gthumb/gth-grid-view.c
index f28d582..286fd11 100644
--- a/gthumb/gth-grid-view.c
+++ b/gthumb/gth-grid-view.c
@@ -371,6 +371,9 @@ _gth_grid_view_free_items (GthGridView *self)
g_list_foreach (self->priv->items, (GFunc) gth_grid_view_item_unref, NULL);
g_list_free (self->priv->items);
self->priv->items = NULL;
+
+ g_list_free (self->priv->selection);
+ self->priv->selection = NULL;
}
@@ -1956,12 +1959,31 @@ model_row_deleted_cb (GtkTreeModel *tree_model,
GthGridView *self = user_data;
int pos;
GList *link;
+ GList *scan;
+ GList *selected_link;
pos = gtk_tree_path_get_indices (path)[0];
link = g_list_nth (self->priv->items, pos);
self->priv->items = g_list_remove_link (self->priv->items, link);
self->priv->n_items--;
+ /* update the selection */
+
+ selected_link = NULL;
+ for (scan = self->priv->selection; scan; scan = scan->next) {
+ int selected_pos = GPOINTER_TO_INT (scan->data);
+ if (selected_pos > pos)
+ scan->data = GINT_TO_POINTER (selected_pos - 1);
+ else if (selected_pos == pos)
+ selected_link = scan;
+ }
+ if (selected_link != NULL) {
+ self->priv->selection = g_list_remove_link (self->priv->selection, selected_link);
+ g_list_free (selected_link);
+ }
+
+ /* relayout from the minimum changed position */
+
_gth_grid_view_keep_focus_consistent (self);
_gth_grid_view_queue_relayout_from_position (self, pos);
@@ -1982,6 +2004,7 @@ model_row_inserted_cb (GtkTreeModel *tree_model,
gboolean is_icon;
GthGridViewItem *item;
int pos;
+ GList *scan;
gtk_tree_model_get (tree_model,
iter,
@@ -1998,6 +2021,16 @@ model_row_inserted_cb (GtkTreeModel *tree_model,
self->priv->items = g_list_insert (self->priv->items, item, pos);
self->priv->n_items++;
+ /* update the selection */
+
+ for (scan = self->priv->selection; scan; scan = scan->next) {
+ int selected_pos = GPOINTER_TO_INT (scan->data);
+ if (selected_pos >= pos)
+ scan->data = GINT_TO_POINTER (selected_pos + 1);
+ }
+
+ /* relayout from the minimum changed position */
+
_gth_grid_view_queue_relayout_from_position (self, pos);
g_object_unref (file_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]