diff --git a/thunar/thunar-launcher.c b/thunar/thunar-launcher.c index 6dbd8bbdc555d91bf5913b159ecd25fd7a09bfdf..4e6399f1cf56356c389c50ed04d18c7a643d92ce 100644 --- a/thunar/thunar-launcher.c +++ b/thunar/thunar-launcher.c @@ -182,11 +182,9 @@ static void thunar_launcher_action_add_shortcuts (Thuna static void thunar_launcher_action_make_link (ThunarLauncher *launcher); static void thunar_launcher_action_duplicate (ThunarLauncher *launcher); static void thunar_launcher_action_rename (ThunarLauncher *launcher); -static void thunar_launcher_action_restore (ThunarLauncher *launcher); static void thunar_launcher_action_move_to_trash (ThunarLauncher *launcher); static void thunar_launcher_action_delete (ThunarLauncher *launcher); static void thunar_launcher_action_trash_delete (ThunarLauncher *launcher); -static void thunar_launcher_action_empty_trash (ThunarLauncher *launcher); static void thunar_launcher_action_cut (ThunarLauncher *launcher); static void thunar_launcher_action_copy (ThunarLauncher *launcher); static void thunar_launcher_action_paste (ThunarLauncher *launcher); @@ -2322,7 +2320,7 @@ thunar_launcher_action_rename (ThunarLauncher *launcher) -static void +void thunar_launcher_action_restore (ThunarLauncher *launcher) { ThunarApplication *application; @@ -2391,18 +2389,13 @@ thunar_launcher_action_trash_delete (ThunarLauncher *launcher) -static void +void thunar_launcher_action_empty_trash (ThunarLauncher *launcher) { ThunarApplication *application; _thunar_return_if_fail (THUNAR_IS_LAUNCHER (launcher)); - if (launcher->single_directory_to_process == FALSE) - return; - if (!thunar_file_is_root (launcher->single_folder) || !thunar_file_is_trashed (launcher->single_folder)) - return; - application = thunar_application_get (); thunar_application_empty_trash (application, launcher->widget, NULL); g_object_unref (G_OBJECT (application)); diff --git a/thunar/thunar-launcher.h b/thunar/thunar-launcher.h index 1075e3b702e840bbac30a504e2eba071b2e9d515..e5dc2c501726b05ef15c5d03c2f6b9f4fab75eac 100644 --- a/thunar/thunar-launcher.h +++ b/thunar/thunar-launcher.h @@ -107,6 +107,8 @@ void thunar_launcher_set_selection (ThunarLaun GList *selected_thunar_files, ThunarDevice *selected_device, GFile *selected_location); +void thunar_launcher_action_empty_trash (ThunarLauncher *launcher); +void thunar_launcher_action_restore (ThunarLauncher *launcher); G_END_DECLS; diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index e4d6015f5ed5283792522eed0f72398b24513f80..21aaa272a117e6d090b0ee76ab00f59022f93888 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -86,6 +86,13 @@ enum LAST_SIGNAL, }; +/* Trash infobar response ids */ +enum +{ + EMPTY, + RESTORE +}; + struct _ThunarBookmark { GFile *g_file; @@ -282,6 +289,10 @@ static void thunar_window_set_directory_specific_settings (ThunarWindow static GType thunar_window_view_type_for_directory (ThunarWindow *window, ThunarFile *directory); static void thunar_window_action_clear_directory_specific_settings (ThunarWindow *window); +static void thunar_window_trash_infobar_clicked (GtkInfoBar *info_bar, + gint response_id, + ThunarWindow *window); +static void thunar_window_trash_selection_updated (ThunarWindow *window); @@ -326,6 +337,8 @@ struct _ThunarWindow GtkWidget *paned; GtkWidget *sidepane; GtkWidget *view_box; + GtkWidget *trash_infobar; + GtkWidget *trash_infobar_restore_button; /* split view panes */ GtkWidget *paned_notebooks; @@ -790,6 +803,15 @@ thunar_window_init (ThunarWindow *window) gtk_paned_pack2 (GTK_PANED (window->paned), window->view_box, TRUE, FALSE); gtk_widget_show (window->view_box); + window->trash_infobar = gtk_info_bar_new(); + gtk_grid_attach (GTK_GRID (window->view_box), window->trash_infobar, 0, 0, 1, 1); + window->trash_infobar_restore_button = gtk_info_bar_add_button (GTK_INFO_BAR (window->trash_infobar), "Restore Selected Items", RESTORE); + gtk_info_bar_add_button (GTK_INFO_BAR (window->trash_infobar), "Empty Trash", EMPTY); + g_signal_connect (window->trash_infobar, + "response", + G_CALLBACK (thunar_window_trash_infobar_clicked), + G_OBJECT (window)); + /* split view: Create panes where the two notebooks */ window->paned_notebooks = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL); gtk_paned_add2 (GTK_PANED (window->paned), window->view_box); @@ -1732,10 +1754,16 @@ thunar_window_notebook_switch_page (GtkWidget *notebook, G_BINDING_SYNC_CREATE); } + if (window->view != NULL) + g_signal_handlers_disconnect_by_func (window->view, thunar_window_trash_selection_updated, window); + /* activate new view */ window->view = page; window->view_type = G_TYPE_FROM_INSTANCE (page); + g_signal_connect_swapped (G_OBJECT (window->view), "notify::selected-files", + G_CALLBACK (thunar_window_trash_selection_updated), window); + /* remember the last view type if directory specific settings are not enabled */ if (!window->directory_specific_settings && window->view_type != G_TYPE_NONE) g_object_set (G_OBJECT (window->preferences), "last-view", g_type_name (window->view_type), NULL); @@ -3979,6 +4007,8 @@ void thunar_window_set_current_directory (ThunarWindow *window, ThunarFile *current_directory) { + gboolean is_trash; + _thunar_return_if_fail (THUNAR_IS_WINDOW (window)); _thunar_return_if_fail (current_directory == NULL || THUNAR_IS_FILE (current_directory)); @@ -4060,10 +4090,16 @@ thunar_window_set_current_directory (ThunarWindow *window, /* show/hide date_deleted column/sortBy in the trash directory */ if (current_directory == NULL) return; + + is_trash = thunar_file_is_trash (current_directory); + if (is_trash) + gtk_widget_show (window->trash_infobar); + else + gtk_widget_hide (window->trash_infobar); + if (THUNAR_IS_DETAILS_VIEW (window->view) == FALSE) return; - - thunar_details_view_set_date_deleted_column_visible (THUNAR_DETAILS_VIEW (window->view), thunar_file_is_trash (current_directory)); + thunar_details_view_set_date_deleted_column_visible (THUNAR_DETAILS_VIEW (window->view), is_trash); } @@ -4388,3 +4424,42 @@ thunar_window_view_type_for_directory (ThunarWindow *window, return type; } + + + +static void +thunar_window_trash_infobar_clicked (GtkInfoBar *info_bar, + gint response_id, + ThunarWindow *window) +{ + switch (response_id) + { + case EMPTY: + thunar_launcher_action_empty_trash (window->launcher); + break; + case RESTORE: + thunar_launcher_action_restore (window->launcher); + break; + default: + g_return_if_reached(); + } +} + + + +/** + * thunar_window_trash_selection_updated: + * @window : a #ThunarWindow instance. + * + * Used to set the `sensitive` value of the `Restore` button in the trash infobar. + **/ +static void +thunar_window_trash_selection_updated (ThunarWindow *window) +{ + GList* selected_files = thunar_view_get_selected_files (THUNAR_VIEW (window->view)); + + if (g_list_length (selected_files) > 0) + gtk_widget_set_sensitive (window->trash_infobar_restore_button, TRUE); + else + gtk_widget_set_sensitive (window->trash_infobar_restore_button, FALSE); +}