diff --git a/ChangeLog b/ChangeLog index 38dd8877fd01d2d5623154bf5d91b6a2a6e5ee44..5ba68fd786e95c273228cfe1d389dd56c38ac095 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-04-08 Benedikt Meurer <benny@xfce.org> + + * thunar/thunar-location-buttons.c: Add "Create Folder" action to the + path bar button context menu. + 2006-04-08 Benedikt Meurer <benny@xfce.org> * thunar/thunar-renamer-dialog.c: Fix tooltips for "add-files" and diff --git a/thunar/thunar-location-buttons.c b/thunar/thunar-location-buttons.c index 309c9813759291c87f8e8337f73372054d6157d1..00f55a0056423f400dcdaaf5cec38aec6115251a 100644 --- a/thunar/thunar-location-buttons.c +++ b/thunar/thunar-location-buttons.c @@ -26,6 +26,7 @@ #include <thunar/thunar-application.h> #include <thunar/thunar-clipboard-manager.h> +#include <thunar/thunar-create-dialog.h> #include <thunar/thunar-file-monitor.h> #include <thunar/thunar-gobject-extensions.h> #include <thunar/thunar-location-button.h> @@ -111,6 +112,8 @@ static void thunar_location_buttons_clicked (ThunarL static void thunar_location_buttons_context_menu (ThunarLocationButton *button, GdkEventButton *event, ThunarLocationButtons *buttons); +static void thunar_location_buttons_action_create_folder (GtkAction *action, + ThunarLocationButtons *buttons); static void thunar_location_buttons_action_down_folder (GtkAction *action, ThunarLocationButtons *buttons); static void thunar_location_buttons_action_open (GtkAction *action, @@ -1288,7 +1291,23 @@ thunar_location_buttons_context_menu (ThunarLocationButton *button, g_free (tooltip); /* add a separator */ - gtk_ui_manager_add_ui (ui_manager, merge_id, "/ThunarLocationButtons::context-menu", "separator", NULL, GTK_UI_MANAGER_SEPARATOR, FALSE); + gtk_ui_manager_add_ui (ui_manager, merge_id, "/ThunarLocationButtons::context-menu", "separator1", NULL, GTK_UI_MANAGER_SEPARATOR, FALSE); + + /* add the "Create Folder" action */ + tooltip = g_strdup_printf (_("Create a new folder in \"%s\""), thunar_file_get_display_name (file)); + action = gtk_action_new ("ThunarLocationButtons::create-folder", _("Create _Folder..."), tooltip, NULL); + g_object_set_data_full (G_OBJECT (action), I_("thunar-file"), g_object_ref (G_OBJECT (file)), (GDestroyNotify) g_object_unref); + g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (thunar_location_buttons_action_create_folder), buttons); + gtk_action_set_sensitive (action, thunar_file_is_writable (file)); + gtk_action_group_add_action (action_group, action); + gtk_ui_manager_add_ui (ui_manager, merge_id, "/ThunarLocationButtons::context-menu", + gtk_action_get_name (action), gtk_action_get_name (action), + GTK_UI_MANAGER_MENUITEM, FALSE); + g_object_unref (G_OBJECT (action)); + g_free (tooltip); + + /* add a separator */ + gtk_ui_manager_add_ui (ui_manager, merge_id, "/ThunarLocationButtons::context-menu", "separator2", NULL, GTK_UI_MANAGER_SEPARATOR, FALSE); /* add the "Open in New Window" action */ tooltip = g_strdup_printf (_("Move or copy files previously selected by a Cut or Copy command into \"%s\""), thunar_file_get_display_name (file)); @@ -1338,6 +1357,57 @@ thunar_location_buttons_context_menu (ThunarLocationButton *button, +static void +thunar_location_buttons_action_create_folder (GtkAction *action, + ThunarLocationButtons *buttons) +{ + ThunarVfsMimeDatabase *mime_database; + ThunarVfsMimeInfo *mime_info; + ThunarApplication *application; + ThunarFile *directory; + GList path_list; + gchar *name; + + g_return_if_fail (GTK_IS_ACTION (action)); + g_return_if_fail (THUNAR_IS_LOCATION_BUTTONS (buttons)); + + /* determine the directory for the action */ + directory = g_object_get_data (G_OBJECT (action), "thunar-file"); + if (G_UNLIKELY (directory == NULL)) + return; + + /* lookup "inode/directory" mime info */ + mime_database = thunar_vfs_mime_database_get_default (); + mime_info = thunar_vfs_mime_database_get_info (mime_database, "inode/directory"); + + /* ask the user to enter a name for the new folder */ + name = thunar_show_create_dialog (GTK_WIDGET (buttons), mime_info, _("New Folder"), _("Create New Folder")); + if (G_LIKELY (name != NULL)) + { + /* fake the path list */ + path_list.data = thunar_vfs_path_relative (thunar_file_get_path (directory), name); + path_list.next = path_list.prev = NULL; + + /* launch the operation */ + application = thunar_application_get (); + thunar_application_mkdir (application, GTK_WIDGET (buttons), &path_list, NULL); + g_object_unref (G_OBJECT (application)); + + /* release the path */ + thunar_vfs_path_unref (path_list.data); + + /* release the file name */ + g_free (name); + } + + /* cleanup */ + g_object_unref (G_OBJECT (mime_database)); + thunar_vfs_mime_info_unref (mime_info); + g_object_unref (G_OBJECT (directory)); +} + + + static void thunar_location_buttons_action_down_folder (GtkAction *action, ThunarLocationButtons *buttons)