summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-06-04 16:19:01 +0800
committerPo Lu <luangruo@yahoo.com>2022-06-04 16:19:01 +0800
commiteffbd2aeef3d6ec3d09d40ff095e072b2d9834d4 (patch)
treec1e9b43ffd0477923fc695e519833fd1748ba9b0
parent2ce686c049a7a35cdc3eb87626d8a94539388a35 (diff)
downloademacs-effbd2aeef3d6ec3d09d40ff095e072b2d9834d4.tar.gz
emacs-effbd2aeef3d6ec3d09d40ff095e072b2d9834d4.tar.bz2
emacs-effbd2aeef3d6ec3d09d40ff095e072b2d9834d4.zip
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.
-rw-r--r--src/nsselect.m10
-rw-r--r--src/nsterm.m33
2 files changed, 32 insertions, 11 deletions
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);