[nautilus/wip/antoniof/use-cached-templates-menu-model: 2/2] files-view: Clean up update_templates_menu()




commit 1ed9ae0c57827daeaf35f7403b5cc285b1bf7aca
Author: António Fernandes <antoniof gnome org>
Date:   Tue Oct 26 11:43:01 2021 +0100

    files-view: Clean up update_templates_menu()
    
    Use autocleanup. Remove empty line. Rearrange early return.

 src/nautilus-files-view.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)
---
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index c2b320dc7..778418082 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -5883,51 +5883,38 @@ update_templates_menu (NautilusFilesView *view,
                        GtkBuilder        *builder)
 {
     NautilusFilesViewPrivate *priv;
-    GList *sorted_copy, *node;
-    NautilusDirectory *directory;
+    g_autolist (NautilusDirectory) sorted_copy = NULL;
+    g_autoptr (NautilusDirectory) directory = NULL;
     g_autoptr (GMenuModel) submenu = NULL;
-    char *uri;
-    char *templates_directory_uri;
+    g_autofree char *uri = NULL;
+    g_autofree char *templates_directory_uri = NULL;
 
     priv = nautilus_files_view_get_instance_private (view);
 
-    if (nautilus_should_use_templates_directory ())
-    {
-        templates_directory_uri = nautilus_get_templates_directory_uri ();
-    }
-    else
+    if (!nautilus_should_use_templates_directory ())
     {
         priv->templates_present = FALSE;
         return;
     }
 
-
+    templates_directory_uri = nautilus_get_templates_directory_uri ();
     sorted_copy = nautilus_directory_list_sort_by_uri
                       (nautilus_directory_list_copy (priv->templates_directory_list));
 
-    for (node = sorted_copy; node != NULL; node = node->next)
+    for (GList *node = sorted_copy; node != NULL; node = node->next)
     {
-        directory = node->data;
-
-        uri = nautilus_directory_get_uri (directory);
+        uri = nautilus_directory_get_uri (node->data);
         if (!directory_belongs_in_templates_menu (templates_directory_uri, uri))
         {
-            remove_directory_from_templates_directory_list (view, directory);
+            remove_directory_from_templates_directory_list (view, node->data);
         }
-        g_free (uri);
     }
-    nautilus_directory_list_free (sorted_copy);
 
     directory = nautilus_directory_get_by_uri (templates_directory_uri);
     submenu = update_directory_in_templates_menu (view, directory);
 
     nautilus_view_set_templates_menu (NAUTILUS_VIEW (view), submenu);
-
-    nautilus_directory_unref (directory);
-
     priv->templates_present = submenu != NULL;
-
-    g_free (templates_directory_uri);
 }
 
 


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