Compare commits

..

No commits in common. "9feb53a792b49ec3547d4678d18e7af23c2f064f" and "92c6ca6c357d0ba6b39760b7706f07ff15c6610b" have entirely different histories.

View File

@ -109,7 +109,7 @@ struct {
GPtrArray *files;
gint files_index;
gchar *path;
gchar *basename;
GtkWidget *window;
GtkWidget *stack;
@ -174,40 +174,11 @@ switch_to_view(const char *path)
gtk_widget_grab_focus(g.view);
}
static gint
files_compare(gconstpointer a, gconstpointer b)
{
gchar *path1 = g_canonicalize_filename(*(gchar **) a, g.directory);
gchar *path2 = g_canonicalize_filename(*(gchar **) b, g.directory);
GFile *location1 = g_file_new_for_path(path1);
GFile *location2 = g_file_new_for_path(path2);
g_free(path1);
g_free(path2);
gint result = fiv_io_filecmp(location1, location2);
g_object_unref(location1);
g_object_unref(location2);
return result;
}
static void
update_files_index(void)
{
g.files_index = -1;
// FIXME: We presume that this basename is from the same directory.
gchar *basename = g.path ? g_path_get_basename(g.path) : NULL;
for (guint i = 0; i < g.files->len; i++) {
if (!g_strcmp0(basename, g_ptr_array_index(g.files, i)))
g.files_index = i;
}
g_free(basename);
}
static void
load_directory(const gchar *dirname)
{
if (dirname) {
g_free(g.directory);
free(g.directory);
g.directory = g_strdup(dirname);
GtkAdjustment *vadjustment = gtk_scrolled_window_get_vadjustment(
@ -233,13 +204,16 @@ load_directory(const gchar *dirname)
char *absolute = g_canonicalize_filename(name, g.directory);
gboolean is_dir = g_file_test(absolute, G_FILE_TEST_IS_DIR);
g_free(absolute);
if (!is_dir && is_supported(name))
g_ptr_array_add(g.files, g_strdup(name));
if (is_dir || !is_supported(name))
continue;
// XXX: We presume that this basename is from the same directory.
if (!g_strcmp0(g.basename, name))
g.files_index = g.files->len;
g_ptr_array_add(g.files, g_strdup(name));
}
g_dir_close(dir);
g_ptr_array_sort(g.files, files_compare);
update_files_index();
} else {
show_error_dialog(error);
}
@ -280,16 +254,22 @@ open(const gchar *path)
g_free(uri);
}
g_free(g.path);
g.path = g_strdup(path);
gchar *basename = g_path_get_basename(path);
g_free(g.basename);
g.basename = basename;
// So that load_directory() itself can be used for reloading.
gchar *dirname = g_path_get_dirname(path);
if (!g.files->len /* hack to always load the directory after launch */ ||
!g.directory || strcmp(dirname, g.directory))
!g.directory || strcmp(dirname, g.directory)) {
load_directory(dirname);
else
update_files_index();
} else {
g.files_index = -1;
for (guint i = 0; i + 1 < g.files->len; i++) {
if (!g_strcmp0(g.basename, g_ptr_array_index(g.files, i)))
g.files_index = i;
}
}
g_free(dirname);
switch_to_view(path);
@ -608,7 +588,8 @@ on_button_press_browser(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event)
return FALSE;
switch (event->button) {
case 9: // forward
switch_to_view(g.path);
// FIXME: This is inconsistent, normally there is an absolute path.
switch_to_view(g.basename);
return TRUE;
default:
return FALSE;