(mml-mode, mml-x-dnd-attach-file): Attach drop and drag
authorJesper Harder <harder@ifa.au.dk>
Fri, 6 Feb 2004 19:37:49 +0000 (19:37 +0000)
committerJesper Harder <harder@ifa.au.dk>
Fri, 6 Feb 2004 19:37:49 +0000 (19:37 +0000)
files.

lisp/ChangeLog
lisp/mml.el

index 5fb0823..be9fec4 100644 (file)
@@ -1,5 +1,8 @@
 2004-02-06  Jesper Harder  <harder@ifa.au.dk>
 
+       * mml.el (mml-mode, mml-x-dnd-attach-file): Attach drop and drag
+       files.
+
        * message.el (message-generate-headers-first): Don't quote nil
        and t in docstrings.
 
index 3b15520..764ebd2 100644 (file)
@@ -37,7 +37,8 @@
   (autoload 'gnus-make-local-hook "gnus-util")
   (autoload 'message-fetch-field "message")
   (autoload 'fill-flowed-encode "flow-fill")
-  (autoload 'message-posting-charset "message"))
+  (autoload 'message-posting-charset "message")
+  (autoload 'x-dnd-get-local-file-name "x-dnd"))
 
 (defcustom mml-content-type-parameters
   '(name access-type expiration size permission format)
@@ -888,6 +889,11 @@ See Info node `(emacs-mime)Composing'.
               (> (prefix-numeric-value arg) 0)))
     (add-minor-mode 'mml-mode " MML" mml-mode-map)
     (easy-menu-add mml-menu mml-mode-map)
+    (when (boundp 'x-dnd-protocol-alist)
+      (set (make-local-variable 'x-dnd-protocol-alist)
+          '(("^file:///" . mml-x-dnd-attach-file)
+            ("^file://"  . x-dnd-open-file)
+            ("^file:"    . mml-x-dnd-attach-file))))
     (run-hooks 'mml-mode-hook)))
 
 ;;;
@@ -1005,6 +1011,15 @@ description of the attachment."
                        'disposition (or disposition "attachment")
                        'description description))
 
+(defun mml-x-dnd-attach-file (uri action)
+  "Attach a drag and drop file."
+  (let ((file (x-dnd-get-local-file-name uri t)))
+    (when (and file (file-regular-p file))
+      (let* ((type (mml-minibuffer-read-type file))
+           (description (mml-minibuffer-read-description))
+           (disposition (mml-minibuffer-read-disposition type)))
+       (mml-attach-file file type description disposition)))))
+
 (defun mml-attach-buffer (buffer &optional type description)
   "Attach a buffer to the outgoing MIME message.
 See `mml-attach-file' for details of operation."