[nautilus/wip/antoniof/use-cached-templates-menu-model: 5/7] files-view: Only refresh New Document menu if needed




commit 4a44f3d922095717e3ee357094d22128dc0badea
Author: António Fernandes <antoniof gnome org>
Date:   Mon Dec 21 23:29:30 2020 +0000

    files-view: Only refresh New Document menu if needed
    
    Menus are updated very frequently. Each time, we read the Templates
    directory tree and recreate a menu model from which we generate the
    New Document menu that's shared between the background context menu
    and the current location menu in the pathbar.
    
    This is wasteful and may cause noticeable UI lag if the Templates
    directory has got a lot of files and subdirectories.
    
    We already have a file monitor in place which notifies us when the
    content of the Templates directory actually changes, so we can rely
    on it to know when we need to read the directory again, and, in the
    remaining situations, we can use the cached menu model.
    
    Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/1069
    Relates to https://gitlab.gnome.org/GNOME/nautilus/-/issues/1705

 src/nautilus-files-view.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index 8f7c1586b..afadd42ae 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -183,6 +183,7 @@ typedef struct
 
     GList *scripts_directory_list;
     GList *templates_directory_list;
+    gboolean templates_menu_updated;
 
     guint display_selection_idle_id;
     guint update_context_menus_timeout_id;
@@ -3048,6 +3049,7 @@ templates_added_or_changed_callback (NautilusDirectory *directory,
     view = NAUTILUS_FILES_VIEW (callback_data);
     priv = nautilus_files_view_get_instance_private (view);
 
+    priv->templates_menu_updated = FALSE;
     if (priv->active)
     {
         schedule_update_context_menus (view);
@@ -5917,12 +5919,6 @@ update_templates_menu (NautilusFilesView *view,
 
     directory = nautilus_directory_get_by_uri (templates_directory_uri);
     submenu = update_directory_in_templates_menu (view, directory);
-    if (submenu != NULL)
-    {
-        GObject *object;
-        object = gtk_builder_get_object (builder, "templates-submenu");
-        nautilus_gmenu_set_from_model (G_MENU (object), submenu);
-    }
 
     nautilus_view_set_templates_menu (NAUTILUS_VIEW (view), submenu);
 
@@ -8310,11 +8306,21 @@ static void
 update_background_menu (NautilusFilesView *view,
                         GtkBuilder        *builder)
 {
+    NautilusFilesViewPrivate *priv = nautilus_files_view_get_instance_private (view);
+    GObject *object;
+
     if (nautilus_files_view_supports_creating_files (view) &&
         !showing_recent_directory (view) &&
         !showing_starred_directory (view))
     {
-        update_templates_menu (view, builder);
+        if (!priv->templates_menu_updated)
+        {
+            update_templates_menu (view, builder);
+            priv->templates_menu_updated = TRUE;
+        }
+
+        object = gtk_builder_get_object (builder, "templates-submenu");
+        nautilus_gmenu_set_from_model (G_MENU (object), priv->templates_menu);
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]