[gnome-text-editor] session: try to reuse visited time from bookmark
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] session: try to reuse visited time from bookmark
- Date: Thu, 21 Oct 2021 19:32:26 +0000 (UTC)
commit 2a67611c299bfd5dada73ef52db1824a54e651a7
Author: Christian Hergert <chergert redhat com>
Date: Thu Oct 21 12:32:21 2021 -0700
session: try to reuse visited time from bookmark
This attempts to use the time from the bookmark so that we don't have to
use the mtime from the underlying file (in most cases).
I don't love that we are using data on the GFile, but it works easy
enough without having to plumb an intermediate structure for the pair.
Addresses comments in #181
src/editor-session.c | 11 +++++++++++
src/editor-sidebar-item.c | 26 ++++++++++++++++----------
src/editor-sidebar-model.c | 13 ++++++++-----
3 files changed, 35 insertions(+), 15 deletions(-)
---
diff --git a/src/editor-session.c b/src/editor-session.c
index 988008d..6b3caf3 100644
--- a/src/editor-session.c
+++ b/src/editor-session.c
@@ -1833,10 +1833,12 @@ editor_session_load_recent_worker (GTask *task,
files = g_ptr_array_new_with_free_func (g_object_unref);
uris = g_bookmark_file_get_uris (bookmarks, &len);
+
for (gsize i = 0; i < len; i++)
{
const gchar *uri = uris[i];
g_autoptr(GFile) file = g_file_new_for_uri (uri);
+ GDateTime *age = g_bookmark_file_get_visited_date_time (bookmarks, uri, NULL);
if (g_file_is_native (file))
{
@@ -1848,6 +1850,15 @@ editor_session_load_recent_worker (GTask *task,
}
}
+ /* Track the age on the GFile without having to create a
+ * new intermediate structure.
+ */
+ if (age != NULL)
+ g_object_set_data_full (G_OBJECT (file),
+ "AGE",
+ g_date_time_ref (age),
+ (GDestroyNotify)g_date_time_unref);
+
g_ptr_array_add (files, g_steal_pointer (&file));
}
diff --git a/src/editor-sidebar-item.c b/src/editor-sidebar-item.c
index df999ac..1726d4a 100644
--- a/src/editor-sidebar-item.c
+++ b/src/editor-sidebar-item.c
@@ -120,16 +120,22 @@ editor_sidebar_item_set_file (EditorSidebarItem *self,
if (g_set_object (&self->file, file))
{
editor_sidebar_item_do_notify (self);
- if (!file || !g_file_is_native (file))
- return;
-
- g_file_query_info_async (file,
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
- G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_LOW + 100,
- NULL,
- editor_sidebar_item_query_info_cb,
- g_object_ref (self));
+
+ if (file != NULL && g_file_is_native (file))
+ {
+ GDateTime *age = g_object_get_data (G_OBJECT (file), "AGE");
+
+ if (age != NULL)
+ self->age = g_date_time_to_unix (age);
+ else
+ g_file_query_info_async (file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_LOW + 100,
+ NULL,
+ editor_sidebar_item_query_info_cb,
+ g_object_ref (self));
+ }
}
}
diff --git a/src/editor-sidebar-model.c b/src/editor-sidebar-model.c
index 5edcb9c..bdc285e 100644
--- a/src/editor-sidebar-model.c
+++ b/src/editor-sidebar-model.c
@@ -338,18 +338,21 @@ editor_sidebar_model_load_recent_cb (GObject *object,
if (!find_by_file (self, file))
{
+ g_autoptr(GDateTime) age = NULL;
EditorSidebarItem *item;
GSequenceIter *iter;
guint position;
item = _editor_sidebar_item_new (file, NULL);
+ age = _editor_sidebar_item_get_age (item);
/* We need to update the position after we have an age */
- g_signal_connect_object (item,
- "notify::age",
- G_CALLBACK (on_notify_age_cb),
- self,
- G_CONNECT_SWAPPED);
+ if (age == NULL)
+ g_signal_connect_object (item,
+ "notify::age",
+ G_CALLBACK (on_notify_age_cb),
+ self,
+ G_CONNECT_SWAPPED);
iter = g_sequence_insert_sorted (self->seq,
item,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]