Commit a73c8c77 authored by Cosimo Cecchi's avatar Cosimo Cecchi

places-sidebar: add a Format menu item for volumes

This runs gnome-disks with a commandline that just sets the format
dialog as transient for the Nautilus toplevel.

https://bugzilla.gnome.org/show_bug.cgi?id=687093
parent f60a3d04
......@@ -25,9 +25,11 @@
#include <config.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include <libnautilus-private/nautilus-dnd.h>
#include <libnautilus-private/nautilus-bookmark.h>
......@@ -93,6 +95,7 @@ typedef struct {
GtkWidget *popup_menu_stop_item;
GtkWidget *popup_menu_properties_separator_item;
GtkWidget *popup_menu_properties_item;
GtkWidget *popup_menu_format_item;
/* volume mounting - delayed open process */
gboolean mounting;
......@@ -1543,6 +1546,20 @@ bookmarks_popup_menu_detach_cb (GtkWidget *attach_widget,
sidebar->popup_menu_empty_trash_item = NULL;
sidebar->popup_menu_properties_separator_item = NULL;
sidebar->popup_menu_properties_item = NULL;
sidebar->popup_menu_format_item = 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 void
......@@ -1577,12 +1594,16 @@ check_visibility (GMount *mount,
gboolean *show_eject,
gboolean *show_rescan,
gboolean *show_start,
gboolean *show_stop)
gboolean *show_stop,
gboolean *show_format)
{
gchar *unix_device_id;
*show_mount = FALSE;
*show_rescan = FALSE;
*show_start = FALSE;
*show_stop = FALSE;
*show_format = FALSE;
check_unmount_and_eject (mount, volume, drive, show_unmount, show_eject);
......@@ -1602,6 +1623,10 @@ check_visibility (GMount *mount,
if (volume != NULL) {
if (mount == NULL)
*show_mount = g_volume_can_mount (volume);
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);
}
}
......@@ -1623,6 +1648,7 @@ bookmarks_check_popup_sensitivity (NautilusPlacesSidebar *sidebar)
gboolean show_stop;
gboolean show_empty_trash;
gboolean show_properties;
gboolean show_format;
char *uri = NULL;
type = PLACES_BUILT_IN;
......@@ -1648,7 +1674,7 @@ bookmarks_check_popup_sensitivity (NautilusPlacesSidebar *sidebar)
gtk_widget_set_sensitive (sidebar->popup_menu_empty_trash_item, !nautilus_trash_monitor_is_empty ());
check_visibility (mount, volume, drive,
&show_mount, &show_unmount, &show_eject, &show_rescan, &show_start, &show_stop);
&show_mount, &show_unmount, &show_eject, &show_rescan, &show_start, &show_stop, &show_format);
/* We actually want both eject and unmount since eject will unmount all volumes.
* TODO: hide unmount if the drive only has a single mountable volume
......@@ -1680,6 +1706,7 @@ bookmarks_check_popup_sensitivity (NautilusPlacesSidebar *sidebar)
gtk_widget_set_visible (sidebar->popup_menu_empty_trash_item, show_empty_trash);
gtk_widget_set_visible (sidebar->popup_menu_properties_separator_item, show_properties);
gtk_widget_set_visible (sidebar->popup_menu_properties_item, show_properties);
gtk_widget_set_visible (sidebar->popup_menu_format_item, show_format);
/* Adjust start/stop items to reflect the type of the drive */
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_start_item), _("_Start"));
......@@ -2513,6 +2540,47 @@ stop_shortcut_cb (GtkMenuItem *item,
g_object_unref (drive);
}
static void
format_shortcut_cb (GtkMenuItem *item,
NautilusPlacesSidebar *sidebar)
{
GAppInfo *app_info;
gchar *cmdline, *device_identifier, *xid_string;
GVolume *volume;
GtkTreeIter iter;
gint xid;
if (!get_selected_iter (sidebar, &iter)) {
return;
}
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
PLACES_SIDEBAR_COLUMN_VOLUME, &volume,
-1);
if (!volume) {
return;
}
device_identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
xid = (gint) gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (sidebar->window)));
xid_string = g_strdup_printf ("%d", xid);
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 (&volume);
g_clear_object (&app_info);
}
static void
empty_trash_cb (GtkMenuItem *item,
NautilusPlacesSidebar *sidebar)
......@@ -2801,6 +2869,12 @@ bookmarks_build_popup_menu (NautilusPlacesSidebar *sidebar)
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
item = gtk_menu_item_new_with_mnemonic (_("_Format…"));
sidebar->popup_menu_format_item = item;
g_signal_connect (item, "activate",
G_CALLBACK (format_shortcut_cb), sidebar);
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
/* Empty Trash menu item */
item = gtk_menu_item_new_with_mnemonic (_("Empty _Trash"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment