Mercurial > emacs
diff src/w32fns.c @ 96489:b76b9628d74f
Changes from Toru Tsuneyoshi for using Trash can when deleting files.
* files.el (backup-extract-version): Handle versioned directories.
(trash-directory): New variable.
(move-file-to-trash): New function.
* cus-start.el (delete-by-moving-to-trash): Declare for custom.
* lisp.h (Qdelete_file, Qdelete_directory): Declare extern.
* fileio.c (delete_by_moving_to_trash, Qmove_file_to_trash): New vars.
(syms_of_fileio): Initialize and export them.
(Fdelete_directory, Fdelete_file): Optionally delete via trash.
* w32fns.c (FOF_NO_CONNECTED_ELEMENTS): Define if not already.
(Fsystem_move_file_to_trash): New function.
(syms_of_w32fns): Export it to lisp.
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Wed, 02 Jul 2008 13:19:07 +0000 |
parents | 4b6d1b55f59c |
children | 187f69369145 |
line wrap: on
line diff
--- a/src/w32fns.c Wed Jul 02 13:17:41 2008 +0000 +++ b/src/w32fns.c Wed Jul 02 13:19:07 2008 +0000 @@ -63,6 +63,10 @@ #include "font.h" #include "w32font.h" +#ifndef FOF_NO_CONNECTED_ELEMENTS +#define FOF_NO_CONNECTED_ELEMENTS 0x2000 +#endif + void syms_of_w32fns (); void globals_of_w32fns (); @@ -6208,6 +6212,60 @@ } +/* Moving files to the system recycle bin. + Used by `move-file-to-trash' instead of the default moving to ~/.Trash */ +DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash, + Ssystem_move_file_to_trash, 1, 1, 0, + doc: /* Move file or directory named FILENAME to the recycle bin. */) + (filename) + Lisp_Object filename; +{ + Lisp_Object handler; + Lisp_Object encoded_file; + Lisp_Object operation; + + operation = Qdelete_file; + if (!NILP (Ffile_directory_p (filename)) + && NILP (Ffile_symlink_p (filename))) + { + operation = Qdelete_directory; + filename = Fdirectory_file_name (filename); + } + filename = Fexpand_file_name (filename, Qnil); + + handler = Ffind_file_name_handler (filename, operation); + if (!NILP (handler)) + return call2 (handler, operation, filename); + + encoded_file = ENCODE_FILE (filename); + + { + const char * path; + SHFILEOPSTRUCT file_op; + char tmp_path[MAX_PATH + 1]; + + path = map_w32_filename (SDATA (encoded_file), NULL); + + /* On Windows, write permission is required to delete/move files. */ + _chmod (path, 0666); + + bzero (tmp_path, sizeof (tmp_path)); + strcpy (tmp_path, path); + + bzero (&file_op, sizeof (file_op)); + file_op.hwnd = HWND_DESKTOP; + file_op.wFunc = FO_DELETE; + file_op.pFrom = tmp_path; + file_op.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_ALLOWUNDO + | FOF_NOERRORUI | FOF_NO_CONNECTED_ELEMENTS; + file_op.fAnyOperationsAborted = FALSE; + + if (SHFileOperation (&file_op) != 0) + report_file_error ("Removing old name", list1 (filename)); + } + return Qnil; +} + /*********************************************************************** w32 specialized functions @@ -7241,6 +7299,7 @@ staticpro (&last_show_tip_args); defsubr (&Sx_file_dialog); + defsubr (&Ssystem_move_file_to_trash); }