Ghidra is a software reverse engineering (SRE) framework
add a "Downloads" folder button to "Select File to Import" file chooser
hippietrail13664c3c1126
diff --git a/Ghidra/Framework/Docking/data/docking.theme.properties b/Ghidra/Framework/Docking/data/docking.theme.propertiesindex fc6bf37645..cfc5d55b32 100644--- a/Ghidra/Framework/Docking/data/docking.theme.properties+++ b/Ghidra/Framework/Docking/data/docking.theme.properties@@ -103,6 +103,7 @@ icon.filechooser.places.my.computer = computer.pngicon.filechooser.places.desktop = desktop.pngicon.filechooser.places.home = user-home.pngicon.filechooser.places.recent = inode-directory.png {edit-undo.png [move(6,10)]}+icon.filechooser.places.downloads = applications-internet.pngicon.filter.options.contains = page_code.pngicon.filter.options.exact = page_green.pngdiff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/GhidraFileChooser.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/GhidraFileChooser.javaindex 01727533c2..d99fd98a73 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/GhidraFileChooser.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/GhidraFileChooser.java@@ -107,6 +107,7 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implementprivate static final Icon ICON_MY_COMPUTER = new GIcon("icon.filechooser.places.my.computer");private static final Icon ICON_DESKTOP = new GIcon("icon.filechooser.places.desktop");private static final Icon ICON_HOME = new GIcon("icon.filechooser.places.home");+ private static final Icon ICON_DOWNLOADS = new GIcon("icon.filechooser.places.downloads");private static final Icon ICON_RECENT = new GIcon("icon.filechooser.places.recent");private final static Cursor WAIT_CURSOR = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);@@ -167,6 +168,7 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implementprivate FileChooserToggleButton myComputerButton;private FileChooserToggleButton desktopButton;private FileChooserToggleButton homeButton;+ private FileChooserToggleButton downloadsButton;private FileChooserToggleButton recentButton;private JTextField currentPathTextField;@@ -323,6 +325,17 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implementhomeButton.addActionListener(e -> updateHome());homeButton.setForeground(FOREROUND_COLOR);+ downloadsButton = new FileChooserToggleButton("Downloads") {+ @Override+ File getFile() {+ return fileChooserModel.getDownloadsDirectory();+ }+ };+ downloadsButton.setName("DOWNLOADS_BUTTON");+ downloadsButton.setIcon(ICON_DOWNLOADS);+ downloadsButton.addActionListener(e -> updateDownloads());+ downloadsButton.setForeground(FOREROUND_COLOR);+recentButton = new FileChooserToggleButton("Recent") {@OverrideFile getFile() {@@ -338,6 +351,7 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implementshortCutButtonGroup.add(myComputerButton);shortCutButtonGroup.add(desktopButton);shortCutButtonGroup.add(homeButton);+ shortCutButtonGroup.add(downloadsButton);shortCutButtonGroup.add(recentButton);JPanel shortCutPanel = new JPanel(new GridLayout(0, 1));@@ -345,6 +359,7 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implementshortCutPanel.add(myComputerButton);shortCutPanel.add(desktopButton);shortCutPanel.add(homeButton);+ shortCutPanel.add(downloadsButton);shortCutPanel.add(recentButton);JPanel panel = new JPanel(new BorderLayout());@@ -718,6 +733,11 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implementupdateDirOnly(home, true);}+ private void updateDownloads() {+ File downloads = downloadsButton.getFile();+ updateDirOnly(downloads, true);+ }+void removeRecentFiles(List<RecentGhidraFile> toRemove) {recentList.removeAll(toRemove);saveRecentList();@@ -1380,6 +1400,7 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implementcheckShortCutButton(homeButton, currentDirectory);checkShortCutButton(recentButton, currentDirectory);checkShortCutButton(desktopButton, currentDirectory);+ checkShortCutButton(downloadsButton, currentDirectory);}private void checkShortCutButton(FileChooserToggleButton button, File currentDirectory) {diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/LocalFileChooserModel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/LocalFileChooserModel.javaindex ba439c4396..6e12623304 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/LocalFileChooserModel.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/LocalFileChooserModel.java@@ -79,6 +79,19 @@ public class LocalFileChooserModel implements GhidraFileChooserModel {return desktop.isDirectory() ? desktop : null;}+ @Override+ public File getDownloadsDirectory() {+ String userHomeProp = System.getProperty("user.home");+ if (userHomeProp == null) {+ return null;+ }++ File home = new File(userHomeProp);+ File downloads = new File(home, "Downloads");++ return downloads.isDirectory() ? downloads : null;+ }+@Overridepublic List<File> getRoots(boolean forceUpdate) {if (FS_ROOT_INFO.isEmpty() || forceUpdate) {diff --git a/Ghidra/Framework/Gui/src/main/java/ghidra/util/filechooser/GhidraFileChooserModel.java b/Ghidra/Framework/Gui/src/main/java/ghidra/util/filechooser/GhidraFileChooserModel.javaindex 83a4fa8133..97fc439c55 100644--- a/Ghidra/Framework/Gui/src/main/java/ghidra/util/filechooser/GhidraFileChooserModel.java+++ b/Ghidra/Framework/Gui/src/main/java/ghidra/util/filechooser/GhidraFileChooserModel.java@@ -53,6 +53,15 @@ public interface GhidraFileChooserModel {*/public File getDesktopDirectory();+ /**+ * Returns the user's downloads directory, as defined by their operating system and/or their windowing environment, or+ * null if there is no downloads directory.<p>+ * Example: "/home/the_user/Downloads" or "c:/Users/the_user/Downloads"+ *+ * @return downloads directory+ */+ public File getDownloadsDirectory();+/*** Returns a list of the root drives/directories.* <p>