[nautilus] sidebar: Implement format volume action
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] sidebar: Implement format volume action
- Date: Mon, 2 May 2022 10:22:24 +0000 (UTC)
commit 7caa0ae67607d104a20482d686fe711faaa553b6
Author: Corey Berla <corey berla me>
Date: Mon Apr 25 09:38:33 2022 -0700
sidebar: Implement format volume action
The format volume action needs to be re-implemented for GTK4.
Move the existing code from nautilus-window to nautilusgtkplacessidebar
and necessary tweaks. Drop --xid flag for gnome-disks command
as that has been ignored by gnome-disks since version 40.beta
https://gitlab.gnome.org/GNOME/gnome-disk-utility/-/commit/9f6571532c6b6f9c78f0ec4ce47ec3d0b178dba7
src/gtk/nautilusgtkplacessidebar.c | 59 ++++++++++++++++++++++++++++
src/nautilus-window.c | 78 --------------------------------------
2 files changed, 59 insertions(+), 78 deletions(-)
---
diff --git a/src/gtk/nautilusgtkplacessidebar.c b/src/gtk/nautilusgtkplacessidebar.c
index a0a329967..20bd829af 100644
--- a/src/gtk/nautilusgtkplacessidebar.c
+++ b/src/gtk/nautilusgtkplacessidebar.c
@@ -3101,6 +3101,31 @@ on_key_pressed (GtkEventControllerKey *controller,
return FALSE;
}
+static void
+format_cb (GSimpleAction *action,
+ GVariant *variant,
+ gpointer data)
+{
+ NautilusGtkPlacesSidebar *sidebar = data;
+ g_autoptr (GVolume) volume = NULL;
+ GAppInfo *app_info;
+ gchar *cmdline, *device_identifier;
+
+ g_object_get (sidebar->context_row, "volume", &volume, NULL);
+ device_identifier = g_volume_get_identifier (volume,
+ G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+ cmdline = g_strconcat ("gnome-disks ",
+ "--block-device ", device_identifier, " ",
+ "--format-device ",
+ NULL);
+ app_info = g_app_info_create_from_commandline (cmdline, NULL, 0, NULL);
+ g_app_info_launch (app_info, NULL, NULL, NULL);
+
+ g_free (cmdline);
+ g_free (device_identifier);
+ g_clear_object (&app_info);
+}
+
static GActionEntry entries[] = {
{ "open", open_shortcut_cb, "i", NULL, NULL },
{ "open-other", open_shortcut_cb, "i", NULL, NULL },
@@ -3115,8 +3140,35 @@ static GActionEntry entries[] = {
{ "stop", stop_shortcut_cb, NULL, NULL, NULL },
{ "properties", properties_cb, NULL, NULL, NULL },
{ "empty-trash", empty_trash_cb, NULL, NULL, NULL },
+ { "format", format_cb, NULL, NULL, NULL },
};
+static gboolean
+check_have_gnome_disks (void)
+{
+ gchar *disks_path;
+ gboolean res;
+
+ disks_path = g_find_program_in_path ("gnome-disks");
+ res = (disks_path != NULL);
+ g_free (disks_path);
+
+ return res;
+}
+
+static gboolean
+should_show_format_command (GVolume *volume)
+{
+ gchar *unix_device_id;
+ gboolean show_format;
+
+ unix_device_id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+ show_format = (unix_device_id != NULL) && check_have_gnome_disks ();
+ g_free (unix_device_id);
+
+ return show_format;
+}
+
static void
on_row_popover_destroy (GtkWidget *row_popover,
NautilusGtkPlacesSidebar *sidebar)
@@ -3369,6 +3421,13 @@ create_row_popover (NautilusGtkPlacesSidebar *sidebar,
g_object_unref (item);
}
+ if (volume != NULL && G_IS_VOLUME (volume) && should_show_format_command (volume))
+ {
+ item = g_menu_item_new (_("Format…"), "row.format");
+ g_menu_append_item (section, item);
+ g_object_unref (item);
+ }
+
g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
g_object_unref (section);
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index b1c4f6a14..f8b1a9110 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1091,32 +1091,6 @@ places_sidebar_drag_perform_drop_cb (NautilusGtkPlacesSidebar *sidebar,
}
#endif
-static gboolean
-check_have_gnome_disks (void)
-{
- gchar *disks_path;
- gboolean res;
-
- disks_path = g_find_program_in_path ("gnome-disks");
- res = (disks_path != NULL);
- g_free (disks_path);
-
- return res;
-}
-
-static gboolean
-should_show_format_command (GVolume *volume)
-{
- gchar *unix_device_id;
- gboolean show_format;
-
- unix_device_id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
- show_format = (unix_device_id != NULL) && check_have_gnome_disks ();
- g_free (unix_device_id);
-
- return show_format;
-}
-
static void
action_restore_tab (GSimpleAction *action,
GVariant *state,
@@ -1160,34 +1134,6 @@ get_window_xid (NautilusWindow *window)
return 0;
}
-static void
-action_format (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- NautilusWindow *window = NAUTILUS_WINDOW (user_data);
- GAppInfo *app_info;
- gchar *cmdline, *device_identifier, *xid_string;
-
- device_identifier = g_volume_get_identifier (window->selected_volume,
- G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
- xid_string = g_strdup_printf ("%x", get_window_xid (window));
-
- cmdline = g_strconcat ("gnome-disks ",
- "--block-device ", device_identifier, " ",
- "--format-device ",
- "--xid ", xid_string,
- NULL);
- app_info = g_app_info_create_from_commandline (cmdline, NULL, 0, NULL);
- g_app_info_launch (app_info, NULL, NULL, NULL);
-
- g_free (cmdline);
- g_free (device_identifier);
- g_free (xid_string);
- g_clear_object (&app_info);
- g_clear_object (&window->selected_volume);
-}
-
static void
add_menu_separator (GtkWidget *menu)
{
@@ -1212,29 +1158,6 @@ places_sidebar_populate_popup_cb (NautilusGtkPlacesSidebar *sidebar,
g_clear_object (&window->selected_file);
g_clear_object (&window->selected_volume);
-
- if (selected_volume)
- {
- if (should_show_format_command (selected_volume))
- {
- menu_item = gtk_model_button_new ();
- gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
- "win.format");
- g_object_set (menu_item, "text", _("_Format…"), NULL);
- if (selected_volume != NULL && G_IS_VOLUME (selected_volume))
- {
- window->selected_volume = g_object_ref (selected_volume);
- }
- gtk_box_append (GTK_BOX (menu), menu_item);
- gtk_widget_show (menu_item);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (window),
- "format");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- selected_volume != NULL &&
- G_IS_VOLUME (selected_volume));
- }
- }
}
#endif
@@ -1806,7 +1729,6 @@ const GActionEntry win_entries[] =
{ "prompt-root-location", action_prompt_for_location_root },
{ "prompt-home-location", action_prompt_for_location_home },
{ "go-to-tab", NULL, "i", "0", action_go_to_tab },
- { "format", action_format },
{ "restore-tab", action_restore_tab },
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]