This commit is contained in:
Přemysl Eric Janouch 2023-04-16 09:21:34 +02:00
parent 00fa76cb69
commit 43363ea4bf
Signed by: p
GPG Key ID: A0420B94F92B9493

51
fiv.c
View File

@ -700,7 +700,7 @@ update_files_index(void)
} }
static void static void
load_directory_without_reload(const char *uri) change_directory_without_reload(const char *uri)
{ {
gchar *uri_duplicated = g_strdup(uri); gchar *uri_duplicated = g_strdup(uri);
if (g.directory_back && !strcmp(uri, g.directory_back->data)) { if (g.directory_back && !strcmp(uri, g.directory_back->data)) {
@ -742,7 +742,7 @@ static void
load_directory_without_switching(const char *uri) load_directory_without_switching(const char *uri)
{ {
if (uri) { if (uri) {
load_directory_without_reload(uri); change_directory_without_reload(uri);
GtkAdjustment *vadjustment = gtk_scrolled_window_get_vadjustment( GtkAdjustment *vadjustment = gtk_scrolled_window_get_vadjustment(
GTK_SCROLLED_WINDOW(g.browser_scroller)); GTK_SCROLLED_WINDOW(g.browser_scroller));
@ -768,9 +768,6 @@ load_directory(const char *uri)
{ {
load_directory_without_switching(uri); load_directory_without_switching(uri);
// XXX: When something outside the filtered entries is open, the index is
// kept at -1, and browsing doesn't work. How to behave here?
// Should we add it to the pointer array as an exception?
if (uri) { if (uri) {
switch_to_browser_noselect(); switch_to_browser_noselect();
@ -779,6 +776,26 @@ load_directory(const char *uri)
} }
} }
static void
go_back(void)
{
if (gtk_stack_get_visible_child(GTK_STACK(g.stack)) == g.view_box) {
switch_to_browser_noselect();
} else if (g.directory_back) {
load_directory(g.directory_back->data);
}
}
static void
go_forward(void)
{
if (g.directory_forward) {
load_directory(g.directory_forward->data);
} else if (g.uri) {
switch_to_view();
}
}
static void static void
on_model_files_changed(FivIoModel *model, G_GNUC_UNUSED gpointer user_data) on_model_files_changed(FivIoModel *model, G_GNUC_UNUSED gpointer user_data)
{ {
@ -877,6 +894,10 @@ open_image(const char *uri)
update_files_index(); update_files_index();
g_free(parent); g_free(parent);
// XXX: When something outside currently filtered entries is open,
// g.files_index is kept at -1, and browsing doesn't work.
// How to behave here?
switch_to_view(); switch_to_view();
} }
@ -1399,16 +1420,10 @@ on_key_press(G_GNUC_UNUSED GtkWidget *widget, GdkEventKey *event,
case GDK_MOD1_MASK: case GDK_MOD1_MASK:
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) go_back();
switch_to_browser_noselect();
else if (g.directory_back)
load_directory(g.directory_back->data);
return TRUE; return TRUE;
case GDK_KEY_Right: case GDK_KEY_Right:
if (g.directory_forward) go_forward();
load_directory(g.directory_forward->data);
else if (g.uri)
switch_to_view();
return TRUE; return TRUE;
} }
break; break;
@ -1570,7 +1585,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_noselect(); go_back();
return TRUE; return TRUE;
case GDK_BUTTON_PRIMARY: case GDK_BUTTON_PRIMARY:
if (event->type == GDK_2BUTTON_PRESS) { if (event->type == GDK_2BUTTON_PRESS) {
@ -1592,15 +1607,11 @@ on_button_press_browser_paned(
switch (event->button) { switch (event->button) {
case 4: // back (GdkWin32, GdkQuartz) case 4: // back (GdkWin32, GdkQuartz)
case 8: // back case 8: // back
if (g.directory_back) go_back();
load_directory(g.directory_back->data);
return TRUE; return TRUE;
case 5: // forward (GdkWin32, GdkQuartz) case 5: // forward (GdkWin32, GdkQuartz)
case 9: // forward case 9: // forward
if (g.directory_forward) go_forward();
load_directory(g.directory_forward->data);
else if (g.uri)
switch_to_view();
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;