diff options
| author | Chong Yidong | 2008-04-06 20:58:20 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-04-06 20:58:20 +0000 |
| commit | 93ab4de3e9711199ab981bbeb22531ce538240be (patch) | |
| tree | bddf237df100a14b26013cdb2f33ea08437da726 | |
| parent | 361be7c303190c6e58d5b5eb0a56914025b63195 (diff) | |
| download | emacs-93ab4de3e9711199ab981bbeb22531ce538240be.tar.gz emacs-93ab4de3e9711199ab981bbeb22531ce538240be.zip | |
(dired-dnd-handle-local-file): Obey dired-backup-overwrite for copy,
move, and link operations.
| -rw-r--r-- | lisp/dired.el | 85 |
1 files changed, 38 insertions, 47 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index 3d6e6d9ea26..4ba6c958b11 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -3281,55 +3281,46 @@ URI is the file to handle, ACTION is one of copy, move, link or ask. | |||
| 3281 | Ask means pop up a menu for the user to select one of copy, move or link." | 3281 | Ask means pop up a menu for the user to select one of copy, move or link." |
| 3282 | (require 'dired-aux) | 3282 | (require 'dired-aux) |
| 3283 | (let* ((from (dnd-get-local-file-name uri t)) | 3283 | (let* ((from (dnd-get-local-file-name uri t)) |
| 3284 | (to (if from (concat (dired-current-directory) | 3284 | (to (when from |
| 3285 | (file-name-nondirectory from)) | 3285 | (concat (dired-current-directory) |
| 3286 | nil))) | 3286 | (file-name-nondirectory from))))) |
| 3287 | (when from | 3287 | (when from |
| 3288 | (cond ((or (eq action 'copy) | 3288 | (cond ((eq action 'ask) |
| 3289 | (eq action 'private)) ; Treat private as copy. | ||
| 3290 | ;; If copying a directory and dired-recursive-copies is nil, | ||
| 3291 | ;; dired-copy-file silently fails. Pop up a notice. | ||
| 3292 | (cond ((and (file-directory-p from) | ||
| 3293 | (not dired-recursive-copies)) | ||
| 3294 | (dired-dnd-popup-notice)) | ||
| 3295 | ((file-exists-p to) | ||
| 3296 | (let ((overwrite | ||
| 3297 | (y-or-n-p (format "Overwrite existing file `%s'? " to))) | ||
| 3298 | ;; We avoid dired-handle-overwrite and use | ||
| 3299 | ;; y-or-n-p, which pops a graphical menu. | ||
| 3300 | dired-overwrite-confirmed backup-file) | ||
| 3301 | (when (and overwrite | ||
| 3302 | ;; silence compiler | ||
| 3303 | (boundp 'dired-backup-overwrite) | ||
| 3304 | dired-backup-overwrite | ||
| 3305 | (setq backup-file | ||
| 3306 | (car (find-backup-file-name to))) | ||
| 3307 | (or (eq dired-backup-overwrite 'always) | ||
| 3308 | (y-or-n-p | ||
| 3309 | (format | ||
| 3310 | "Make backup for existing file `%s'? " to)))) | ||
| 3311 | (rename-file to backup-file 0) | ||
| 3312 | (dired-relist-entry backup-file)) | ||
| 3313 | (dired-copy-file from to overwrite))) | ||
| 3314 | (t | ||
| 3315 | (let (dired-overwrite-confirmed) | ||
| 3316 | (dired-copy-file from to nil)))) | ||
| 3317 | (dired-relist-entry to) | ||
| 3318 | action) | ||
| 3319 | ((eq action 'move) | ||
| 3320 | (dired-rename-file from to 1) | ||
| 3321 | (dired-relist-entry to) | ||
| 3322 | action) | ||
| 3323 | |||
| 3324 | ((eq action 'link) | ||
| 3325 | (make-symbolic-link from to 1) | ||
| 3326 | (dired-relist-entry to) | ||
| 3327 | action) | ||
| 3328 | |||
| 3329 | ((eq action 'ask) | ||
| 3330 | (dired-dnd-do-ask-action uri)) | 3289 | (dired-dnd-do-ask-action uri)) |
| 3331 | 3290 | ;; If copying a directory and dired-recursive-copies is | |
| 3332 | (t nil))))) | 3291 | ;; nil, dired-copy-file fails. Pop up a notice. |
| 3292 | ((and (memq action '(copy private)) | ||
| 3293 | (file-directory-p from) | ||
| 3294 | (not dired-recursive-copies)) | ||
| 3295 | (dired-dnd-popup-notice)) | ||
| 3296 | ((memq action '(copy private move link)) | ||
| 3297 | (let ((overwrite (and (file-exists-p to) | ||
| 3298 | (y-or-n-p | ||
| 3299 | (format "Overwrite existing file `%s'? " to)))) | ||
| 3300 | ;; Binding dired-overwrite-confirmed to nil makes | ||
| 3301 | ;; dired-handle-overwrite a no-op. We instead use | ||
| 3302 | ;; y-or-n-p, which pops a graphical menu. | ||
| 3303 | dired-overwrite-confirmed backup-file) | ||
| 3304 | (when (and overwrite | ||
| 3305 | ;; d-b-o is defined in dired-aux. | ||
| 3306 | (boundp 'dired-backup-overwrite) | ||
| 3307 | dired-backup-overwrite | ||
| 3308 | (setq backup-file | ||
| 3309 | (car (find-backup-file-name to))) | ||
| 3310 | (or (eq dired-backup-overwrite 'always) | ||
| 3311 | (y-or-n-p | ||
| 3312 | (format | ||
| 3313 | "Make backup for existing file `%s'? " to)))) | ||
| 3314 | (rename-file to backup-file 0) | ||
| 3315 | (dired-relist-entry backup-file)) | ||
| 3316 | (cond ((memq action '(copy private)) | ||
| 3317 | (dired-copy-file from to overwrite)) | ||
| 3318 | ((eq action 'move) | ||
| 3319 | (dired-rename-file from to overwrite)) | ||
| 3320 | ((eq action 'link) | ||
| 3321 | (make-symbolic-link from to overwrite))) | ||
| 3322 | (dired-relist-entry to) | ||
| 3323 | action)))))) | ||
| 3333 | 3324 | ||
| 3334 | (defun dired-dnd-handle-file (uri action) | 3325 | (defun dired-dnd-handle-file (uri action) |
| 3335 | "Copy, move or link a file to the dired directory if it is a local file. | 3326 | "Copy, move or link a file to the dired directory if it is a local file. |