mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-25 00:10:48 +08:00
Merge remote-tracking branch 'origin/GT-3630-dragonmacher-file-chooser-selection'
This commit is contained in:
+7
-2
@@ -1702,8 +1702,13 @@ public class GhidraFileChooser extends DialogComponentProvider
|
||||
void userSelectedFiles(List<File> files) {
|
||||
selectedFiles.setFiles(files);
|
||||
|
||||
// Update the display when we are in single selection mode
|
||||
if (!isMultiSelectionEnabled()) {
|
||||
// Update the display to...
|
||||
if (isMultiSelectionEnabled() && selectedFiles.size() > 1) {
|
||||
// clear the filename text field when multiple files are selected
|
||||
filenameTextField.setText("");
|
||||
}
|
||||
else {
|
||||
// set the filename text on single selection, regardless of mode
|
||||
updateTextFieldForFile(selectedFiles.getFile());
|
||||
}
|
||||
}
|
||||
|
||||
+78
-1
@@ -20,6 +20,7 @@ package docking.widgets.filechooser;
|
||||
|
||||
import static docking.widgets.filechooser.GhidraFileChooserMode.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.text.IsEmptyString.isEmptyOrNullString;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -1875,6 +1876,57 @@ public class GhidraFileChooserTest extends AbstractDockingTest {
|
||||
assertChosen(results, CollectionUtils.asIterable(files.files, files.dirs)); // dirs are dropped
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectingFileUpdatesTheTextField_SingleSelection() throws Exception {
|
||||
|
||||
TestFiles files = createMixedDirectory();
|
||||
showSingleSelectionChooser(files.parent, GhidraFileChooserMode.FILES_ONLY);
|
||||
|
||||
File file = files.files.get(0);
|
||||
selectFiles(file);
|
||||
|
||||
waitForChooser();
|
||||
String filenameFieldText = getFilenameFieldText();
|
||||
assertEquals("Filename text field not updated upon file selection", file.getName(),
|
||||
filenameFieldText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectingFileUpdatesTheTextField_MultiSelection() throws Exception {
|
||||
|
||||
TestFiles files = createMixedDirectory();
|
||||
showMultiSelectionChooser(files.parent, GhidraFileChooserMode.FILES_ONLY);
|
||||
|
||||
File file = files.files.get(0);
|
||||
selectFiles(file);
|
||||
|
||||
//
|
||||
// A single file selection will set the text field text
|
||||
//
|
||||
waitForChooser();
|
||||
String filenameFieldText = getFilenameFieldText();
|
||||
assertEquals("Filename text field not updated upon file selection", file.getName(),
|
||||
filenameFieldText);
|
||||
|
||||
//
|
||||
// A multi-selection will clear the text field text
|
||||
//
|
||||
selectFiles(files.files);
|
||||
waitForChooser();
|
||||
filenameFieldText = getFilenameFieldText();
|
||||
assertThat("Filename text field not cleared upon multi-file selection", filenameFieldText,
|
||||
isEmptyOrNullString());
|
||||
|
||||
//
|
||||
// Clear the multi-selection; a single file selection will set the text field text
|
||||
//
|
||||
selectFiles(file);
|
||||
waitForChooser();
|
||||
filenameFieldText = getFilenameFieldText();
|
||||
assertEquals("Filename text field not updated upon file selection", file.getName(),
|
||||
filenameFieldText);
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
// Private Methods
|
||||
//==================================================================================================
|
||||
@@ -1976,8 +2028,11 @@ public class GhidraFileChooserTest extends AbstractDockingTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void selectFiles(Iterable<File> files) {
|
||||
private void selectFiles(File file) {
|
||||
selectFiles(CollectionUtils.asIterable(file));
|
||||
}
|
||||
|
||||
private void selectFiles(Iterable<File> files) {
|
||||
DirectoryList dirlist = getListView();
|
||||
runSwing(() -> dirlist.setSelectedFiles(files));
|
||||
}
|
||||
@@ -2284,6 +2339,28 @@ public class GhidraFileChooserTest extends AbstractDockingTest {
|
||||
show(null, useDefaults);
|
||||
}
|
||||
|
||||
private CompletableFuture<List<File>> showSingleSelectionChooser(File dir,
|
||||
GhidraFileChooserMode mode) throws Exception {
|
||||
|
||||
close();
|
||||
|
||||
CompletableFuture<List<File>> theFuture = new CompletableFuture<>();
|
||||
|
||||
chooser = new GhidraFileChooser(null);
|
||||
chooser.setFileSelectionMode(mode);
|
||||
|
||||
runSwing(() -> {
|
||||
chooser.setCurrentDirectory(dir);
|
||||
chooser.setMultiSelectionEnabled(false);
|
||||
List<File> choice = chooser.getSelectedFiles();
|
||||
theFuture.complete(choice);
|
||||
}, false);
|
||||
|
||||
initialize(chooser, dir, true);
|
||||
|
||||
return theFuture;
|
||||
}
|
||||
|
||||
private CompletableFuture<List<File>> showMultiSelectionChooser(File dir,
|
||||
GhidraFileChooserMode mode) throws Exception {
|
||||
close();
|
||||
|
||||
Reference in New Issue
Block a user