-
Notifications
You must be signed in to change notification settings - Fork 2
/
3163-Better-keyboard-handling-in-the-Language-dialog.patch
325 lines (308 loc) · 10.9 KB
/
3163-Better-keyboard-handling-in-the-Language-dialog.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Alessandro Gatti <[email protected]>
Date: Sun, 27 Jun 2021 20:18:35 +0200
Subject: [PATCH] 3163: Better keyboard handling in the Language dialog.
This change introduces three main improvements:
* If the language table is in focus, digits, Letters, dashes and
backspace keypresses are automatically rerouted to the filter
textedit box, to allow showing a particular entry by typing right
away.
* If the language table is in focus and a line is selected, pressing
the Enter key commits the selection and closes the dialog, as if the
'OK' button was pressed.
* Double-clicking a line would act as if the line was selected and the
'OK' button was pressed.
Additionally, Left/Right cursor key events are consumed with no further
processing, since there is no point in focussing/selecting a particular
column in this dialog.
---
.../core/processors/SetLanguageDialog.java | 48 ++++++----
.../importer/ImporterLanguageDialog.java | 16 ++--
.../plugin/importer/LcsSelectionListener.java | 37 +++++++-
.../plugin/importer/NewLanguagePanel.java | 88 +++++++++++++++++--
4 files changed, 153 insertions(+), 36 deletions(-)
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/processors/SetLanguageDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/processors/SetLanguageDialog.java
index b7e1bd355c..54cdbff10b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/processors/SetLanguageDialog.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/processors/SetLanguageDialog.java
@@ -19,6 +19,7 @@ import javax.swing.BorderFactory;
import docking.DialogComponentProvider;
import ghidra.framework.plugintool.PluginTool;
+import ghidra.plugin.importer.LcsSelectionEvent;
import ghidra.plugin.importer.LcsSelectionListener;
import ghidra.plugin.importer.NewLanguagePanel;
import ghidra.program.model.lang.*;
@@ -35,28 +36,37 @@ public class SetLanguageDialog extends DialogComponentProvider {
private LanguageID dialogLanguageID;
private CompilerSpecID dialogCompilerSpecID;
- LcsSelectionListener listener = e -> {
- LanguageID langID = null;
- CompilerSpecID compilerSpecID = null;
- if (e != null && e.selection != null) {
- langID = e.selection.languageID;
- compilerSpecID = e.selection.compilerSpecID;
- }
- if ((currentLCSPair != null) && (langID != null) &&
- (langID.equals(currentLCSPair.getLanguageID()))) {
- if (compilerSpecID != null &&
- compilerSpecID.equals(currentLCSPair.getCompilerSpecID())) {
- setStatusText("Please select a different Language or Compiler Spec.");
- setOkEnabled(false);
+ LcsSelectionListener listener = new LcsSelectionListener() {
+ @Override
+ public void valueChanged(LcsSelectionEvent e) {
+ LanguageID langID = null;
+ CompilerSpecID compilerSpecID = null;
+ if (e != null && e.selection != null) {
+ langID = e.selection.languageID;
+ compilerSpecID = e.selection.compilerSpecID;
+ }
+ if ((currentLCSPair != null) && (langID != null) &&
+ (langID.equals(currentLCSPair.getLanguageID()))) {
+ if ((compilerSpecID != null) &&
+ (compilerSpecID.equals(currentLCSPair.getCompilerSpecID()))) {
+ setStatusText("Please select a different Language or Compiler Spec.");
+ setOkEnabled(false);
+ } else {
+ setStatusText(null);
+ setOkEnabled(true);
+ }
+ return;
}
- else {
- setStatusText(null);
- setOkEnabled(true);
+ setStatusText(null);
+ setOkEnabled(langID != null);
+ }
+
+ @Override
+ public void valueChosen(LcsSelectionEvent e) {
+ if (isOKEnabled()) {
+ okCallback();
}
- return;
}
- setStatusText(null);
- setOkEnabled(langID != null);
};
/**
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterLanguageDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterLanguageDialog.java
index 0dadbd87ec..d5fe698cba 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterLanguageDialog.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterLanguageDialog.java
@@ -52,12 +52,9 @@ public class ImporterLanguageDialog extends DialogComponentProvider {
}
else {
try {
- SwingUtilities.invokeAndWait(new Runnable() {
- @Override
- public void run() {
- build();
- tool.showDialog(ImporterLanguageDialog.this, parent);
- }
+ SwingUtilities.invokeAndWait(() -> {
+ build();
+ tool.showDialog(ImporterLanguageDialog.this, parent);
});
}
catch (Exception e) {
@@ -77,6 +74,13 @@ public class ImporterLanguageDialog extends DialogComponentProvider {
public void valueChanged(LcsSelectionEvent e) {
validateFormInput();
}
+
+ @Override
+ public void valueChosen(LcsSelectionEvent e) {
+ if (isOKEnabled()) {
+ okCallback();
+ }
+ }
});
initialize();
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/LcsSelectionListener.java b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/LcsSelectionListener.java
index 4d70214639..31bf70aa40 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/LcsSelectionListener.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/LcsSelectionListener.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,6 +15,37 @@
*/
package ghidra.plugin.importer;
+/**
+ * Language/Compiler selection table event listener interface.
+ */
public interface LcsSelectionListener {
- public void valueChanged(LcsSelectionEvent e);
+
+ /**
+ * Event types enumeration.
+ */
+ enum EventType {
+ /**
+ * The selected value has changed.
+ */
+ VALUE_CHANGED,
+
+ /**
+ * The currently selected value was chosen.
+ */
+ VALUE_CHOSEN
+ }
+
+ /**
+ * The selected value in the language/compiler selection table has changed.
+ *
+ * @param e the selection event.
+ */
+ void valueChanged(LcsSelectionEvent e);
+
+ /**
+ * The currently selected value in the language/compiler selection table was chosen for further operations.
+ *
+ * @param e the selection event.
+ */
+ void valueChosen(LcsSelectionEvent e);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/NewLanguagePanel.java b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/NewLanguagePanel.java
index 0a9f2d2b2b..c080be4e14 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/NewLanguagePanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/NewLanguagePanel.java
@@ -138,16 +138,73 @@ public class NewLanguagePanel extends JPanel {
if (e.getValueIsAdjusting()) {
return;
}
- notifyListeners();
+ notifyListeners(LcsSelectionListener.EventType.VALUE_CHANGED);
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent e) {
if (e.getClickCount() == 2) {
- // do the next action thingie
+ notifyListeners(LcsSelectionListener.EventType.VALUE_CHOSEN);
}
}
});
+ table.addKeyListener(new KeyListener() {
+ @Override
+ public void keyTyped(KeyEvent e) {
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ // Digits, letters, and dashes are appended to the filter text box.
+ if (Character.isLetterOrDigit(e.getKeyChar()) || e.getKeyChar() == '-') {
+ e.consume();
+ String filterText = tableFilterPanel.getFilterText();
+ tableFilterPanel.setFilterText(filterText + e.getKeyChar());
+ return;
+ }
+
+ switch (e.getKeyCode()) {
+ // Enter commits the selection if there is any.
+ case KeyEvent.VK_ENTER:
+ e.consume();
+
+ if (table.getSelectedRows().length > 0) {
+ notifyListeners(LcsSelectionListener.EventType.VALUE_CHOSEN);
+ }
+ break;
+
+ // Backspace removes the last character from the filter text box.
+ case KeyEvent.VK_BACK_SPACE:
+ e.consume();
+
+ String filterText = tableFilterPanel.getFilterText();
+ if (!filterText.isEmpty()) {
+ tableFilterPanel.setFilterText(filterText.substring(0, filterText.length() - 1));
+ }
+ break;
+
+ // Left and right cursor movement events are ignored, as columns don't need to be individually
+ // selected anyway.
+ //
+ // TODO: The proper fix for this is to add single-line selection to TableModel and GhidraTable,
+ // let's do it later.
+ case KeyEvent.VK_LEFT:
+ case KeyEvent.VK_RIGHT:
+ e.consume();
+ break;
+
+ // TODO: Fix handling of TAB/focus change events. Right now all focus change events are used to
+ // change the currently selected cell, which in this specific dialog does not really matter.
+ // All it has to do instead is to transfer focus to the next eligible UI element.
+ default:
+ break;
+ }
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ }
+ });
}
public void setFormatText(String text) {
@@ -174,7 +231,7 @@ public class NewLanguagePanel extends JPanel {
private void setLanguages(List<LanguageCompilerSpecPair> lcsPairList) {
tableModel.setLanguages(lcsPairList);
- notifyListeners();
+ notifyListeners(LcsSelectionListener.EventType.VALUE_CHANGED);
}
private void switchToAllList() {
@@ -208,7 +265,7 @@ public class NewLanguagePanel extends JPanel {
private LanguageCompilerSpecPair recommendedLcsPair;
- private void notifyListeners() {
+ private void notifyListeners(LcsSelectionListener.EventType eventType) {
LanguageCompilerSpecPair selectedLcsPair = getSelectedLcsPair();
if (selectedLcsPair == null) {
descriptionLabel.setText(DEFAULT_DESCRIPTION_TEXT);
@@ -221,11 +278,27 @@ public class NewLanguagePanel extends JPanel {
descriptionLabel.setText("<LanguageNotFound>");
}
}
-// notifyListenersOfValidityChanged();
+
if (!listeners.isEmpty()) {
LcsSelectionEvent e = new LcsSelectionEvent(selectedLcsPair);
- for (LcsSelectionListener listener : listeners) {
- listener.valueChanged(e);
+
+ switch (eventType) {
+ case VALUE_CHANGED: {
+ for (LcsSelectionListener listener : listeners) {
+ listener.valueChanged(e);
+ }
+ break;
+ }
+
+ case VALUE_CHOSEN: {
+ for (LcsSelectionListener listener : listeners) {
+ listener.valueChosen(e);
+ }
+ break;
+ }
+
+ default:
+ break;
}
}
}
@@ -329,5 +402,4 @@ public class NewLanguagePanel extends JPanel {
table.dispose();
listeners.clear();
}
-
}
--
2.45.1