aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fiv-browser.c32
-rw-r--r--fiv-browser.h1
-rw-r--r--fiv.c5
3 files changed, 27 insertions, 11 deletions
diff --git a/fiv-browser.c b/fiv-browser.c
index 9566e10..354d3b2 100644
--- a/fiv-browser.c
+++ b/fiv-browser.c
@@ -1550,12 +1550,9 @@ on_model_files_changed(FivIoModel *model, FivBrowser *self)
{
g_return_if_fail(model == self->model);
- int selected = -1;
gchar *selected_uri = NULL;
- if (self->selected) {
+ if (self->selected)
selected_uri = g_strdup(self->selected->uri);
- self->selected = NULL;
- }
// TODO(p): Later implement arguments.
thumbnailers_abort(self);
@@ -1566,16 +1563,12 @@ on_model_files_changed(FivIoModel *model, FivBrowser *self)
for (guint i = 0; i < files->len; i++) {
g_array_append_val(self->entries,
((Entry) {.thumbnail = NULL, .uri = files->pdata[i]}));
- if (!g_strcmp0(selected_uri, files->pdata[i]))
- selected = i;
files->pdata[i] = NULL;
}
g_ptr_array_free(files, TRUE);
- // Beware that the pointer may shift with the storage.
+ fiv_browser_select(self, selected_uri);
g_free(selected_uri);
- if (selected >= 0)
- self->selected = &g_array_index(self->entries, Entry, selected);
reload_thumbnails(self);
thumbnailers_start(self);
@@ -1594,3 +1587,24 @@ fiv_browser_new(FivIoModel *model)
on_model_files_changed(self->model, self);
return GTK_WIDGET(self);
}
+
+void
+fiv_browser_select(FivBrowser *self, const char *uri)
+{
+ g_return_if_fail(FIV_IS_BROWSER(self));
+
+ self->selected = NULL;
+ gtk_widget_queue_draw(GTK_WIDGET(self));
+ if (!uri)
+ return;
+
+ for (guint i = 0; i < self->entries->len; i++) {
+ const Entry *entry = &g_array_index(self->entries, Entry, i);
+ if (!g_strcmp0(entry->uri, uri)) {
+ self->selected = entry;
+ break;
+ }
+ }
+
+ // TODO(p): Scroll to selection.
+}
diff --git a/fiv-browser.h b/fiv-browser.h
index 6a1a5c4..0a93721 100644
--- a/fiv-browser.h
+++ b/fiv-browser.h
@@ -25,3 +25,4 @@
G_DECLARE_FINAL_TYPE(FivBrowser, fiv_browser, FIV, BROWSER, GtkWidget)
GtkWidget *fiv_browser_new(FivIoModel *model);
+void fiv_browser_select(FivBrowser *self, const char *uri);
diff --git a/fiv.c b/fiv.c
index 69d6cb8..56944e3 100644
--- a/fiv.c
+++ b/fiv.c
@@ -880,11 +880,12 @@ open_any_file(GFile *file, gboolean force_browser)
} else if (type == G_FILE_TYPE_DIRECTORY) {
load_directory(uri);
} else if (force_browser) {
- // GNOME, e.g., invokes this as a hint to focus the particular file,
- // which we can't currently do yet.
+ // GNOME, e.g., invokes this as a hint to focus the particular file.
gchar *parent = parent_uri(file);
load_directory(parent);
g_free(parent);
+
+ fiv_browser_select(FIV_BROWSER(g.browser), uri);
} else {
open(uri);
}