Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class TextSelectionCursorController implements ViewTreeObserver.OnTouchMo
public final int ACTION_COPY = 1;
public final int ACTION_PASTE = 2;
public final int ACTION_MORE = 3;
public final int ACTION_SELECT_ALL = 4;

public TextSelectionCursorController(TerminalView terminalView) {
this.terminalView = terminalView;
Expand Down Expand Up @@ -101,7 +102,7 @@ public void setInitialTextSelectionPosition(MotionEvent event) {
}
}
}

public void setActionModeCallBacks() {
final ActionMode.Callback callback = new ActionMode.Callback() {
@Override
Expand All @@ -111,6 +112,7 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {
ClipboardManager clipboard = (ClipboardManager) terminalView.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
menu.add(Menu.NONE, ACTION_COPY, Menu.NONE, R.string.copy_text).setShowAsAction(show);
menu.add(Menu.NONE, ACTION_PASTE, Menu.NONE, R.string.paste_text).setEnabled(clipboard != null && clipboard.hasPrimaryClip()).setShowAsAction(show);
menu.add(Menu.NONE, ACTION_SELECT_ALL, Menu.NONE, R.string.select_all_text).setShowAsAction(show);
menu.add(Menu.NONE, ACTION_MORE, Menu.NONE, R.string.text_selection_more);
return true;
}
Expand All @@ -137,6 +139,9 @@ public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
terminalView.stopTextSelectionMode();
terminalView.mTermSession.onPasteTextFromClipboard();
break;
case ACTION_SELECT_ALL:
selectAll();
break;
case ACTION_MORE:
// We first store the selected text in case TerminalViewClient needs the
// selected text before MORE button was pressed since we are going to
Expand Down Expand Up @@ -345,19 +350,46 @@ public boolean isActive() {
return mIsSelectingText;
}

/**
* Select All Text
*/
public void selectAll() {
TerminalBuffer screen = terminalView.mEmulator.getScreen();
final int scrollRows = screen.getActiveRows() - terminalView.mEmulator.mRows;

mSelX1 = 0;
mSelY1 = -scrollRows;
mSelX2 = terminalView.mEmulator.mColumns - 1;
mSelY2 = terminalView.mEmulator.mRows - 1;

mStartHandle.positionAtCursor(mSelX1, mSelY1, true);
mEndHandle.positionAtCursor(mSelX2 + 1, mSelY2, true);

terminalView.invalidate();

/** Get the currently selected text. */
if (mActionMode != null) {
mActionMode.invalidate();
}
}

/**
* Get the currently selected text.
*/
public String getSelectedText() {
return terminalView.mEmulator.getSelectedText(mSelX1, mSelY1, mSelX2, mSelY2);
}

/** Get the selected text stored before "MORE" button was pressed on the context menu. */
/**
* Get the selected text stored before "MORE" button was pressed on the context menu.
*/
@Nullable
public String getStoredSelectedText() {
return mStoredSelectedText;
}

/** Unset the selected text stored before "MORE" button was pressed on the context menu. */
/**
* Unset the selected text stored before "MORE" button was pressed on the context menu.
*/
public void unsetStoredSelectedText() {
mStoredSelectedText = null;
}
Expand Down
1 change: 1 addition & 0 deletions terminal-view/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<string name="paste_text">Paste</string>
<string name="copy_text">Copy</string>
<string name="text_selection_more">More…</string>
<string name="select_all_text">Select All</string>
</resources>