filechooser: move files to the trash with Delete or the context menu
This commit is contained in:
parent
c3651fec43
commit
2abbe2d865
2 changed files with 114 additions and 0 deletions
|
|
@ -2693,6 +2693,98 @@ rename_finish_editing (GtkFileChooserDefault *impl)
|
|||
g_object_unref (file);
|
||||
}
|
||||
|
||||
/* Moving the selected files to the trash, one after the other in the
|
||||
* background; the folder monitor takes them off the list. The files go
|
||||
* even if the dialog closes meanwhile, as the user asked for that. */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GtkFileChooserDefault *impl;
|
||||
GList *files;
|
||||
} TrashData;
|
||||
|
||||
static void trash_next (TrashData *data);
|
||||
|
||||
static void
|
||||
trash_done (GObject *source,
|
||||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
TrashData *data = user_data;
|
||||
GError *error = NULL;
|
||||
|
||||
GDK_THREADS_ENTER ();
|
||||
|
||||
if (g_file_trash_finish (G_FILE (source), result, &error))
|
||||
trash_next (data);
|
||||
else
|
||||
{
|
||||
/* the rest stays, so the user sees what happened */
|
||||
g_list_free_full (data->files, g_object_unref);
|
||||
data->files = NULL;
|
||||
if (gtk_widget_get_mapped (GTK_WIDGET (data->impl)))
|
||||
error_dialog (data->impl, _("The file could not be moved to the Trash"),
|
||||
G_FILE (source), error);
|
||||
else
|
||||
g_error_free (error);
|
||||
trash_next (data);
|
||||
}
|
||||
|
||||
GDK_THREADS_LEAVE ();
|
||||
}
|
||||
|
||||
static void
|
||||
trash_next (TrashData *data)
|
||||
{
|
||||
GFile *file;
|
||||
|
||||
if (data->files == NULL)
|
||||
{
|
||||
g_object_unref (data->impl);
|
||||
g_slice_free (TrashData, data);
|
||||
return;
|
||||
}
|
||||
|
||||
file = data->files->data;
|
||||
data->files = g_list_delete_link (data->files, data->files);
|
||||
g_file_trash_async (file, G_PRIORITY_DEFAULT, NULL, trash_done, data);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
static void
|
||||
trash_selected_foreach (GtkTreeModel *model,
|
||||
GtkTreePath *path,
|
||||
GtkTreeIter *iter,
|
||||
gpointer user_data)
|
||||
{
|
||||
GList **files = user_data;
|
||||
GFile *file;
|
||||
|
||||
gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1);
|
||||
if (file)
|
||||
*files = g_list_prepend (*files, file);
|
||||
}
|
||||
|
||||
static void
|
||||
trash_selected_files (GtkFileChooserDefault *impl)
|
||||
{
|
||||
TrashData *data;
|
||||
GList *files = NULL;
|
||||
|
||||
if (impl->operation_mode != OPERATION_MODE_BROWSE ||
|
||||
impl->rename_file || impl->edited_idle)
|
||||
return;
|
||||
|
||||
current_selection_selected_foreach (impl, trash_selected_foreach, &files);
|
||||
if (files == NULL)
|
||||
return;
|
||||
|
||||
data = g_slice_new (TrashData);
|
||||
data->impl = g_object_ref (impl);
|
||||
data->files = g_list_reverse (files);
|
||||
trash_next (data);
|
||||
}
|
||||
|
||||
/* Starts editing the name of the one selected file */
|
||||
static void
|
||||
rename_selected_file (GtkFileChooserDefault *impl)
|
||||
|
|
@ -4243,6 +4335,14 @@ browse_files_key_press_event_cb (GtkWidget *widget,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
if ((event->keyval == GDK_KEY_Delete || event->keyval == GDK_KEY_KP_Delete) &&
|
||||
!(event->state & gtk_accelerator_get_default_mod_mask ()) &&
|
||||
impl->operation_mode == OPERATION_MODE_BROWSE)
|
||||
{
|
||||
trash_selected_files (impl);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ((event->keyval == GDK_KEY_Return
|
||||
|| event->keyval == GDK_KEY_ISO_Enter
|
||||
|| event->keyval == GDK_KEY_KP_Enter
|
||||
|
|
@ -4289,6 +4389,7 @@ popup_menu_detach_cb (GtkWidget *attach_widget,
|
|||
impl->browse_files_popup_menu_add_shortcut_item = NULL;
|
||||
impl->browse_files_popup_menu_copy_location_item = NULL;
|
||||
impl->browse_files_popup_menu_rename_item = NULL;
|
||||
impl->browse_files_popup_menu_trash_item = NULL;
|
||||
impl->browse_files_popup_menu_hidden_files_item = NULL;
|
||||
impl->browse_files_popup_menu_thumbnails_item = NULL;
|
||||
}
|
||||
|
|
@ -4716,6 +4817,15 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl)
|
|||
gtk_widget_show (item);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
|
||||
|
||||
item = gtk_image_menu_item_new_with_mnemonic (_("Move to _Trash"));
|
||||
impl->browse_files_popup_menu_trash_item = item;
|
||||
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
|
||||
gtk_image_new_from_icon_name ("user-trash", GTK_ICON_SIZE_MENU));
|
||||
g_signal_connect_swapped (item, "activate",
|
||||
G_CALLBACK (trash_selected_files), impl);
|
||||
gtk_widget_show (item);
|
||||
gtk_menu_shell_append (GTK_MENU_SHELL (impl->browse_files_popup_menu), item);
|
||||
|
||||
item = gtk_image_menu_item_new_with_mnemonic (_("_Copy Location"));
|
||||
impl->browse_files_popup_menu_copy_location_item = item;
|
||||
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
|
||||
|
|
@ -4828,6 +4938,9 @@ file_list_update_popup_menu (GtkFileChooserDefault *impl)
|
|||
gtk_widget_set_sensitive (impl->browse_files_popup_menu_rename_item,
|
||||
impl->operation_mode == OPERATION_MODE_BROWSE &&
|
||||
current_selection_count_selected_rows (impl) == 1);
|
||||
gtk_widget_set_sensitive (impl->browse_files_popup_menu_trash_item,
|
||||
impl->operation_mode == OPERATION_MODE_BROWSE &&
|
||||
current_selection_count_selected_rows (impl) > 0);
|
||||
gtk_widget_set_sensitive (impl->browse_files_popup_menu_copy_location_item,
|
||||
current_selection_count_selected_rows (impl) > 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ struct _GtkFileChooserDefault
|
|||
GtkWidget *browse_files_popup_menu_add_shortcut_item;
|
||||
GtkWidget *browse_files_popup_menu_copy_location_item;
|
||||
GtkWidget *browse_files_popup_menu_rename_item;
|
||||
GtkWidget *browse_files_popup_menu_trash_item;
|
||||
GtkWidget *browse_files_popup_menu_hidden_files_item;
|
||||
GtkWidget *browse_files_popup_menu_thumbnails_item;
|
||||
GtkWidget *browse_files_popup_menu_size_column_item;
|
||||
|
|
|
|||
Loading…
Reference in a new issue