Compare commits
2 Commits
92c6ca6c35
...
9feb53a792
Author | SHA1 | Date | |
---|---|---|---|
9feb53a792 | |||
4427da5343 |
65
fastiv.c
65
fastiv.c
@ -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;
|
||||||
@ -174,11 +174,40 @@ switch_to_view(const char *path)
|
|||||||
gtk_widget_grab_focus(g.view);
|
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
|
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(
|
||||||
@ -204,16 +233,13 @@ load_directory(const gchar *dirname)
|
|||||||
char *absolute = g_canonicalize_filename(name, g.directory);
|
char *absolute = g_canonicalize_filename(name, g.directory);
|
||||||
gboolean is_dir = g_file_test(absolute, G_FILE_TEST_IS_DIR);
|
gboolean is_dir = g_file_test(absolute, G_FILE_TEST_IS_DIR);
|
||||||
g_free(absolute);
|
g_free(absolute);
|
||||||
if (is_dir || !is_supported(name))
|
if (!is_dir && is_supported(name))
|
||||||
continue;
|
g_ptr_array_add(g.files, g_strdup(name));
|
||||||
|
|
||||||
// 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_dir_close(dir);
|
||||||
|
|
||||||
|
g_ptr_array_sort(g.files, files_compare);
|
||||||
|
update_files_index();
|
||||||
} else {
|
} else {
|
||||||
show_error_dialog(error);
|
show_error_dialog(error);
|
||||||
}
|
}
|
||||||
@ -254,22 +280,16 @@ 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);
|
||||||
if (!g.files->len /* hack to always load the directory after launch */ ||
|
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);
|
load_directory(dirname);
|
||||||
} else {
|
else
|
||||||
g.files_index = -1;
|
update_files_index();
|
||||||
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);
|
g_free(dirname);
|
||||||
|
|
||||||
switch_to_view(path);
|
switch_to_view(path);
|
||||||
@ -588,8 +608,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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user