emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master effbd2aeef: Fix file drag-and-drop on GNUstep


From: Po Lu
Subject: master effbd2aeef: Fix file drag-and-drop on GNUstep
Date: Sat, 4 Jun 2022 04:19:21 -0400 (EDT)

branch: master
commit effbd2aeef3d6ec3d09d40ff095e072b2d9834d4
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    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.
---
 src/nsselect.m | 10 +++++++++-
 src/nsterm.m   | 33 +++++++++++++++++++++++----------
 2 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/nsselect.m b/src/nsselect.m
index a719eef4e8..6831090aa2 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 04475bbba0..4663ac85d8 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);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]