[nautilus] sidebar: Restore "Properties" menu item



commit 50d23558947b0bf755555d67b7698e95c6ffe345
Author: Corey Berla <corey berla me>
Date:   Mon Apr 4 11:40:04 2022 -0700

    sidebar: Restore "Properties" menu item
    
    With the changes for GTK4, the sidebar items no longer have
    support for populating the context menus with additional items.
    
    Add a Properties action directly in the sidebar, by moving and
    adapting code from NautilusWindow.

 src/gtk/nautilusgtkplacessidebar.c | 44 ++++++++++++++++++++++++++++++++++++++
 src/nautilus-window.c              | 35 ------------------------------
 2 files changed, 44 insertions(+), 35 deletions(-)
---
diff --git a/src/gtk/nautilusgtkplacessidebar.c b/src/gtk/nautilusgtkplacessidebar.c
index 9328f6cac..f258f9076 100644
--- a/src/gtk/nautilusgtkplacessidebar.c
+++ b/src/gtk/nautilusgtkplacessidebar.c
@@ -35,6 +35,8 @@
 #include "nautilusgtksidebarrowprivate.h"
 #include "gdk/gdkkeysyms.h"
 #include "nautilusgtkbookmarksmanagerprivate.h"
+#include "nautilus-file.h"
+#include "nautilus-properties-window.h"
 #include "nautilus-trash-monitor.h"
 #pragma GCC diagnostic ignored "-Wshadow"
 
@@ -2413,6 +2415,24 @@ rename_shortcut_cb (GSimpleAction *action,
   rename_bookmark (sidebar->context_row);
 }
 
+static void
+properties_cb (GSimpleAction *action,
+               GVariant      *parameter,
+               gpointer       data)
+{
+  NautilusGtkPlacesSidebar *sidebar = data;
+  GList *list;
+  NautilusFile *file;
+  g_autofree gchar *uri = NULL;
+
+  g_object_get (sidebar->context_row, "uri", &uri, NULL);
+  file = nautilus_file_get_by_uri (uri);
+  list = g_list_append (NULL, file);
+  nautilus_properties_window_present (list, GTK_WIDGET (sidebar), NULL, NULL, NULL);
+
+  nautilus_file_list_free (list);
+}
+
 static void
 remove_bookmark (NautilusGtkSidebarRow *row)
 {
@@ -3083,6 +3103,7 @@ static GActionEntry entries[] = {
   { "rescan", rescan_shortcut_cb, NULL, NULL, NULL },
   { "start", start_shortcut_cb, NULL, NULL, NULL },
   { "stop", stop_shortcut_cb, NULL, NULL, NULL },
+  { "properties", properties_cb, NULL, NULL, NULL },
 };
 
 static void
@@ -3164,15 +3185,28 @@ create_row_popover (NautilusGtkPlacesSidebar *sidebar,
   GAction *action;
   gboolean show_unmount, show_eject;
   gboolean show_stop;
+  g_autofree gchar *uri = NULL;
+  g_autoptr (GFile) file = NULL;
+  gboolean show_properties;
 
   g_object_get (row,
                 "place-type", &type,
                 "drive", &drive,
                 "volume", &volume,
                 "mount", &mount,
+                "uri", &uri,
                 NULL);
 
   check_unmount_and_eject (mount, volume, drive, &show_unmount, &show_eject);
+  if (uri != NULL)
+    {
+      file = g_file_new_for_uri (uri);
+      show_properties = (g_file_is_native (file) || mount != NULL);
+    }
+  else
+    {
+      show_properties = FALSE;
+    }
 
 #ifdef HAVE_CLOUDPROVIDERS
   CloudProvidersAccount *cloud_provider_account;
@@ -3310,6 +3344,16 @@ create_row_popover (NautilusGtkPlacesSidebar *sidebar,
   g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
   g_object_unref (section);
 
+  if (show_properties) {
+    section = g_menu_new ();
+    item = g_menu_item_new (_("Properties"), "row.properties");
+    g_menu_append_item (section, item);
+    g_object_unref (item);
+
+    g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
+    g_object_unref (section);
+  }
+
   sidebar->popover = gtk_popover_menu_new_from_model (G_MENU_MODEL (menu));
   g_object_unref (menu);
   g_signal_connect (sidebar->popover, "destroy", G_CALLBACK (on_row_popover_destroy), sidebar);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index f1b0f7da6..c47a8b770 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -64,7 +64,6 @@
 #include "nautilus-notebook.h"
 #include "nautilus-pathbar.h"
 #include "nautilus-profile.h"
-#include "nautilus-properties-window.h"
 #include "nautilus-signaller.h"
 #include "nautilus-toolbar.h"
 #include "nautilus-trash-monitor.h"
@@ -1104,26 +1103,6 @@ action_empty_trash (GSimpleAction *action,
     nautilus_file_operations_empty_trash (GTK_WIDGET (window), TRUE, NULL);
 }
 
-/* Callback used for the "properties" menu item from the places sidebar */
-static void
-action_properties (GSimpleAction *action,
-                   GVariant      *variant,
-                   gpointer       user_data)
-{
-    NautilusWindow *window = NAUTILUS_WINDOW (user_data);
-    GList *list;
-    NautilusFile *file;
-
-    file = nautilus_file_get (window->selected_file);
-
-    list = g_list_append (NULL, file);
-    nautilus_properties_window_present (list, GTK_WIDGET (window), NULL, NULL,
-                                        NULL);
-    nautilus_file_list_free (list);
-
-    g_clear_object (&window->selected_file);
-}
-
 static gboolean
 check_have_gnome_disks (void)
 {
@@ -1267,19 +1246,6 @@ places_sidebar_populate_popup_cb (NautilusGtkPlacesSidebar *sidebar,
                                          !nautilus_trash_monitor_is_empty ());
         }
         g_object_unref (trash);
-
-        if (g_file_is_native (selected_file))
-        {
-            window->selected_file = g_object_ref (selected_file);
-            add_menu_separator (menu);
-
-            menu_item = gtk_model_button_new ();
-            gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
-                                            "win.properties");
-            g_object_set (menu_item, "text", _("_Properties"), NULL);
-            gtk_box_append (GTK_BOX (menu), menu_item);
-            gtk_widget_show (menu_item);
-        }
     }
     if (selected_volume)
     {
@@ -1875,7 +1841,6 @@ const GActionEntry win_entries[] =
     { "prompt-home-location", action_prompt_for_location_home },
     { "go-to-tab", NULL, "i", "0", action_go_to_tab },
     { "empty-trash", action_empty_trash },
-    { "properties", action_properties },
     { "format", action_format },
     { "restore-tab", action_restore_tab },
 };


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