Mercurial > emacs
comparison lisp/dired.el @ 80462:837d54fb9fc9
(dired-dnd-handle-local-file): Obey dired-backup-overwrite for copy,
move, and link operations.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 06 Apr 2008 21:01:54 +0000 |
parents | 3c2f95ff2ff3 |
children | 3af508d0bd74 |
comparison
equal
deleted
inserted
replaced
80461:42cedd27ec5a | 80462:837d54fb9fc9 |
---|---|
3234 (const :tag "Copy directories without asking" always)) | 3234 (const :tag "Copy directories without asking" always)) |
3235 :group 'dired) | 3235 :group 'dired) |
3236 | 3236 |
3237 (defun dired-dnd-popup-notice () | 3237 (defun dired-dnd-popup-notice () |
3238 (message-box | 3238 (message-box |
3239 "Recursive copies not enabled.\nSee variable dired-recursive-copies.")) | 3239 "Dired recursive copies are currently disabled.\nSee the variable `dired-recursive-copies'.")) |
3240 | 3240 |
3241 | 3241 |
3242 (defun dired-dnd-do-ask-action (uri) | 3242 (defun dired-dnd-do-ask-action (uri) |
3243 ;; No need to get actions and descriptions from the source, | 3243 ;; No need to get actions and descriptions from the source, |
3244 ;; we only have three actions anyway. | 3244 ;; we only have three actions anyway. |
3259 "Copy, move or link a file to the dired directory. | 3259 "Copy, move or link a file to the dired directory. |
3260 URI is the file to handle, ACTION is one of copy, move, link or ask. | 3260 URI is the file to handle, ACTION is one of copy, move, link or ask. |
3261 Ask means pop up a menu for the user to select one of copy, move or link." | 3261 Ask means pop up a menu for the user to select one of copy, move or link." |
3262 (require 'dired-aux) | 3262 (require 'dired-aux) |
3263 (let* ((from (dnd-get-local-file-name uri t)) | 3263 (let* ((from (dnd-get-local-file-name uri t)) |
3264 (to (if from (concat (dired-current-directory) | 3264 (to (when from |
3265 (file-name-nondirectory from)) | 3265 (concat (dired-current-directory) |
3266 nil))) | 3266 (file-name-nondirectory from))))) |
3267 (if from | 3267 (when from |
3268 (cond ((or (eq action 'copy) | 3268 (cond ((eq action 'ask) |
3269 (eq action 'private)) ; Treat private as copy. | 3269 (dired-dnd-do-ask-action uri)) |
3270 | 3270 ;; If copying a directory and dired-recursive-copies is |
3271 ;; If copying a directory and dired-recursive-copies is nil, | 3271 ;; nil, dired-copy-file fails. Pop up a notice. |
3272 ;; dired-copy-file silently fails. Pop up a notice. | 3272 ((and (memq action '(copy private)) |
3273 (if (and (file-directory-p from) | 3273 (file-directory-p from) |
3274 (not dired-recursive-copies)) | 3274 (not dired-recursive-copies)) |
3275 (dired-dnd-popup-notice) | 3275 (dired-dnd-popup-notice)) |
3276 (progn | 3276 ((memq action '(copy private move link)) |
3277 (dired-copy-file from to 1) | 3277 (let ((overwrite (and (file-exists-p to) |
3278 (dired-relist-entry to) | 3278 (y-or-n-p |
3279 action))) | 3279 (format "Overwrite existing file `%s'? " to)))) |
3280 | 3280 ;; Binding dired-overwrite-confirmed to nil makes |
3281 ((eq action 'move) | 3281 ;; dired-handle-overwrite a no-op. We instead use |
3282 (dired-rename-file from to 1) | 3282 ;; y-or-n-p, which pops a graphical menu. |
3283 (dired-relist-entry to) | 3283 dired-overwrite-confirmed backup-file) |
3284 action) | 3284 (when (and overwrite |
3285 | 3285 ;; d-b-o is defined in dired-aux. |
3286 ((eq action 'link) | 3286 (boundp 'dired-backup-overwrite) |
3287 (make-symbolic-link from to 1) | 3287 dired-backup-overwrite |
3288 (dired-relist-entry to) | 3288 (setq backup-file |
3289 action) | 3289 (car (find-backup-file-name to))) |
3290 | 3290 (or (eq dired-backup-overwrite 'always) |
3291 ((eq action 'ask) | 3291 (y-or-n-p |
3292 (dired-dnd-do-ask-action uri)) | 3292 (format |
3293 | 3293 "Make backup for existing file `%s'? " to)))) |
3294 (t nil))))) | 3294 (rename-file to backup-file 0) |
3295 (dired-relist-entry backup-file)) | |
3296 (cond ((memq action '(copy private)) | |
3297 (dired-copy-file from to overwrite)) | |
3298 ((eq action 'move) | |
3299 (dired-rename-file from to overwrite)) | |
3300 ((eq action 'link) | |
3301 (make-symbolic-link from to overwrite))) | |
3302 (dired-relist-entry to) | |
3303 action)))))) | |
3295 | 3304 |
3296 (defun dired-dnd-handle-file (uri action) | 3305 (defun dired-dnd-handle-file (uri action) |
3297 "Copy, move or link a file to the dired directory if it is a local file. | 3306 "Copy, move or link a file to the dired directory if it is a local file. |
3298 URI is the file to handle. If the hostname in the URI isn't local, do nothing. | 3307 URI is the file to handle. If the hostname in the URI isn't local, do nothing. |
3299 ACTION is one of copy, move, link or ask. | 3308 ACTION is one of copy, move, link or ask. |