diff options
author | Po Lu <luangruo@yahoo.com> | 2022-06-03 12:32:17 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-06-03 12:32:30 +0800 |
commit | e65647a70e5c055c4cdab004d671c198c7a1d3ce (patch) | |
tree | e9a0d3e093911c9695fad11d21674d0989aab1da /lisp/dired.el | |
parent | 1d5eb67c6a87bcf155429b11af98de913e901dd9 (diff) | |
download | emacs-e65647a70e5c055c4cdab004d671c198c7a1d3ce.tar.gz emacs-e65647a70e5c055c4cdab004d671c198c7a1d3ce.tar.bz2 emacs-e65647a70e5c055c4cdab004d671c198c7a1d3ce.zip |
Add easier-to-use interfaces for initiating drag-and-drop
The previous interface required that users know intricacies of
the data types used to transfer data on each platform Emacs
supports.
* doc/lispref/frames.texi (Drag and Drop): Document new
functions.
* lisp/dired.el (dired-last-dragged-remote-file)
(dired-remove-last-dragged-local-file): Delete functions.
(dired-mouse-drag): Use `dnd-begin-file-drag'.
* lisp/dnd.el (dnd-last-dragged-remote-file)
(dnd-remove-last-dragged-remote-file): New variables and
functions.
(dnd-begin-text-drag, dnd-begin-file-drag): New functions.
* src/xterm.c (x_dnd_begin_drag_and_drop): Add porting note.
Diffstat (limited to 'lisp/dired.el')
-rw-r--r-- | lisp/dired.el | 47 |
1 files changed, 5 insertions, 42 deletions
diff --git a/lisp/dired.el b/lisp/dired.el index 5a1fce860e1..94df2ddc4e9 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -38,6 +38,7 @@ (eval-when-compile (require 'cl-lib)) ;; When bootstrapping dired-loaddefs has not been generated. (require 'dired-loaddefs nil t) +(require 'dnd) (declare-function dired-buffer-more-recently-used-p "dired-x" (buffer1 buffer2)) @@ -1702,29 +1703,13 @@ see `dired-use-ls-dired' for more details.") beg)) beg)))) -(defvar dired-last-dragged-remote-file nil - "If non-nil, the name of a local copy of the last remote file that was dragged. -It can't be removed immediately after the drag-and-drop operation -completes, since there is no way to determine when the drop -target has finished opening it. So instead, this file is removed -when Emacs exits or the user drags another file.") - (declare-function x-begin-drag "xfns.c") -(defun dired-remove-last-dragged-local-file () - "Remove the local copy of the last remote file to be dragged." - (when dired-last-dragged-remote-file - (unwind-protect - (delete-file dired-last-dragged-remote-file) - (setq dired-last-dragged-remote-file nil))) - (remove-hook 'kill-emacs-hook #'dired-remove-last-dragged-local-file)) - (defun dired-mouse-drag (event) "Begin a drag-and-drop operation for the file at EVENT." (interactive "e") (when mark-active (deactivate-mark)) - (dired-remove-last-dragged-local-file) (save-excursion (with-selected-window (posn-window (event-end event)) (goto-char (posn-point (event-end event)))) @@ -1753,32 +1738,10 @@ when Emacs exits or the user drags another file.") (event-end event)) (dired-file-name-at-point)))) (when filename - ;; In theory x-dnd-username combined with a proper - ;; file URI containing the hostname of the remote - ;; server could be used here instead of creating a - ;; local copy of the remote file, but no program - ;; actually implements file DND according to the - ;; spec. - (when (file-remote-p filename) - (setq filename (file-local-copy filename)) - (setq dired-last-dragged-remote-file filename) - (add-hook 'kill-emacs-hook - #'dired-remove-last-dragged-local-file)) - (gui-backend-set-selection - ;; FIXME: this seems arbitrarily confusing. - ;; Should drag-and-drop for common items (such as - ;; files and text) should be abstracted into - ;; dnd.el? - 'XdndSelection - (propertize filename 'text/uri-list - (concat "file://" - (expand-file-name filename)))) - (x-begin-drag '("text/uri-list" "text/x-dnd-username" - "FILE_NAME" "FILE" "HOST_NAME" "_DT_NETFILE") - (if (eq 'dired-mouse-drag-files 'link) - 'XdndActionLink - 'XdndActionCopy) - nil nil t))) + (dnd-begin-file-drag filename nil + (if (eq 'dired-mouse-drag-files 'link) + 'move 'copy) + t))) (error (when (eq (event-basic-type new-event) 'mouse-1) (push new-event unread-command-events)))))))))) |