[gthumb/gthumb-3-4] grid view: update the cursor position when the model changes
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb/gthumb-3-4] grid view: update the cursor position when the model changes
- Date: Mon, 3 Oct 2016 09:24:31 +0000 (UTC)
commit 9e1eaa5dc4f8181163733b733fbc707a89428a23
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Sep 11 09:54:41 2016 +0200
grid view: update the cursor position when the model changes
gthumb/gth-grid-view.c | 33 ++++++++++++++++++++-------------
1 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/gthumb/gth-grid-view.c b/gthumb/gth-grid-view.c
index 855b552..498668d 100644
--- a/gthumb/gth-grid-view.c
+++ b/gthumb/gth-grid-view.c
@@ -1797,23 +1797,11 @@ gth_grid_view_draw (GtkWidget *widget,
}
-static void
-_gth_grid_view_keep_focus_consistent (GthGridView *self)
-{
- if (self->priv->focused_item > self->priv->n_items - 1)
- self->priv->focused_item = - 1;
-}
-
-
static gboolean
gth_grid_view_focus_in (GtkWidget *widget,
GdkEventFocus *event)
{
- GthGridView *self = GTH_GRID_VIEW (widget);
-
- _gth_grid_view_keep_focus_consistent (self);
gtk_widget_queue_draw (widget);
-
return TRUE;
}
@@ -2271,9 +2259,15 @@ model_row_deleted_cb (GtkTreeModel *tree_model,
g_list_free (selected_link);
}
+ /* update the cursor position */
+
+ if (pos < self->priv->focused_item)
+ self->priv->focused_item--;
+ else if (pos == self->priv->focused_item)
+ self->priv->focused_item = -1;
+
/* relayout from the minimum changed position */
- _gth_grid_view_keep_focus_consistent (self);
_gth_grid_view_queue_relayout_from_position (self, pos);
gth_grid_view_item_unref (GTH_GRID_VIEW_ITEM (link->data));
@@ -2318,6 +2312,11 @@ model_row_inserted_cb (GtkTreeModel *tree_model,
scan->data = GINT_TO_POINTER (selected_pos + 1);
}
+ /* update the cursor position */
+
+ if (pos <= self->priv->focused_item)
+ self->priv->focused_item++;
+
/* relayout from the minimum changed position */
_gth_grid_view_queue_relayout_from_position (self, pos);
@@ -2338,6 +2337,7 @@ model_rows_reordered_cb (GtkTreeModel *tree_model,
GList *items;
int i;
int min_changed_pos;
+ gboolean focused_updated = FALSE;
GList *scan;
/* change the order of the items list */
@@ -2352,6 +2352,13 @@ model_rows_reordered_cb (GtkTreeModel *tree_model,
if ((min_changed_pos == -1) && (old_pos != i))
min_changed_pos = i;
+ /* update the cursor position */
+
+ if (! focused_updated && (old_pos == self->priv->focused_item)) {
+ self->priv->focused_item = i;
+ focused_updated = TRUE;
+ }
+
link = g_list_nth (self->priv->items, old_pos);
g_return_if_fail (link != NULL);
items = g_list_prepend (items, link->data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]