Make the switch-to-browser button select last file

Before, it was only possible to achieve the same result using keyboard.
This commit is contained in:
Přemysl Eric Janouch 2022-07-26 00:30:34 +02:00
parent 78636fdc18
commit 6baf1a7bbd
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 13 additions and 5 deletions

18
fiv.c
View File

@ -602,13 +602,22 @@ set_window_title(const char *uri)
} }
static void static void
switch_to_browser(void) switch_to_browser_noselect(void)
{ {
set_window_title(g.directory); set_window_title(g.directory);
gtk_stack_set_visible_child(GTK_STACK(g.stack), g.browser_paned); gtk_stack_set_visible_child(GTK_STACK(g.stack), g.browser_paned);
gtk_widget_grab_focus(g.browser); gtk_widget_grab_focus(g.browser);
} }
static void
switch_to_browser(void)
{
// XXX: This distinction is weird, it might make sense to make
// an end-user option for the behaviour.
switch_to_browser_noselect();
fiv_browser_select(FIV_BROWSER(g.browser), g.uri);
}
static void static void
switch_to_view(void) switch_to_view(void)
{ {
@ -710,7 +719,7 @@ load_directory(const char *uri)
// kept at -1, and browsing doesn't work. How to behave here? // kept at -1, and browsing doesn't work. How to behave here?
// Should we add it to the pointer array as an exception? // Should we add it to the pointer array as an exception?
if (uri) { if (uri) {
switch_to_browser(); switch_to_browser_noselect();
// TODO(p): Rather place it in history. // TODO(p): Rather place it in history.
g_clear_pointer(&g.uri, g_free); g_clear_pointer(&g.uri, g_free);
@ -1161,7 +1170,7 @@ on_key_press(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event,
switch (event->keyval) { switch (event->keyval) {
case GDK_KEY_Left: case GDK_KEY_Left:
if (gtk_stack_get_visible_child(GTK_STACK(g.stack)) == g.view_box) if (gtk_stack_get_visible_child(GTK_STACK(g.stack)) == g.view_box)
switch_to_browser(); switch_to_browser_noselect();
else if (g.directory_back) else if (g.directory_back)
load_directory(g.directory_back->data); load_directory(g.directory_back->data);
return TRUE; return TRUE;
@ -1252,7 +1261,6 @@ on_key_press_view(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event,
case GDK_KEY_Escape: case GDK_KEY_Escape:
case GDK_KEY_Return: case GDK_KEY_Return:
switch_to_browser(); switch_to_browser();
fiv_browser_select(FIV_BROWSER(g.browser), g.uri);
return TRUE; return TRUE;
} }
} }
@ -1315,7 +1323,7 @@ on_button_press_view(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event)
switch (event->button) { switch (event->button) {
case 4: // back (GdkWin32, GdkQuartz) case 4: // back (GdkWin32, GdkQuartz)
case 8: // back case 8: // back
switch_to_browser(); switch_to_browser_noselect();
return TRUE; return TRUE;
case GDK_BUTTON_PRIMARY: case GDK_BUTTON_PRIMARY:
if (event->type == GDK_2BUTTON_PRESS) { if (event->type == GDK_2BUTTON_PRESS) {