aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-06-04 15:45:41 +0800
committerPo Lu2022-06-04 15:45:41 +0800
commit2ce686c049a7a35cdc3eb87626d8a94539388a35 (patch)
treef15e65e4c65ec8b2b43a3e017871457ba96e8da9 /src
parent1289d0c3dd964a501ea0b039c0ce9bc39ec47caa (diff)
downloademacs-2ce686c049a7a35cdc3eb87626d8a94539388a35.tar.gz
emacs-2ce686c049a7a35cdc3eb87626d8a94539388a35.zip
Support dragging multiple files on NS
This has to use a deprecated pasteboard type, since Emacs uses the "old" (but not deprecated) dragImage: method for drag-and-drop, which can't drop file URLs. * lisp/term/ns-win.el (x-begin-drag): Update accordingly. * src/nsselect.m (ns_decode_data_to_pasteboard): (Fns_begin_drag): Allow files to be a list of filenames as well.
Diffstat (limited to 'src')
-rw-r--r--src/nsselect.m50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/nsselect.m b/src/nsselect.m
index a4129b12f03..a719eef4e86 100644
--- a/src/nsselect.m
+++ b/src/nsselect.m
@@ -562,8 +562,12 @@ ns_decode_data_to_pasteboard (Lisp_Object type, Lisp_Object data,
562 NSPasteboard *pasteboard) 562 NSPasteboard *pasteboard)
563{ 563{
564 NSArray *types, *new; 564 NSArray *types, *new;
565 NSMutableArray *temp;
566 Lisp_Object tem;
567 specpdl_ref count;
565 568
566 types = [pasteboard types]; 569 types = [pasteboard types];
570 count = SPECPDL_INDEX ();
567 571
568 CHECK_SYMBOL (type); 572 CHECK_SYMBOL (type);
569 573
@@ -580,10 +584,11 @@ ns_decode_data_to_pasteboard (Lisp_Object type, Lisp_Object data,
580 } 584 }
581 else if (EQ (type, Qfile)) 585 else if (EQ (type, Qfile))
582 { 586 {
583 CHECK_STRING (data);
584
585#if NS_USE_NSPasteboardTypeFileURL 587#if NS_USE_NSPasteboardTypeFileURL
586 new = [types arrayByAddingObject: NSPasteboardTypeFileURL]; 588 if (CONSP (data))
589 new = [types arrayByAddingObject: NSPasteboardTypeURL];
590 else
591 new = [types arrayByAddingObject: NSPasteboardTypeFileURL];
587#else 592#else
588 new = [types arrayByAddingObject: NSFilenamesPboardType]; 593 new = [types arrayByAddingObject: NSFilenamesPboardType];
589#endif 594#endif
@@ -591,13 +596,41 @@ ns_decode_data_to_pasteboard (Lisp_Object type, Lisp_Object data,
591 [pasteboard declareTypes: new 596 [pasteboard declareTypes: new
592 owner: nil]; 597 owner: nil];
593 598
599 if (STRINGP (data))
600 {
594#if NS_USE_NSPasteboardTypeFileURL 601#if NS_USE_NSPasteboardTypeFileURL
595 [pasteboard setString: [NSString stringWithLispString: data] 602 [pasteboard setString: [NSString stringWithLispString: data]
596 forType: NSPasteboardTypeFileURL]; 603 forType: NSPasteboardTypeFileURL];
597#else 604#else
598 [pasteboard setString: [NSString stringWithLispString: data] 605 [pasteboard setString: [NSString stringWithLispString: data]
599 forType: NSFilenamesPboardType]; 606 forType: NSFilenamesPboardType];
607#endif
608 }
609 else
610 {
611 CHECK_LIST (data);
612 temp = [[NSMutableArray alloc] init];
613 record_unwind_protect_ptr (ns_release_object, temp);
614
615 for (tem = data; CONSP (tem); tem = XCDR (tem))
616 {
617 CHECK_STRING (XCAR (tem));
618
619 [temp addObject: [NSString stringWithLispString: XCAR (tem)]];
620 }
621 CHECK_LIST_END (tem, data);
622#if NS_USE_NSPasteboardTypeFileURL
623 [pasteboard setPropertyList: temp
624 /* We have to use this deprecated pasteboard
625 type, since Apple doesn't let us use
626 dragImage:at: to drag multiple file URLs. */
627 forType: @"NSFilenamesPboardType"];
628#else
629 [pasteboard setPropertyList: temp
630 forType: NSFilenamesPboardType];
600#endif 631#endif
632 unbind_to (count, Qnil);
633 }
601 } 634 }
602 else 635 else
603 signal_error ("Unknown pasteboard type", type); 636 signal_error ("Unknown pasteboard type", type);
@@ -673,7 +706,8 @@ the meaning of DATA:
673 be dragged to another program. 706 be dragged to another program.
674 707
675 - `file' means DATA should be a file URL that will be dragged to 708 - `file' means DATA should be a file URL that will be dragged to
676 another program. 709 another program. DATA may also be a list of file names; that
710 means each file in the list will be dragged to another program.
677 711
678ACTION is the action that will be taken by the drop target towards the 712ACTION is the action that will be taken by the drop target towards the
679data inside PBOARD. 713data inside PBOARD.