]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid macOS NSFilenamesPboardType warning (bug#33035)
authorMattias Engdegård <mattiase@acm.org>
Sun, 10 Jan 2021 16:05:18 +0000 (17:05 +0100)
committerMattias Engdegård <mattiase@acm.org>
Mon, 18 Jan 2021 11:52:08 +0000 (12:52 +0100)
* src/nsterm.h (NS_USE_NSPasteboardTypeFileURL): New #define.
* src/nsterm.m (ns_term_init):
([EmacsView performDragOperation:]):
* src/nsselect.m (ns_string_to_symbol):
(nxatoms_of_nsselect):
NSFilenamesPboardType was deprecated in macOS 10.14; use
NSPasteboardTypeFileURL instead when available.

src/nsselect.m
src/nsterm.h
src/nsterm.m

index 27db9248e466461745bfe9f1dbf5bedeb5f1a0cf..5ab3ef77fec2e44ec41588eebc1948280a92b2a9 100644 (file)
@@ -78,7 +78,13 @@ ns_string_to_symbol (NSString *t)
     return QSECONDARY;
   if ([t isEqualToString: NSPasteboardTypeString])
     return QTEXT;
-  if ([t isEqualToString: NSFilenamesPboardType])
+  if ([t isEqualToString:
+#if NS_USE_NSPasteboardTypeFileURL != 0
+           NSPasteboardTypeFileURL
+#else
+           NSFilenamesPboardType
+#endif
+       ])
     return QFILE_NAME;
   if ([t isEqualToString: NSPasteboardTypeTabularText])
     return QTEXT;
@@ -467,7 +473,12 @@ nxatoms_of_nsselect (void)
             [NSNumber numberWithLong:0], NXPrimaryPboard,
             [NSNumber numberWithLong:0], NXSecondaryPboard,
             [NSNumber numberWithLong:0], NSPasteboardTypeString,
-            [NSNumber numberWithLong:0], NSFilenamesPboardType,
+            [NSNumber numberWithLong:0],
+#if NS_USE_NSPasteboardTypeFileURL != 0
+                                          NSPasteboardTypeFileURL,
+#else
+                                          NSFilenamesPboardType,
+#endif
             [NSNumber numberWithLong:0], NSPasteboardTypeTabularText,
         nil] retain];
 }
index 2c9d8e85ba9b48d482abb3c3bbac4ec8f47ec9e7..eae1d0725ea17333d81ba04028ee65658429a266 100644 (file)
@@ -39,6 +39,15 @@ typedef CGFloat EmacsCGFloat;
 typedef float EmacsCGFloat;
 #endif
 
+/* NSFilenamesPboardType is deprecated in macOS 10.14, but
+   NSPasteboardTypeFileURL is only available in 10.13 (and GNUstep
+   probably lacks it too). */
+#if defined NS_IMPL_COCOA && MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
+#define NS_USE_NSPasteboardTypeFileURL 1
+#else
+#define NS_USE_NSPasteboardTypeFileURL 0
+#endif
+
 /* ==========================================================================
 
    Trace support
index 2defb9e2eec1001cd98f4452d6a30ffae1274185..c5815ce8d1057c3c64b02ae1d40d208caf95bef9 100644 (file)
@@ -5602,7 +5602,11 @@ ns_term_init (Lisp_Object display_name)
   ns_drag_types = [[NSArray arrayWithObjects:
                             NSPasteboardTypeString,
                             NSPasteboardTypeTabularText,
+#if NS_USE_NSPasteboardTypeFileURL != 0
+                            NSPasteboardTypeFileURL,
+#else
                             NSFilenamesPboardType,
+#endif
                             NSPasteboardTypeURL, nil] retain];
 
   /* If fullscreen is in init/default-frame-alist, focus isn't set
@@ -8533,9 +8537,19 @@ not_in_argv (NSString *arg)
     {
       return NO;
     }
-  /* FIXME: NSFilenamesPboardType is deprecated in 10.14, but the
-     NSURL method can only handle one file at a time.  Stick with the
-     existing code at the moment.  */
+#if NS_USE_NSPasteboardTypeFileURL != 0
+  else if ([type isEqualToString: NSPasteboardTypeFileURL])
+    {
+      type_sym = Qfile;
+
+      NSArray *urls = [pb readObjectsForClasses: @[[NSURL self]]
+                                        options: nil];
+      NSEnumerator *uenum = [urls objectEnumerator];
+      NSURL *url;
+      while ((url = [uenum nextObject]))
+        strings = Fcons ([[url path] lispString], strings);
+    }
+#else  // !NS_USE_NSPasteboardTypeFileURL
   else if ([type isEqualToString: NSFilenamesPboardType])
     {
       NSArray *files;
@@ -8551,6 +8565,7 @@ not_in_argv (NSString *arg)
       while ( (file = [fenum nextObject]) )
         strings = Fcons ([file lispString], strings);
     }
+#endif   // !NS_USE_NSPasteboardTypeFileURL
   else if ([type isEqualToString: NSPasteboardTypeURL])
     {
       NSURL *url = [NSURL URLFromPasteboard: pb];