Merge remote-tracking branch 'origin/GP-4631_Dan_TerminalSelectAll'

(#6502)
This commit is contained in:
Ryan Kurtz 2024-05-28 13:09:49 -04:00
commit 8361eb3e9d
2 changed files with 36 additions and 0 deletions

View File

@ -83,6 +83,13 @@
<B>CTRL-SHIFT-H</B> or <B>CTRL-SHIFT-G</B>, respectively. They repeat the last search in the
forward or backward direction.</P>
<H3><A name="select_all"></A>Select All</H3>
<P>This is accessed using the local drop-down menu or the key sequence <B>CTRL-SHIFT-A</B>. It
selects all text in the terminal, including its scrollback buffer. If all the text is already
selected, then this selects nothing, so that pressing the keystroke twice is effectively
"Select None."</P>
<H3><A name="terminate"></A>Terminate</H3>
<P>This action is accessed using the local drop-down menu. It will terminate the Terminal's

View File

@ -18,6 +18,7 @@ package ghidra.app.plugin.core.terminal;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.*;
@ -32,6 +33,7 @@ import docking.*;
import docking.action.DockingAction;
import docking.action.DockingActionIf;
import docking.action.builder.ActionBuilder;
import docking.widgets.EventTrigger;
import docking.widgets.OkDialog;
import docking.widgets.fieldpanel.support.*;
import generic.theme.GColor;
@ -163,6 +165,7 @@ public class TerminalProvider extends ComponentProviderAdapter {
protected DockingAction actionFind;
protected DockingAction actionFindNext;
protected DockingAction actionFindPrevious;
protected DockingAction actionSelectAll;
protected DockingAction actionTerminate;
private boolean terminated = false;
@ -251,6 +254,14 @@ public class TerminalProvider extends ComponentProviderAdapter {
.enabledWhen(this::isEnabledFindStep)
.onAction(this::activatedFindPrevious)
.buildAndInstallLocal(this);
actionSelectAll = new ActionBuilder("Select All", plugin.getName())
.menuPath("Select All")
.menuGroup("Select")
.keyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_A,
InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK))
.helpLocation(new HelpLocation(helpPlugin.getName(), "select_all"))
.onAction(this::activatedSelectAll)
.buildAndInstallLocal(this);
}
protected void activatedFind(ActionContext ctx) {
@ -300,6 +311,24 @@ public class TerminalProvider extends ComponentProviderAdapter {
doFind(false);
}
protected void activatedSelectAll(ActionContext ctx) {
FieldSelection sel = new FieldSelection();
BigInteger numIndexes = panel.model.getNumIndexes();
if (numIndexes.equals(BigInteger.ZERO)) {
return;
}
BigInteger lastIndex = numIndexes.subtract(BigInteger.ONE);
TerminalLayout layout = panel.model.getLayout(lastIndex);
int lastCol = layout.line.length();
sel.addRange(
new FieldLocation(BigInteger.ZERO, 0, 0, 0),
new FieldLocation(lastIndex, 0, 0, lastCol));
if (panel.getFieldPanel().getSelection().equals(sel)) {
sel.clear();
}
panel.getFieldPanel().setSelection(sel, EventTrigger.GUI_ACTION);
}
/**
* Check if the given keystroke would activate a local action.
*