feat(gui): ctrl+c copy node string in search window (#293)

This commit is contained in:
Skylot
2022-02-18 19:09:00 +00:00
parent d3a0a56b8b
commit 25166970cc
@@ -6,6 +6,7 @@ import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
@@ -18,6 +19,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
@@ -143,12 +145,11 @@ public abstract class CommonSearchDialog extends JFrame {
}
protected void openSelectedItem() {
int selectedId = resultsTable.getSelectedRow();
if (selectedId == -1) {
JNode node = getSelectedNode();
if (node == null) {
return;
}
JumpPosition jmpPos;
JNode node = (JNode) resultsModel.getValueAt(selectedId, 0);
if (node instanceof JResSearchNode) {
jmpPos = new JumpPosition(((JResSearchNode) node).getResNode(), node.getLine(), node.getPos());
} else {
@@ -160,6 +161,15 @@ public abstract class CommonSearchDialog extends JFrame {
}
}
@Nullable
private JNode getSelectedNode() {
int selectedId = resultsTable.getSelectedRow();
if (selectedId == -1) {
return null;
}
return (JNode) resultsModel.getValueAt(selectedId, 0);
}
@Override
public void dispose() {
mainWindow.getSettings().saveWindowPos(this);
@@ -210,7 +220,6 @@ public abstract class CommonSearchDialog extends JFrame {
resultsTable.setShowHorizontalLines(false);
resultsTable.setDragEnabled(false);
resultsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// resultsTable.setBackground(CodeArea.CODE_BACKGROUND);
resultsTable.setColumnSelectionAllowed(false);
resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
resultsTable.setAutoscrolls(false);
@@ -238,6 +247,16 @@ public abstract class CommonSearchDialog extends JFrame {
}
}
});
// override copy action to copy long string of node column
resultsTable.getActionMap().put("copy", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
JNode selectedNode = getSelectedNode();
if (selectedNode != null) {
UiUtils.copyToClipboard(selectedNode.makeLongString());
}
}
});
warnLabel = new JLabel();
warnLabel.setForeground(Color.RED);