mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 10:45:23 +08:00
Add PASTE
extra key for pasting text from clipboard
This commit is contained in:
@@ -162,13 +162,25 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClipboardText(TerminalSession session, String text) {
|
public void onCopyTextToClipboard(TerminalSession session, String text) {
|
||||||
if (!mActivity.isVisible()) return;
|
if (!mActivity.isVisible()) return;
|
||||||
|
|
||||||
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
clipboard.setPrimaryClip(new ClipData(null, new String[]{"text/plain"}, new ClipData.Item(text)));
|
clipboard.setPrimaryClip(new ClipData(null, new String[]{"text/plain"}, new ClipData.Item(text)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasteTextFromClipboard(TerminalSession session) {
|
||||||
|
if (!mActivity.isVisible()) return;
|
||||||
|
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
ClipData clipData = clipboard.getPrimaryClip();
|
||||||
|
if (clipData != null) {
|
||||||
|
CharSequence paste = clipData.getItemAt(0).coerceToText(mActivity);
|
||||||
|
if (!TextUtils.isEmpty(paste)) mActivity.getTerminalView().mEmulator.paste(paste.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBell(TerminalSession session) {
|
public void onBell(TerminalSession session) {
|
||||||
if (!mActivity.isVisible()) return;
|
if (!mActivity.isVisible()) return;
|
||||||
|
@@ -45,6 +45,7 @@ public class TerminalToolbarViewPager {
|
|||||||
layout = inflater.inflate(R.layout.view_terminal_toolbar_extra_keys, collection, false);
|
layout = inflater.inflate(R.layout.view_terminal_toolbar_extra_keys, collection, false);
|
||||||
ExtraKeysView extraKeysView = (ExtraKeysView) layout;
|
ExtraKeysView extraKeysView = (ExtraKeysView) layout;
|
||||||
extraKeysView.setTermuxTerminalViewClient(mActivity.getTermuxTerminalViewClient());
|
extraKeysView.setTermuxTerminalViewClient(mActivity.getTermuxTerminalViewClient());
|
||||||
|
extraKeysView.setTermuxTerminalSessionClient(mActivity.getTermuxTerminalSessionClient());
|
||||||
mActivity.setExtraKeysView(extraKeysView);
|
mActivity.setExtraKeysView(extraKeysView);
|
||||||
extraKeysView.reload(mActivity.getProperties().getExtraKeysInfo());
|
extraKeysView.reload(mActivity.getProperties().getExtraKeysInfo());
|
||||||
|
|
||||||
|
@@ -116,6 +116,8 @@ public class ExtraKeysInfo {
|
|||||||
put("DEL", "⌦"); // U+2326 ⌦ ERASE TO THE RIGHT not well known but easy to understand
|
put("DEL", "⌦"); // U+2326 ⌦ ERASE TO THE RIGHT not well known but easy to understand
|
||||||
put("DRAWER", "☰"); // U+2630 ☰ TRIGRAM FOR HEAVEN not well known but easy to understand
|
put("DRAWER", "☰"); // U+2630 ☰ TRIGRAM FOR HEAVEN not well known but easy to understand
|
||||||
put("KEYBOARD", "⌨"); // U+2328 ⌨ KEYBOARD not well known but easy to understand
|
put("KEYBOARD", "⌨"); // U+2328 ⌨ KEYBOARD not well known but easy to understand
|
||||||
|
//put("PASTE", "📋"); // U+2328 ⌨ KEYBOARD not well known but easy to understand
|
||||||
|
put("PASTE", "⎘"); // U+2328 ⌨ KEYBOARD not well known but easy to understand
|
||||||
}};
|
}};
|
||||||
|
|
||||||
static final CharDisplayMap lessKnownCharactersDisplay = new CharDisplayMap() {{
|
static final CharDisplayMap lessKnownCharactersDisplay = new CharDisplayMap() {{
|
||||||
|
@@ -28,6 +28,7 @@ import android.widget.GridLayout;
|
|||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
|
|
||||||
import com.termux.R;
|
import com.termux.R;
|
||||||
|
import com.termux.app.terminal.TermuxTerminalSessionClient;
|
||||||
import com.termux.app.terminal.TermuxTerminalViewClient;
|
import com.termux.app.terminal.TermuxTerminalViewClient;
|
||||||
import com.termux.view.TerminalView;
|
import com.termux.view.TerminalView;
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
private static final int BUTTON_PRESSED_COLOR = 0xFF7F7F7F;
|
private static final int BUTTON_PRESSED_COLOR = 0xFF7F7F7F;
|
||||||
|
|
||||||
TermuxTerminalViewClient mTermuxTerminalViewClient;
|
TermuxTerminalViewClient mTermuxTerminalViewClient;
|
||||||
|
TermuxTerminalSessionClient mTermuxTerminalSessionClient;
|
||||||
|
|
||||||
public ExtraKeysView(Context context, AttributeSet attrs) {
|
public ExtraKeysView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@@ -89,6 +91,9 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
} else if ("DRAWER".equals(keyName)) {
|
} else if ("DRAWER".equals(keyName)) {
|
||||||
DrawerLayout drawer = view.findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = view.findViewById(R.id.drawer_layout);
|
||||||
drawer.openDrawer(Gravity.LEFT);
|
drawer.openDrawer(Gravity.LEFT);
|
||||||
|
} else if ("PASTE".equals(keyName)) {
|
||||||
|
if(mTermuxTerminalSessionClient != null)
|
||||||
|
mTermuxTerminalSessionClient.onPasteTextFromClipboard(null);
|
||||||
} else if (keyCodesForString.containsKey(keyName)) {
|
} else if (keyCodesForString.containsKey(keyName)) {
|
||||||
Integer keyCode = keyCodesForString.get(keyName);
|
Integer keyCode = keyCodesForString.get(keyName);
|
||||||
if (keyCode == null) return;
|
if (keyCode == null) return;
|
||||||
@@ -389,4 +394,8 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
this.mTermuxTerminalViewClient = termuxTerminalViewClient;
|
this.mTermuxTerminalViewClient = termuxTerminalViewClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTermuxTerminalSessionClient(TermuxTerminalSessionClient termuxTerminalSessionClient) {
|
||||||
|
this.mTermuxTerminalSessionClient = termuxTerminalSessionClient;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1980,7 +1980,7 @@ public final class TerminalEmulator {
|
|||||||
int startIndex = textParameter.indexOf(";") + 1;
|
int startIndex = textParameter.indexOf(";") + 1;
|
||||||
try {
|
try {
|
||||||
String clipboardText = new String(Base64.decode(textParameter.substring(startIndex), 0), StandardCharsets.UTF_8);
|
String clipboardText = new String(Base64.decode(textParameter.substring(startIndex), 0), StandardCharsets.UTF_8);
|
||||||
mSession.clipboardText(clipboardText);
|
mSession.onCopyTextToClipboard(clipboardText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mClient.logError(LOG_TAG, "OSC Manipulate selection, invalid string '" + textParameter + "");
|
mClient.logError(LOG_TAG, "OSC Manipulate selection, invalid string '" + textParameter + "");
|
||||||
}
|
}
|
||||||
|
@@ -18,8 +18,11 @@ public abstract class TerminalOutput {
|
|||||||
/** Notify the terminal client that the terminal title has changed. */
|
/** Notify the terminal client that the terminal title has changed. */
|
||||||
public abstract void titleChanged(String oldTitle, String newTitle);
|
public abstract void titleChanged(String oldTitle, String newTitle);
|
||||||
|
|
||||||
/** Notify the terminal client that the terminal title has changed. */
|
/** Notify the terminal client that text should be copied to clipboard. */
|
||||||
public abstract void clipboardText(String text);
|
public abstract void onCopyTextToClipboard(String text);
|
||||||
|
|
||||||
|
/** Notify the terminal client that text should be pasted from clipboard. */
|
||||||
|
public abstract void onPasteTextFromClipboard();
|
||||||
|
|
||||||
/** Notify the terminal client that a bell character (ASCII 7, bell, BEL, \a, ^G)) has been received. */
|
/** Notify the terminal client that a bell character (ASCII 7, bell, BEL, \a, ^G)) has been received. */
|
||||||
public abstract void onBell();
|
public abstract void onBell();
|
||||||
|
@@ -269,8 +269,13 @@ public final class TerminalSession extends TerminalOutput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clipboardText(String text) {
|
public void onCopyTextToClipboard(String text) {
|
||||||
mClient.onClipboardText(this, text);
|
mClient.onCopyTextToClipboard(this, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasteTextFromClipboard() {
|
||||||
|
mClient.onPasteTextFromClipboard(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -13,7 +13,9 @@ public interface TerminalSessionClient {
|
|||||||
|
|
||||||
void onSessionFinished(TerminalSession finishedSession);
|
void onSessionFinished(TerminalSession finishedSession);
|
||||||
|
|
||||||
void onClipboardText(TerminalSession session, String text);
|
void onCopyTextToClipboard(TerminalSession session, String text);
|
||||||
|
|
||||||
|
void onPasteTextFromClipboard(TerminalSession session);
|
||||||
|
|
||||||
void onBell(TerminalSession session);
|
void onBell(TerminalSession session);
|
||||||
|
|
||||||
|
@@ -37,10 +37,14 @@ public abstract class TerminalTestCase extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clipboardText(String text) {
|
public void onCopyTextToClipboard(String text) {
|
||||||
clipboardPuts.add(text);
|
clipboardPuts.add(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasteTextFromClipboard() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBell() {
|
public void onBell() {
|
||||||
bellsRung++;
|
bellsRung++;
|
||||||
|
@@ -138,17 +138,12 @@ public class TextSelectionCursorController implements CursorController {
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case ACTION_COPY:
|
case ACTION_COPY:
|
||||||
String selectedText = terminalView.mEmulator.getSelectedText(mSelX1, mSelY1, mSelX2, mSelY2).trim();
|
String selectedText = terminalView.mEmulator.getSelectedText(mSelX1, mSelY1, mSelX2, mSelY2).trim();
|
||||||
terminalView.mTermSession.clipboardText(selectedText);
|
terminalView.mTermSession.onCopyTextToClipboard(selectedText);
|
||||||
terminalView.stopTextSelectionMode();
|
terminalView.stopTextSelectionMode();
|
||||||
break;
|
break;
|
||||||
case ACTION_PASTE:
|
case ACTION_PASTE:
|
||||||
terminalView.stopTextSelectionMode();
|
terminalView.stopTextSelectionMode();
|
||||||
ClipboardManager clipboard = (ClipboardManager) terminalView.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
terminalView.mTermSession.onPasteTextFromClipboard();
|
||||||
ClipData clipData = clipboard.getPrimaryClip();
|
|
||||||
if (clipData != null) {
|
|
||||||
CharSequence paste = clipData.getItemAt(0).coerceToText(terminalView.getContext());
|
|
||||||
if (!TextUtils.isEmpty(paste)) terminalView.mEmulator.paste(paste.toString());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ACTION_MORE:
|
case ACTION_MORE:
|
||||||
terminalView.stopTextSelectionMode(); //we stop text selection first, otherwise handles will show above popup
|
terminalView.stopTextSelectionMode(); //we stop text selection first, otherwise handles will show above popup
|
||||||
|
@@ -22,7 +22,11 @@ public class TermuxTerminalSessionClientBase implements TerminalSessionClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClipboardText(TerminalSession session, String text) {
|
public void onCopyTextToClipboard(TerminalSession session, String text) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPasteTextFromClipboard(TerminalSession session) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user