summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gridview.c27
-rw-r--r--src/gridview.h4
-rw-r--r--src/window.c6
3 files changed, 37 insertions, 0 deletions
diff --git a/src/gridview.c b/src/gridview.c
index 56267b3..c57eeac 100644
--- a/src/gridview.c
+++ b/src/gridview.c
@@ -171,6 +171,9 @@ _on_flow_key(GtkEventControllerKey *p_key, guint u_kv, guint u_kc,
(void)e_st;
GgazeGrid *p_grid = GGAZE_GRID(p_data);
if (u_kv == GDK_KEY_Return || u_kv == GDK_KEY_KP_Enter) {
+ /* Sync navigator.current to the highlighted cell before activating, so
+ * Enter opens the arrow-selected image, not a stale current. */
+ ggaze_grid_sync_current(p_grid);
g_signal_emit(p_grid, u_activate_signal, 0);
return (TRUE);
}
@@ -213,6 +216,30 @@ _select_current(GgazeGrid *p_grid) {
}
}
+/* Sync navigator.current to the flowbox's currently-selected child, so that
+ * leaving the grid (Enter or toggle-to-large) opens the highlighted cell,
+ * not a stale current left over from when the grid was entered. Mirrors the
+ * sync _on_child_activated does for a double-click. Returns TRUE if a
+ * selection was found and current was (or already was) that file. */
+gboolean
+ggaze_grid_sync_current(GgazeGrid *p_grid) {
+ g_return_val_if_fail(GGAZE_IS_GRID(p_grid), FALSE);
+ if (p_grid->p_nav == NULL) {
+ return (FALSE);
+ }
+ GList *p_sel =
+ gtk_flow_box_get_selected_children(GTK_FLOW_BOX(p_grid->p_flow));
+ if (p_sel == NULL) {
+ return (FALSE);
+ }
+ GFile *p_file = (GFile *)g_object_get_data(G_OBJECT(p_sel->data), "file");
+ g_list_free(p_sel);
+ if (p_file == NULL) {
+ return (FALSE);
+ }
+ return (navigator_set_current_file(p_grid->p_nav, p_file));
+}
+
void
ggaze_grid_refresh(GgazeGrid *p_grid) {
g_return_if_fail(GGAZE_IS_GRID(p_grid));
diff --git a/src/gridview.h b/src/gridview.h
index 582ada8..f6a4ad2 100644
--- a/src/gridview.h
+++ b/src/gridview.h
@@ -34,6 +34,10 @@ void ggaze_grid_set_hide_trashed(GgazeGrid *p_grid, gboolean b_hide);
/* Rebuild the cells from the navigator (call after structural changes). */
void ggaze_grid_refresh(GgazeGrid *p_grid);
+/* Sync navigator.current to the flowbox's currently-selected cell, so leaving
+ * the grid (Enter / toggle-to-large) opens the highlighted image. */
+gboolean ggaze_grid_sync_current(GgazeGrid *p_grid);
+
/* Number of cells currently in the grid. */
guint ggaze_grid_get_count(GgazeGrid *p_grid);
diff --git a/src/window.c b/src/window.c
index 688f879..d978be3 100644
--- a/src/window.c
+++ b/src/window.c
@@ -243,7 +243,13 @@ _action_toggle_view(GSimpleAction *p_a, GVariant *p_v, gpointer p_data) {
if (g_strcmp0(c_cur, "large") == 0) {
gtk_stack_set_visible_child_name(GTK_STACK(p_win->p_stack), "grid");
} else {
+ /* Leaving the grid: sync navigator.current to the highlighted cell so
+ * the large view opens the selected image, then load it. */
+ if (p_win->p_grid != NULL) {
+ ggaze_grid_sync_current(p_win->p_grid);
+ }
gtk_stack_set_visible_child_name(GTK_STACK(p_win->p_stack), "large");
+ _load_current(p_win);
}
}