From 98b752f33fb7fed37c6813c0c269fb38cbbb2090 Mon Sep 17 00:00:00 2001 From: Nick Schermer <nick@xfce.org> Date: Tue, 30 Oct 2012 22:04:07 +0100 Subject: [PATCH] Only show Move to Trash if trash is supported. --- thunar/thunar-standard-view.c | 52 +++++++++++++++++++---------------- thunar/thunar-tree-view.c | 22 +++++++++------ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 4323a9cf4..8576c7923 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -1779,22 +1779,30 @@ thunar_standard_view_delete_selected_files (ThunarStandardView *standard_view) _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view), FALSE); - /* Check if there is a user defined accelerator for the delete action, - * if there is, skip events from the hard-coded keys which are set in - * the class of the standard view. See bug #4173. - * - * The trick here is that if a custom accelerator is set by the user, - * this function is never called. If a hardcoded key combination is - * pressed and a custom accelerator is set, accel_key || accel_mods - * are no 0. */ - accel_path = gtk_action_get_accel_path (action); - if (accel_path != NULL - && gtk_accel_map_lookup_entry (accel_path, &key) - && (key.accel_key != 0 || key.accel_mods != 0)) - return FALSE; + if (thunar_g_vfs_is_uri_scheme_supported ("trash")) + { + /* Check if there is a user defined accelerator for the delete action, + * if there is, skip events from the hard-coded keys which are set in + * the class of the standard view. See bug #4173. + * + * The trick here is that if a custom accelerator is set by the user, + * this function is never called. If a hardcoded key combination is + * pressed and a custom accelerator is set, accel_key || accel_mods + * are no 0. */ + accel_path = gtk_action_get_accel_path (action); + if (accel_path != NULL + && gtk_accel_map_lookup_entry (accel_path, &key) + && (key.accel_key != 0 || key.accel_mods != 0)) + return FALSE; - /* just emit the "activate" signal on the "delete" action */ - gtk_action_activate (action); + /* just emit the "activate" signal on the "move-trash" action */ + gtk_action_activate (action); + } + else + { + /* do a permanent delete */ + gtk_action_activate (GTK_ACTION (standard_view->priv->action_delete)); + } /* ...and we're done */ return TRUE; @@ -4016,6 +4024,7 @@ thunar_standard_view_selection_changed (ThunarStandardView *standard_view) /* determine the new list of selected files (replacing GtkTreePath's with ThunarFile's) */ selected_files = (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->get_selected_items) (standard_view); + restorable = (selected_files != NULL); for (lp = selected_files; lp != NULL; lp = lp->next, ++n_selected_files) { /* determine the iterator for the path */ @@ -4026,19 +4035,15 @@ thunar_standard_view_selection_changed (ThunarStandardView *standard_view) /* ...and replace it with the file */ lp->data = thunar_list_model_get_file (standard_view->model, &iter); + + /* enable "Restore" if we have only trashed files (atleast one file) */ + if (!thunar_file_is_trashed (lp->data)) + restorable = FALSE; } /* and setup the new selected files list */ standard_view->priv->selected_files = selected_files; - /* enable "Restore" if we have only trashed files (atleast one file) */ - for (lp = selected_files, restorable = (lp != NULL); lp != NULL; lp = lp->next) - if (!thunar_file_is_trashed (lp->data)) - { - restorable = FALSE; - break; - } - /* check whether the folder displayed by the view is writable/in the trash */ current_directory = thunar_navigator_get_current_directory (THUNAR_NAVIGATOR (standard_view)); writable = (current_directory != NULL && thunar_file_is_writable (current_directory)); @@ -4083,6 +4088,7 @@ thunar_standard_view_selection_changed (ThunarStandardView *standard_view) /* update the "Move to Trash" action */ g_object_set (G_OBJECT (standard_view->priv->action_move_to_trash), "sensitive", (n_selected_files > 0) && writable, + "visible", !trashed && thunar_g_vfs_is_uri_scheme_supported ("trash"), "tooltip", ngettext ("Move the selected file to the Trash", "Move the selected files to the Trash", n_selected_files), diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c index b652270e9..55efdb099 100644 --- a/thunar/thunar-tree-view.c +++ b/thunar/thunar-tree-view.c @@ -1263,16 +1263,20 @@ thunar_tree_view_context_menu (ThunarTreeView *view, gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); - /* append the "Delete" menu action */ - item = gtk_image_menu_item_new_with_mnemonic (_("Mo_ve to Trash")); - g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_tree_view_action_move_to_trash), view); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - gtk_widget_set_sensitive (item, (parent_file != NULL && thunar_file_is_writable (parent_file))); - gtk_widget_show (item); + if (thunar_g_vfs_is_uri_scheme_supported ("trash") + && thunar_file_can_be_trashed (file)) + { + /* append the "Move to Tash" menu action */ + item = gtk_image_menu_item_new_with_mnemonic (_("Mo_ve to Trash")); + g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (thunar_tree_view_action_move_to_trash), view); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_set_sensitive (item, (parent_file != NULL && thunar_file_is_writable (parent_file))); + gtk_widget_show (item); - /* set the stock icon */ - image = gtk_image_new_from_stock (THUNAR_STOCK_TRASH_FULL, GTK_ICON_SIZE_MENU); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + /* set the stock icon */ + image = gtk_image_new_from_stock (THUNAR_STOCK_TRASH_FULL, GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + } /* append the "Delete" menu action */ item = gtk_image_menu_item_new_with_mnemonic (_("_Delete")); -- GitLab