diff options
| author | Po Lu | 2022-06-29 06:05:25 +0000 |
|---|---|---|
| committer | Po Lu | 2022-06-29 06:05:42 +0000 |
| commit | 7fa37d7a1439bf8cd76b336ea95d3a1982b3ae03 (patch) | |
| tree | f5f12071448a408ecf07e61669fdd3a9f14a9b17 | |
| parent | 9c2b1d37e729f7af9e9661be7ece8348bae70ffa (diff) | |
| download | emacs-7fa37d7a1439bf8cd76b336ea95d3a1982b3ae03.tar.gz emacs-7fa37d7a1439bf8cd76b336ea95d3a1982b3ae03.zip | |
Handle be:actions field in Haiku DND messages
* lisp/term/haiku-win.el (haiku-get-numeric-enum): New function.
(haiku-numeric-enum): New macro.
(haiku-select-encode-xstring, haiku-select-encode-utf-8-string):
Replace hard-coded numeric enumerators.
(haiku-parse-drag-actions): New function.
(haiku-drag-and-drop): Use action returned by that function.
(x-begin-drag): Replace hard-coded enumerator.
| -rw-r--r-- | lisp/term/haiku-win.el | 102 |
1 files changed, 71 insertions, 31 deletions
diff --git a/lisp/term/haiku-win.el b/lisp/term/haiku-win.el index 024459e6475..f73c8b71252 100644 --- a/lisp/term/haiku-win.el +++ b/lisp/term/haiku-win.el | |||
| @@ -174,6 +174,30 @@ VALUE as a unibyte string, or nil if VALUE was not a string." | |||
| 174 | (insert "\n"))) | 174 | (insert "\n"))) |
| 175 | (buffer-string)))))) | 175 | (buffer-string)))))) |
| 176 | 176 | ||
| 177 | (defun haiku-get-numeric-enum (name) | ||
| 178 | "Return the numeric value of the system enumerator NAME." | ||
| 179 | (or (get name 'haiku-numeric-enum) | ||
| 180 | (let ((value 0) | ||
| 181 | (offset 0) | ||
| 182 | (string (symbol-name name))) | ||
| 183 | (cl-loop for octet across string | ||
| 184 | do (progn | ||
| 185 | (when (or (< octet 0) | ||
| 186 | (> octet 255)) | ||
| 187 | (error "Out of range octet: %d" octet)) | ||
| 188 | (setq value | ||
| 189 | (logior value | ||
| 190 | (lsh octet | ||
| 191 | (- (* (1- (length string)) 8) | ||
| 192 | offset)))) | ||
| 193 | (setq offset (+ offset 8)))) | ||
| 194 | (prog1 value | ||
| 195 | (put name 'haiku-enumerator-id value))))) | ||
| 196 | |||
| 197 | (defmacro haiku-numeric-enum (name) | ||
| 198 | "Expand to the numeric value NAME as a system identifier." | ||
| 199 | (haiku-get-numeric-enum name)) | ||
| 200 | |||
| 177 | (declare-function x-open-connection "haikufns.c") | 201 | (declare-function x-open-connection "haikufns.c") |
| 178 | (declare-function x-handle-args "common-win") | 202 | (declare-function x-handle-args "common-win") |
| 179 | (declare-function haiku-selection-data "haikuselect.c") | 203 | (declare-function haiku-selection-data "haikuselect.c") |
| @@ -237,7 +261,7 @@ under the type `text/plain;charset=iso-8859-1'." | |||
| 237 | (buffer-substring (nth 0 bounds) | 261 | (buffer-substring (nth 0 bounds) |
| 238 | (nth 1 bounds))))))) | 262 | (nth 1 bounds))))))) |
| 239 | (when (and (stringp value) (not (string-empty-p value))) | 263 | (when (and (stringp value) (not (string-empty-p value))) |
| 240 | (list "text/plain;charset=iso-8859-1" 1296649541 | 264 | (list "text/plain;charset=iso-8859-1" (haiku-numeric-enum MIME) |
| 241 | (encode-coding-string value 'iso-latin-1)))) | 265 | (encode-coding-string value 'iso-latin-1)))) |
| 242 | 266 | ||
| 243 | (defun haiku-select-encode-utf-8-string (_selection value) | 267 | (defun haiku-select-encode-utf-8-string (_selection value) |
| @@ -251,7 +275,7 @@ VALUE will be encoded as UTF-8 and stored under the type | |||
| 251 | (buffer-substring (nth 0 bounds) | 275 | (buffer-substring (nth 0 bounds) |
| 252 | (nth 1 bounds))))))) | 276 | (nth 1 bounds))))))) |
| 253 | (when (and (stringp value) (not (string-empty-p value))) | 277 | (when (and (stringp value) (not (string-empty-p value))) |
| 254 | (list "text/plain" 1296649541 | 278 | (list "text/plain" (haiku-numeric-enum MIME) |
| 255 | (encode-coding-string value 'utf-8-unix)))) | 279 | (encode-coding-string value 'utf-8-unix)))) |
| 256 | 280 | ||
| 257 | (defun haiku-select-encode-file-name (_selection value) | 281 | (defun haiku-select-encode-file-name (_selection value) |
| @@ -304,6 +328,21 @@ or a pair of markers) and turns it into a file system reference." | |||
| 304 | (file-name-nondirectory default-filename))) | 328 | (file-name-nondirectory default-filename))) |
| 305 | (error "x-file-dialog on a tty frame"))) | 329 | (error "x-file-dialog on a tty frame"))) |
| 306 | 330 | ||
| 331 | (defun haiku-parse-drag-actions (message) | ||
| 332 | "Given the drag-and-drop message MESSAGE, retrieve the desired action." | ||
| 333 | (let ((actions (cddr (assoc "be:actions" message))) | ||
| 334 | (sorted nil)) | ||
| 335 | (dolist (action (list (haiku-numeric-enum DDCP) | ||
| 336 | (haiku-numeric-enum DDMV) | ||
| 337 | (haiku-numeric-enum DDLN))) | ||
| 338 | (when (member action actions) | ||
| 339 | (push sorted action))) | ||
| 340 | (cond | ||
| 341 | ((eql (car sorted) (haiku-numeric-enum DDCP)) 'copy) | ||
| 342 | ((eql (car sorted) (haiku-numeric-enum DDMV)) 'move) | ||
| 343 | ((eql (car sorted) (haiku-numeric-enum DDLN)) 'link) | ||
| 344 | (t 'private)))) | ||
| 345 | |||
| 307 | (defun haiku-drag-and-drop (event) | 346 | (defun haiku-drag-and-drop (event) |
| 308 | "Handle specified drag-n-drop EVENT." | 347 | "Handle specified drag-n-drop EVENT." |
| 309 | (interactive "e") | 348 | (interactive "e") |
| @@ -311,34 +350,35 @@ or a pair of markers) and turns it into a file system reference." | |||
| 311 | (window (posn-window (event-start event)))) | 350 | (window (posn-window (event-start event)))) |
| 312 | (if (eq string 'lambda) ; This means the mouse moved. | 351 | (if (eq string 'lambda) ; This means the mouse moved. |
| 313 | (dnd-handle-movement (event-start event)) | 352 | (dnd-handle-movement (event-start event)) |
| 314 | (cond | 353 | (let ((action (haiku-parse-drag-actions string))) |
| 315 | ;; Don't allow dropping on something other than the text area. | 354 | (cond |
| 316 | ;; It does nothing and doesn't work with text anyway. | 355 | ;; Don't allow dropping on something other than the text area. |
| 317 | ((posn-area (event-start event))) | 356 | ;; It does nothing and doesn't work with text anyway. |
| 318 | ((assoc "refs" string) | 357 | ((posn-area (event-start event))) |
| 319 | (with-selected-window window | 358 | ((assoc "refs" string) |
| 320 | (dolist (filename (cddr (assoc "refs" string))) | 359 | (with-selected-window window |
| 321 | (dnd-handle-one-url window 'private | 360 | (dolist (filename (cddr (assoc "refs" string))) |
| 322 | (concat "file:" filename))))) | 361 | (dnd-handle-one-url window action |
| 323 | ((assoc "text/uri-list" string) | 362 | (concat "file:" filename))))) |
| 324 | (dolist (text (cddr (assoc "text/uri-list" string))) | 363 | ((assoc "text/uri-list" string) |
| 325 | (let ((uri-list (split-string text "[\0\r\n]" t))) | 364 | (dolist (text (cddr (assoc "text/uri-list" string))) |
| 326 | (dolist (bf uri-list) | 365 | (let ((uri-list (split-string text "[\0\r\n]" t))) |
| 327 | (dnd-handle-one-url window 'private bf))))) | 366 | (dolist (bf uri-list) |
| 328 | ((assoc "text/plain" string) | 367 | (dnd-handle-one-url window action bf))))) |
| 329 | (with-selected-window window | 368 | ((assoc "text/plain" string) |
| 330 | (dolist (text (cddr (assoc "text/plain" string))) | 369 | (with-selected-window window |
| 331 | (unless mouse-yank-at-point | 370 | (dolist (text (cddr (assoc "text/plain" string))) |
| 332 | (goto-char (posn-point (event-start event)))) | 371 | (unless mouse-yank-at-point |
| 333 | (dnd-insert-text window 'private | 372 | (goto-char (posn-point (event-start event)))) |
| 334 | (if (multibyte-string-p text) | 373 | (dnd-insert-text window action |
| 335 | text | 374 | (if (multibyte-string-p text) |
| 336 | (decode-coding-string text 'undecided)))))) | 375 | text |
| 337 | ((not (eq (cdr (assq 'type string)) | 376 | (decode-coding-string text 'undecided)))))) |
| 338 | 3003)) ; Type of the placeholder message Emacs uses | 377 | ((not (eq (cdr (assq 'type string)) |
| 339 | ; to cancel a drop on C-g. | 378 | 3003)) ; Type of the placeholder message Emacs uses |
| 340 | (message "Don't know how to drop any of: %s" | 379 | ; to cancel a drop on C-g. |
| 341 | (mapcar #'car string))))))) | 380 | (message "Don't know how to drop any of: %s" |
| 381 | (mapcar #'car string)))))))) | ||
| 342 | 382 | ||
| 343 | (define-key special-event-map [drag-n-drop] 'haiku-drag-and-drop) | 383 | (define-key special-event-map [drag-n-drop] 'haiku-drag-and-drop) |
| 344 | 384 | ||
| @@ -393,7 +433,7 @@ take effect on menu items until the menu bar is updated again." | |||
| 393 | ;; Add B_MIME_TYPE to the message if the type was not | 433 | ;; Add B_MIME_TYPE to the message if the type was not |
| 394 | ;; previously specified, or the type if it was. | 434 | ;; previously specified, or the type if it was. |
| 395 | (push (or (get-text-property 0 'type maybe-string) | 435 | (push (or (get-text-property 0 'type maybe-string) |
| 396 | 1296649541) | 436 | (haiku-numeric-enum MIME)) |
| 397 | (alist-get (car selection-result) message | 437 | (alist-get (car selection-result) message |
| 398 | nil nil #'equal)))) | 438 | nil nil #'equal)))) |
| 399 | (if (not (consp (cadr selection-result))) | 439 | (if (not (consp (cadr selection-result))) |