summaryrefslogtreecommitdiff
path: root/src/gridview.c
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-20 17:36:28 +0300
committerPaul Buetow <paul@buetow.org>2026-07-20 17:36:28 +0300
commit7f9dc97115bb59b62b92f58c8fb01697f15e5a10 (patch)
tree7cd49219664d7b1ba895f96fd406b81aac2c8f8c /src/gridview.c
parentf4eea795c070e5ddca183bc6ff2e4199e39a5cd1 (diff)
grid: sync flowbox selection to navigator.current on Enter/t (cu0)
Arrow-key navigation in the grid moved the GtkFlowBox selection but never updated navigator.current, so Enter (and toggling to large with t) opened the stale current image instead of the highlighted one. _on_flow_key emitted the activate signal directly without syncing, unlike the double-click path (_on_child_activated) which does sync. Add ggaze_grid_sync_current(): reads the selected flowbox child and calls navigator_set_current_file. Call it from _on_flow_key before emitting activate, and from _action_toggle_view's grid→large branch (then load the now-current image). Mirrors the existing double-click sync.
Diffstat (limited to 'src/gridview.c')
-rw-r--r--src/gridview.c27
1 files changed, 27 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));