From: Po Lu Date: Sat, 4 Jun 2022 08:19:01 +0000 (+0800) Subject: Fix file drag-and-drop on GNUstep X-Git-Tag: emacs-29.0.90~1910^2~244 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=effbd2aeef3d6ec3d09d40ff095e072b2d9834d4;p=emacs.git Fix file drag-and-drop on GNUstep * src/nsselect.m (ns_decode_data_to_pasteboard): Convert URL to path names when we're using NSFilenamesPboardType. * src/nsterm.m: ([EmacsView performDragOperation:]): Handle cases where plist is a string. --- diff --git a/src/nsselect.m b/src/nsselect.m index a719eef4e86..6831090aa20 100644 --- a/src/nsselect.m +++ b/src/nsselect.m @@ -565,6 +565,9 @@ ns_decode_data_to_pasteboard (Lisp_Object type, Lisp_Object data, NSMutableArray *temp; Lisp_Object tem; specpdl_ref count; +#if !NS_USE_NSPasteboardTypeFileURL + NSURL *url; +#endif types = [pasteboard types]; count = SPECPDL_INDEX (); @@ -602,7 +605,12 @@ ns_decode_data_to_pasteboard (Lisp_Object type, Lisp_Object data, [pasteboard setString: [NSString stringWithLispString: data] forType: NSPasteboardTypeFileURL]; #else - [pasteboard setString: [NSString stringWithLispString: data] + url = [NSURL URLWithString: [NSString stringWithLispString: data]]; + + if (!url) + signal_error ("Invalid file URL", data); + + [pasteboard setString: [url path] forType: NSFilenamesPboardType]; #endif } diff --git a/src/nsterm.m b/src/nsterm.m index 04475bbba05..4663ac85d84 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -8724,7 +8724,7 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) Lisp_Object type_sym; struct input_event ie; - NSTRACE ("[EmacsView performDragOperation:]"); + NSTRACE (@"[EmacsView performDragOperation:]"); source = [sender draggingSource]; @@ -8752,7 +8752,7 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) if (!type) return NO; -#if NS_USE_NSPasteboardTypeFileURL != 0 +#if NS_USE_NSPasteboardTypeFileURL else if ([type isEqualToString: NSPasteboardTypeFileURL]) { type_sym = Qfile; @@ -8767,18 +8767,29 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) #else // !NS_USE_NSPasteboardTypeFileURL else if ([type isEqualToString: NSFilenamesPboardType]) { - NSArray *files; + id files; NSEnumerator *fenum; NSString *file; - if (!(files = [pb propertyListForType: type])) + files = [pb propertyListForType: type]; + + if (!files) return NO; type_sym = Qfile; - fenum = [files objectEnumerator]; - while ( (file = [fenum nextObject]) ) - strings = Fcons ([file lispString], strings); + /* On GNUstep, files might be a string. */ + + if ([files respondsToSelector: @selector (objectEnumerator:)]) + { + fenum = [files objectEnumerator]; + + while ((file = [fenum nextObject])) + strings = Fcons ([file lispString], strings); + } + else + /* Then `files' is an NSString. */ + strings = list1 ([files lispString]); } #endif // !NS_USE_NSPasteboardTypeFileURL else if ([type isEqualToString: NSPasteboardTypeURL]) @@ -8795,11 +8806,12 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) { NSString *data; - if (! (data = [pb stringForType: type])) + data = [pb stringForType: type]; + + if (!data) return NO; type_sym = Qnil; - strings = list1 ([data lispString]); } else @@ -8807,7 +8819,8 @@ ns_create_font_panel_buttons (id target, SEL select, SEL cancel_action) EVENT_INIT (ie); ie.kind = DRAG_N_DROP_EVENT; - ie.arg = Fcons (type_sym, Fcons (operations, strings)); + ie.arg = Fcons (type_sym, Fcons (operations, + strings)); XSETINT (ie.x, x); XSETINT (ie.y, y); XSETFRAME (ie.frame_or_window, emacsframe);