Store the full path of the loaded image

Fixes a minor inconsistency with the window title.
This commit is contained in:
Přemysl Eric Janouch 2021-12-19 08:48:32 +01:00
parent 92c6ca6c35
commit 4427da5343
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 13 additions and 12 deletions

View File

@ -109,7 +109,7 @@ struct {
GPtrArray *files; GPtrArray *files;
gint files_index; gint files_index;
gchar *basename; gchar *path;
GtkWidget *window; GtkWidget *window;
GtkWidget *stack; GtkWidget *stack;
@ -178,7 +178,7 @@ static void
load_directory(const gchar *dirname) load_directory(const gchar *dirname)
{ {
if (dirname) { if (dirname) {
free(g.directory); g_free(g.directory);
g.directory = g_strdup(dirname); g.directory = g_strdup(dirname);
GtkAdjustment *vadjustment = gtk_scrolled_window_get_vadjustment( GtkAdjustment *vadjustment = gtk_scrolled_window_get_vadjustment(
@ -207,9 +207,11 @@ load_directory(const gchar *dirname)
if (is_dir || !is_supported(name)) if (is_dir || !is_supported(name))
continue; continue;
// XXX: We presume that this basename is from the same directory. // FIXME: We presume that this basename is from the same directory.
if (!g_strcmp0(g.basename, name)) gchar *basename = g.path ? g_path_get_basename(g.path) : NULL;
if (!g_strcmp0(basename, name))
g.files_index = g.files->len; g.files_index = g.files->len;
g_free(basename);
g_ptr_array_add(g.files, g_strdup(name)); g_ptr_array_add(g.files, g_strdup(name));
} }
@ -254,9 +256,8 @@ open(const gchar *path)
g_free(uri); g_free(uri);
} }
gchar *basename = g_path_get_basename(path); g_free(g.path);
g_free(g.basename); g.path = g_strdup(path);
g.basename = basename;
// So that load_directory() itself can be used for reloading. // So that load_directory() itself can be used for reloading.
gchar *dirname = g_path_get_dirname(path); gchar *dirname = g_path_get_dirname(path);
@ -265,10 +266,11 @@ open(const gchar *path)
load_directory(dirname); load_directory(dirname);
} else { } else {
g.files_index = -1; g.files_index = -1;
for (guint i = 0; i + 1 < g.files->len; i++) { gchar *basename = g_path_get_basename(g.path);
if (!g_strcmp0(g.basename, g_ptr_array_index(g.files, i))) for (guint i = 0; i + 1 < g.files->len; i++)
if (!g_strcmp0(basename, g_ptr_array_index(g.files, i)))
g.files_index = i; g.files_index = i;
} g_free(basename);
} }
g_free(dirname); g_free(dirname);
@ -588,8 +590,7 @@ on_button_press_browser(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event)
return FALSE; return FALSE;
switch (event->button) { switch (event->button) {
case 9: // forward case 9: // forward
// FIXME: This is inconsistent, normally there is an absolute path. switch_to_view(g.path);
switch_to_view(g.basename);
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;