summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2023-10-21 14:24:25 +0800
committerPo Lu <luangruo@yahoo.com>2023-10-21 14:25:02 +0800
commit9ad22b3a01826539a832da54f2a55b68186dc7cc (patch)
tree9d6b80417047de8ff2e358af78ea1bc547f6987c /java
parent8faffc26a623cee5cd46565ad519fef8ceb1eacb (diff)
downloademacs-9ad22b3a01826539a832da54f2a55b68186dc7cc.tar.gz
Facilitate opening multiple files through DND under Android
* java/org/gnu/emacs/EmacsWindow.java (onDragEvent): Agglomerate each provided content URI into a text/uri list.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsWindow.java69
1 files changed, 43 insertions, 26 deletions
diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java
index 386eaca8c41..7662186a0eb 100644
--- a/java/org/gnu/emacs/EmacsWindow.java
+++ b/java/org/gnu/emacs/EmacsWindow.java
@@ -1605,6 +1605,7 @@ public final class EmacsWindow extends EmacsHandleObject
String type;
Uri uri;
EmacsActivity activity;
+ StringBuilder builder;
x = (int) event.getX ();
y = (int) event.getY ();
@@ -1659,38 +1660,54 @@ public final class EmacsWindow extends EmacsHandleObject
EmacsNative.sendDndUri (handle, x, y, type);
return true;
}
- else
- {
- /* If the item dropped is a URI, send it to the main
- thread. */
-
- uri = data.getItemAt (0).getUri ();
+ }
- /* Attempt to acquire permissions for this URI;
- failing which, insert it as text instead. */
+ /* There's no plain text data within this clipboard item, so
+ each item within should be treated as a content URI
+ designating a file. */
- if (uri != null
- && uri.getScheme () != null
- && uri.getScheme ().equals ("content")
- && (activity = EmacsActivity.lastFocusedActivity) != null)
- {
- if (activity.requestDragAndDropPermissions (event) == null)
- uri = null;
- }
+ /* Collect the URIs into a string with each suffixed
+ by newlines, much as in a text/uri-list. */
+ builder = new StringBuilder ();
- if (uri != null)
- EmacsNative.sendDndUri (handle, x, y, uri.toString ());
- else
- {
- type = (data.getItemAt (0)
- .coerceToText (EmacsService.SERVICE)
- .toString ());
- EmacsNative.sendDndText (handle, x, y, type);
- }
+ for (i = 0; i < itemCount; ++i)
+ {
+ /* If the item dropped is a URI, send it to the
+ main thread. */
+
+ uri = data.getItemAt (i).getUri ();
+
+ /* Attempt to acquire permissions for this URI;
+ failing which, insert it as text instead. */
+
+ if (uri != null
+ && uri.getScheme () != null
+ && uri.getScheme ().equals ("content")
+ && (activity = EmacsActivity.lastFocusedActivity) != null)
+ {
+ if ((activity.requestDragAndDropPermissions (event) == null))
+ uri = null;
+ }
- return true;
+ if (uri != null)
+ builder.append (uri.toString ()).append ("\n");
+ else
+ {
+ /* Treat each URI that Emacs cannot secure
+ permissions for as plain text. */
+ type = (data.getItemAt (i)
+ .coerceToText (EmacsService.SERVICE)
+ .toString ());
+ EmacsNative.sendDndText (handle, x, y, type);
}
}
+
+ /* Now send each URI to Emacs. */
+
+ if (builder.length () > 0)
+ EmacsNative.sendDndUri (handle, x, y, builder.toString ());
+
+ return true;
}
return true;