emacs-diffs
[Top][All Lists]
Advanced

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

master e72f17e4622: Respect file display names during Android drag-and-d


From: Po Lu
Subject: master e72f17e4622: Respect file display names during Android drag-and-drop
Date: Tue, 19 Mar 2024 22:23:55 -0400 (EDT)

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

    Respect file display names during Android drag-and-drop
    
    * java/org/gnu/emacs/EmacsService.java (buildContentName):
    Remove redundant projection argument to resolver.query.
    
    * java/org/gnu/emacs/EmacsWindow.java (onDragEvent): If a
    content resolver is available, attempt to convert content URIs
    into file names in advance.
    
    * lisp/term/android-win.el (android-handle-dnd-event): Adjust
    correspondingly.
---
 java/org/gnu/emacs/EmacsService.java |  4 +---
 java/org/gnu/emacs/EmacsWindow.java  | 18 +++++++++++++++++-
 lisp/term/android-win.el             | 37 ++++++++++++++++++++----------------
 3 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/java/org/gnu/emacs/EmacsService.java 
b/java/org/gnu/emacs/EmacsService.java
index 19aa3dee456..785163c713c 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -1072,7 +1072,6 @@ public final class EmacsService extends Service
   {
     StringBuilder builder;
     String displayName;
-    String[] projection;
     Cursor cursor;
     int column;
 
@@ -1081,8 +1080,7 @@ public final class EmacsService extends Service
 
     try
       {
-       projection = new String[] { OpenableColumns.DISPLAY_NAME, };
-       cursor = resolver.query (uri, projection, null, null, null);
+       cursor = resolver.query (uri, null, null, null, null);
 
        if (cursor != null)
          {
diff --git a/java/org/gnu/emacs/EmacsWindow.java 
b/java/org/gnu/emacs/EmacsWindow.java
index 6e8bdaf7401..93a512cc7ef 100644
--- a/java/org/gnu/emacs/EmacsWindow.java
+++ b/java/org/gnu/emacs/EmacsWindow.java
@@ -31,6 +31,7 @@ import android.app.Activity;
 
 import android.content.ClipData;
 import android.content.ClipDescription;
+import android.content.ContentResolver;
 import android.content.Context;
 
 import android.graphics.Rect;
@@ -1699,10 +1700,11 @@ public final class EmacsWindow extends EmacsHandleObject
     ClipData data;
     ClipDescription description;
     int i, j, x, y, itemCount;
-    String type;
+    String type, uriString;
     Uri uri;
     EmacsActivity activity;
     StringBuilder builder;
+    ContentResolver resolver;
 
     x = (int) event.getX ();
     y = (int) event.getY ();
@@ -1799,6 +1801,20 @@ public final class EmacsWindow extends EmacsHandleObject
              {
                if ((activity.requestDragAndDropPermissions (event) == null))
                  uri = null;
+               else
+                 {
+                   resolver = activity.getContentResolver ();
+
+                   /* Substitute a content file name for the URI, if
+                      possible.  */
+                   uriString = EmacsService.buildContentName (uri, resolver);
+
+                   if (uriString != null)
+                     {
+                       builder.append (uriString).append ("\n");
+                       continue;
+                     }
+                 }
              }
 
            if (uri != null)
diff --git a/lisp/term/android-win.el b/lisp/term/android-win.el
index 1d10402b15d..8d262e5da98 100644
--- a/lisp/term/android-win.el
+++ b/lisp/term/android-win.el
@@ -282,11 +282,12 @@ If it reflects the motion of an item above a frame, call
 `dnd-handle-movement' to move the cursor or scroll the window
 under the item pursuant to the pertinent user options.
 
-If it reflects dropped text, insert such text within window at
-the location of the drop.
+If it holds dropped text, insert such text within window at the
+location of the drop.
 
-If it reflects a list of URIs, then open each URI, converting
-content:// URIs into the special file names which represent them."
+If it holds a list of URIs, or file names, then open each URI or
+file name, converting content:// URIs into the special file
+names which represent them."
   (interactive "e")
   (let ((message (caddr event))
         (posn (event-start event)))
@@ -304,18 +305,22 @@ content:// URIs into the special file names which 
represent them."
                  (new-uri-list nil)
                  (dnd-unescape-file-uris t))
              (dolist (uri uri-list)
-               (ignore-errors
-                 (let ((url (url-generic-parse-url uri)))
-                   (when (equal (url-type url) "content")
-                     ;; Replace URI with a matching /content file
-                     ;; name.
-                     (setq uri (format "file:/content/by-authority/%s%s"
-                                       (url-host url)
-                                       (url-filename url))
-                           ;; And guarantee that this file URI is not
-                           ;; subject to URI decoding, for it must be
-                           ;; transformed back into a content URI.
-                           dnd-unescape-file-uris nil))))
+               ;; If the URI is a preprepared file name, insert it directly.
+               (if (string-match-p "^/content/by-authority\\(-named\\)?/" uri)
+                   (setq uri (concat "file:" uri)
+                         dnd-unescape-file-uris nil)
+                 (ignore-errors
+                   (let ((url (url-generic-parse-url uri)))
+                     (when (equal (url-type url) "content")
+                       ;; Replace URI with a matching /content file
+                       ;; name.
+                       (setq uri (format "file:/content/by-authority/%s%s"
+                                         (url-host url)
+                                         (url-filename url))
+                             ;; And guarantee that this file URI is not
+                             ;; subject to URI decoding, for it must be
+                             ;; transformed back into a content URI.
+                             dnd-unescape-file-uris nil)))))
                (push uri new-uri-list))
              (dnd-handle-multiple-urls (posn-window posn)
                                        new-uri-list



reply via email to

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