From e9c0faba42633d62c46cbed4fc165bbe6294d698 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Thu, 25 Aug 2011 12:57:03 -0500 Subject: [PATCH 1/3] Don't sort the recent-items by hand The mtime from GtkRecentManager may not the same as the file's actual mtime, so the final result could appear unsorted to the user. Instead, we will let the view do the sorting. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index d24c3c110b..d3b95e50b6 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -9321,16 +9321,6 @@ recent_idle_cleanup (gpointer data) g_free (load_data); } -static gint -recent_sort_mru (gconstpointer a, - gconstpointer b) -{ - GtkRecentInfo *info_a = (GtkRecentInfo *) a; - GtkRecentInfo *info_b = (GtkRecentInfo *) b; - - return (gtk_recent_info_get_modified (info_b) - gtk_recent_info_get_modified (info_a)); -} - static gint get_recent_files_limit (GtkWidget *widget) { @@ -9421,8 +9411,6 @@ recent_idle_load (gpointer data) /* second iteration: MRU sorting and clamping, and populating the model */ if (load_data->needs_sorting) { - load_data->items = g_list_sort (load_data->items, recent_sort_mru); - if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN) populate_model_with_recent_items (impl, load_data->items); else From 3bd037b7d90cef249c43855077478a1ee20a116d Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 26 Aug 2011 11:38:11 -0500 Subject: [PATCH 2/3] Load and populate the recent-items in a single pass There's no real asynchronicity going on, anyway, so let's do both within a single iteration of the idle handler. Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index d3b95e50b6..ad79631a81 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -9301,7 +9301,6 @@ typedef struct { GtkFileChooserDefault *impl; GList *items; - guint needs_sorting : 1; } RecentLoadData; static void @@ -9396,30 +9395,18 @@ recent_idle_load (gpointer data) if (!impl->recent_manager) return FALSE; - /* first iteration: load all the items */ + load_data->items = gtk_recent_manager_get_items (impl->recent_manager); if (!load_data->items) - { - load_data->items = gtk_recent_manager_get_items (impl->recent_manager); - if (!load_data->items) - return FALSE; + return FALSE; - load_data->needs_sorting = TRUE; + if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN) + populate_model_with_recent_items (impl, load_data->items); + else + populate_model_with_folders (impl, load_data->items); - return TRUE; - } - - /* second iteration: MRU sorting and clamping, and populating the model */ - if (load_data->needs_sorting) - { - if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN) - populate_model_with_recent_items (impl, load_data->items); - else - populate_model_with_folders (impl, load_data->items); - - g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL); - g_list_free (load_data->items); - load_data->items = NULL; - } + g_list_foreach (load_data->items, (GFunc) gtk_recent_info_unref, NULL); + g_list_free (load_data->items); + load_data->items = NULL; return FALSE; } @@ -9439,7 +9426,6 @@ recent_start_loading (GtkFileChooserDefault *impl) load_data = g_new (RecentLoadData, 1); load_data->impl = impl; load_data->items = NULL; - load_data->needs_sorting = TRUE; /* begin lazy loading the recent files into the model */ impl->load_recent_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30, From a265fb763bf3e57ee40a60bfff098a5f29ef5fa2 Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 26 Aug 2011 12:32:00 -0500 Subject: [PATCH 3/3] bgo#657186 - Sort the recent-files list in newest-to-oldest order Otherwise it's not very useful... :) Signed-off-by: Federico Mena Quintero --- gtk/gtkfilechooserdefault.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index ad79631a81..eec27973e8 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -9312,6 +9312,7 @@ recent_idle_cleanup (gpointer data) gtk_tree_view_set_model (GTK_TREE_VIEW (impl->browse_files_tree_view), GTK_TREE_MODEL (impl->recent_model)); file_list_set_sort_column_ids (impl); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (impl->recent_model), MODEL_COL_MTIME, GTK_SORT_DESCENDING); set_busy_cursor (impl, FALSE);