Function: x-dnd-do-direct-save
x-dnd-do-direct-save is a byte-compiled function defined in
x-dnd.el.gz.
Signature
(x-dnd-do-direct-save FILE NAME FRAME ALLOW-SAME-FRAME)
Documentation
Perform a direct save operation on FILE, from FRAME.
FILE is the file containing the contents to drop. NAME is the name that should be given to the file after dropping. FRAME is the frame from which the drop will originate. ALLOW-SAME-FRAME means whether or not dropping will be allowed on FRAME.
Return the action taken by the drop target, or nil if no action was taken, or the direct save failed.
Source Code
;; Defined in /usr/src/emacs/lisp/x-dnd.el.gz
(defun x-dnd-do-direct-save (file name frame allow-same-frame)
"Perform a direct save operation on FILE, from FRAME.
FILE is the file containing the contents to drop.
NAME is the name that should be given to the file after dropping.
FRAME is the frame from which the drop will originate.
ALLOW-SAME-FRAME means whether or not dropping will be allowed
on FRAME.
Return the action taken by the drop target, or nil if no action
was taken, or the direct save failed."
(dnd-remove-last-dragged-remote-file)
(let ((file-name file)
(original-file-name file)
(selection-converter-alist
(append '((XdndDirectSave0 . x-dnd-handle-direct-save)
(application/octet-stream . x-dnd-handle-octet-stream))
selection-converter-alist))
(x-dnd-xds-current-file nil)
(x-dnd-xds-source-frame frame)
(x-dnd-xds-performed nil)
;; The XDS protocol is built on top of XDND, and cannot
;; possibly work with Motif or OffiX programs.
(x-dnd-disable-motif-protocol t)
(x-dnd-use-offix-drop nil)
(x-dnd-use-unsupported-drop nil)
(prop-deleted nil)
encoded-name)
(unwind-protect
(progn
(when (file-remote-p file)
(setq file-name (file-local-copy file))
(setq dnd-last-dragged-remote-file file-name)
(add-hook 'kill-emacs-hook
#'dnd-remove-last-dragged-remote-file))
(setq encoded-name
(encode-coding-string name
(or file-name-coding-system
default-file-name-coding-system)))
(setq x-dnd-xds-current-file file-name)
(x-change-window-property "XdndDirectSave0" encoded-name
frame "text/plain" 8 nil)
(gui-set-selection 'XdndSelection (concat "file://" file-name))
;; FIXME: this does not work with GTK file managers,
;; since they always reach for `text/uri-list' first,
;; contrary to the spec.
(let ((action (x-begin-drag '("XdndDirectSave0" "text/uri-list"
"application/octet-stream")
'XdndActionDirectSave
frame nil allow-same-frame)))
(if (not x-dnd-xds-performed)
action
(let ((property (x-window-property "XdndDirectSave0" frame
"AnyPropertyType" nil t)))
(setq prop-deleted t)
;; "System-G" deletes the property upon success.
(and (or (null property)
(and (stringp property)
(not (equal property ""))))
action)))))
(unless prop-deleted
(x-delete-window-property "XdndDirectSave0" frame))
;; Delete any remote copy that was made.
(when (and (not (equal file-name original-file-name))
x-dnd-xds-performed)
(delete-file file-name)))))