filechooserwidget: Load recent files synchronously
authorTimm Bäder <mail@baedert.org>
Fri, 30 Aug 2019 05:07:48 +0000 (07:07 +0200)
committerTimm Bäder <mail@baedert.org>
Mon, 9 Sep 2019 15:36:26 +0000 (17:36 +0200)
Delaying this by one frame by putting it in an idle just makes the code
more complex for no gain. The actual slow part is reading the
recently-used.xbel, which happens when creating the recent manager.

gtk/gtkfilechooserwidget.c

index dfbd360d434c47f307a28ad9b9ec2bc2039a8992..d136782059a47c2cc8e4a7433cf58a2bab8a0565 100644 (file)
@@ -295,7 +295,6 @@ struct _GtkFileChooserWidgetPrivate {
   /* OPERATION_MODE_RECENT */
   GtkRecentManager *recent_manager;
   GtkFileSystemModel *recent_model;
-  guint load_recent_id;
 
   GtkWidget *extra_and_filters;
   GtkWidget *filter_combo_hbox;
@@ -614,7 +613,6 @@ static void     show_filters                 (GtkFileChooserWidget *impl,
 
 static gboolean recent_files_setting_is_enabled (GtkFileChooserWidget *impl);
 static void     recent_start_loading         (GtkFileChooserWidget *impl);
-static void     recent_stop_loading          (GtkFileChooserWidget *impl);
 static void     recent_clear_model           (GtkFileChooserWidget *impl,
                                               gboolean               remove_from_treeview);
 static gboolean recent_should_respond        (GtkFileChooserWidget *impl);
@@ -3136,7 +3134,6 @@ operation_mode_set_other_locations (GtkFileChooserWidget *impl)
   gtk_revealer_set_reveal_child (GTK_REVEALER (priv->browse_header_revealer), FALSE);
   location_bar_update (impl);
   stop_loading_and_clear_list_model (impl, TRUE);
-  recent_stop_loading (impl);
   search_stop_searching (impl, TRUE);
   recent_clear_model (impl, TRUE);
   search_clear_model (impl, TRUE);
@@ -3506,7 +3503,6 @@ cancel_all_operations (GtkFileChooserWidget *impl)
   g_clear_pointer (&priv->file_exists_get_info_cancellable, g_cancellable_cancel);
 
   search_stop_searching (impl, TRUE);
-  recent_stop_loading (impl);
 }
 
 /* Removes the settings signal handler.  It's safe to call multiple times */
@@ -7307,7 +7303,6 @@ search_start_query (GtkFileChooserWidget *impl,
     return;
 
   stop_loading_and_clear_list_model (impl, TRUE);
-  recent_stop_loading (impl);
   recent_clear_model (impl, TRUE);
 
   search_stop_searching (impl, FALSE);
@@ -7439,21 +7434,6 @@ recent_clear_model (GtkFileChooserWidget *impl,
   g_set_object (&priv->recent_model, NULL);
 }
 
-/* Stops any ongoing loading of the recent files list; does
- * not touch the recent_model
- */
-static void
-recent_stop_loading (GtkFileChooserWidget *impl)
-{
-  GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
-
-  if (priv->load_recent_id)
-    {
-      g_source_remove (priv->load_recent_id);
-      priv->load_recent_id = 0;
-    }
-}
-
 static void
 recent_setup_model (GtkFileChooserWidget *impl)
 {
@@ -7474,38 +7454,6 @@ recent_setup_model (GtkFileChooserWidget *impl)
                                         GTK_SORT_DESCENDING);
 }
 
-typedef struct
-{
-  GtkFileChooserWidget *impl;
-  GList *items;
-} RecentLoadData;
-
-static void
-recent_idle_cleanup (gpointer data)
-{
-  RecentLoadData *load_data = data;
-  GtkFileChooserWidget *impl = load_data->impl;
-  GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
-
-  gtk_tree_view_set_model (GTK_TREE_VIEW (priv->browse_files_tree_view),
-                           GTK_TREE_MODEL (priv->recent_model));
-  gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->browse_files_tree_view), -1);
-
-  gtk_tree_view_column_set_sort_column_id (priv->list_name_column, -1);
-  gtk_tree_view_column_set_sort_column_id (priv->list_time_column, -1);
-  gtk_tree_view_column_set_sort_column_id (priv->list_size_column, -1);
-  gtk_tree_view_column_set_sort_column_id (priv->list_type_column, -1);
-  gtk_tree_view_column_set_sort_column_id (priv->list_location_column, -1);
-
-  update_columns (impl, TRUE, _("Accessed"));
-
-  set_busy_cursor (impl, FALSE);
-
-  priv->load_recent_id = 0;
-
-  g_free (load_data);
-}
-
 static gboolean
 recent_item_is_private (GtkRecentInfo *info)
 {
@@ -7579,54 +7527,40 @@ populate_model_with_folders (GtkFileChooserWidget *impl,
   g_list_free_full (folders, g_object_unref);
 }
 
-static gboolean
-recent_idle_load (gpointer data)
+static void
+recent_start_loading (GtkFileChooserWidget *impl)
 {
-  RecentLoadData *load_data = data;
-  GtkFileChooserWidget *impl = load_data->impl;
   GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
+  GList *items;
+
+  recent_clear_model (impl, TRUE);
+  recent_setup_model (impl);
 
   if (!priv->recent_manager)
-    return FALSE;
+    return;
 
-  load_data->items = gtk_recent_manager_get_items (priv->recent_manager);
-  if (!load_data->items)
-    return FALSE;
+  items = gtk_recent_manager_get_items (priv->recent_manager);
+  if (!items)
+    return;
 
   if (priv->action == GTK_FILE_CHOOSER_ACTION_OPEN)
-    populate_model_with_recent_items (impl, load_data->items);
+    populate_model_with_recent_items (impl, items);
   else
-    populate_model_with_folders (impl, load_data->items);
-
-  g_list_free_full (load_data->items, (GDestroyNotify) gtk_recent_info_unref);
-  load_data->items = NULL;
+    populate_model_with_folders (impl, items);
 
-  return FALSE;
-}
+  g_list_free_full (items, (GDestroyNotify) gtk_recent_info_unref);
 
-static void
-recent_start_loading (GtkFileChooserWidget *impl)
-{
-  GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
-  RecentLoadData *load_data;
-
-  recent_stop_loading (impl);
-  recent_clear_model (impl, TRUE);
-  recent_setup_model (impl);
-  set_busy_cursor (impl, TRUE);
-
-  g_assert (priv->load_recent_id == 0);
+  gtk_tree_view_set_model (GTK_TREE_VIEW (priv->browse_files_tree_view),
+                           GTK_TREE_MODEL (priv->recent_model));
+  gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->browse_files_tree_view), -1);
 
-  load_data = g_new (RecentLoadData, 1);
-  load_data->impl = impl;
-  load_data->items = NULL;
+  gtk_tree_view_column_set_sort_column_id (priv->list_name_column, -1);
+  gtk_tree_view_column_set_sort_column_id (priv->list_time_column, -1);
+  gtk_tree_view_column_set_sort_column_id (priv->list_size_column, -1);
+  gtk_tree_view_column_set_sort_column_id (priv->list_type_column, -1);
+  gtk_tree_view_column_set_sort_column_id (priv->list_location_column, -1);
 
-  /* begin lazy loading the recent files into the model */
-  priv->load_recent_id = g_idle_add_full (G_PRIORITY_DEFAULT,
-                                          recent_idle_load,
-                                          load_data,
-                                          recent_idle_cleanup);
-  g_source_set_name_by_id (priv->load_recent_id, "[gtk] recent_idle_load");
+  update_columns (impl, TRUE, _("Accessed"));
 }
 
 /* Called from ::should_respond(). We return whether there are selected