From 13664c3c112658e6bfdbadb316252221eadbed78 Mon Sep 17 00:00:00 2001 From: hippietrail Date: Wed, 30 Oct 2024 03:42:39 +0700 Subject: [PATCH 1/2] add a "Downloads" folder button to "Select File to Import" file chooser --- .../Docking/data/docking.theme.properties | 1 + .../filechooser/GhidraFileChooser.java | 21 +++++++++++++++++++ .../filechooser/LocalFileChooserModel.java | 13 ++++++++++++ .../filechooser/GhidraFileChooserModel.java | 9 ++++++++ 4 files changed, 44 insertions(+) diff --git a/Ghidra/Framework/Docking/data/docking.theme.properties b/Ghidra/Framework/Docking/data/docking.theme.properties index 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.png icon.filechooser.places.desktop = desktop.png icon.filechooser.places.home = user-home.png icon.filechooser.places.recent = inode-directory.png {edit-undo.png [move(6,10)]} +icon.filechooser.places.downloads = applications-internet.png icon.filter.options.contains = page_code.png icon.filter.options.exact = page_green.png diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/GhidraFileChooser.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/filechooser/GhidraFileChooser.java index 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 implement private 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 implement private 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 implement homeButton.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") { @Override File getFile() { @@ -338,6 +351,7 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implement shortCutButtonGroup.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 implement shortCutPanel.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 implement updateDirOnly(home, true); } + private void updateDownloads() { + File downloads = downloadsButton.getFile(); + updateDirOnly(downloads, true); + } + void removeRecentFiles(List toRemove) { recentList.removeAll(toRemove); saveRecentList(); @@ -1380,6 +1400,7 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implement checkShortCutButton(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.java index 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; + } + @Override public List 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.java index 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.

+ * 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. *

From 5e29463bd77c53a82ced99bf0d2040b52c5b40ff Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:09:58 -0500 Subject: [PATCH 2/2] GP-5118 - File Chooser - Add Downloads button --- Ghidra/Features/Base/certification.manifest | 1 + .../resources/images/folder-downloads-32.png | Bin 0 -> 1351 bytes .../Docking/data/docking.theme.properties | 2 +- .../filechooser/LocalFileChooserModel.java | 4 ++-- .../util/filechooser/GhidraFileChooserModel.java | 4 ++-- 5 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 Ghidra/Features/Base/src/main/resources/images/folder-downloads-32.png diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifest index 197fae7184..0fc0541072 100644 --- a/Ghidra/Features/Base/certification.manifest +++ b/Ghidra/Features/Base/certification.manifest @@ -821,6 +821,7 @@ src/main/resources/images/field.header.up.png||GHIDRA||||END| src/main/resources/images/fingerPointer.png||GHIDRA||||END| src/main/resources/images/flag-green.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END| src/main/resources/images/flag-yellow.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END| +src/main/resources/images/folder-downloads-32.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END| src/main/resources/images/format-text-bold.png||Tango Icons - Public Domain|||tango icon set|END| src/main/resources/images/functionDef.png||GHIDRA||||END| src/main/resources/images/function_graph.png||FAMFAMFAM Icons - CC 2.5|||famfamfam silk icon set|END| diff --git a/Ghidra/Features/Base/src/main/resources/images/folder-downloads-32.png b/Ghidra/Features/Base/src/main/resources/images/folder-downloads-32.png new file mode 100644 index 0000000000000000000000000000000000000000..8d4c84c046412b1e556505666382daa22edae706 GIT binary patch literal 1351 zcmV-N1-SZ&P)1K~#9!#g|KHTvZ&0zyEpMnam`anI<%8V;gNsLu<5EDt00G z05?9MT@;E6?z$+53l{}l2!e|)iwoVja3j(RB8a+BDYy|Ih+3icX;W%ao7&0a-g(}0 zy!UpDjcqb$Y5bT!48uKVzWM#maJk~W=l?|UKV#_d#%EXdmGbIs5ei&~_r#5+|K#)) zdG65O%Is}RK*6q@b%nq9!@%ilNc+EJq>Wp-qEv^{p?i za4RVB%|@F&FFZc@@e+Y%%cTO{;}UL_pxNRvV5z|LY^_|4JgY&Hz#2Np!FSJpSNQ$HKEoz)AC&ejE7R$GBjw} zG&GD+W>KJ}>daiOV{CvimX(lBbULfRs!%Jr7K`^?qEl2VIh1J=wQ5<^B9g5W6H_VY z$QgyztcZwY6Dt)a6-ZQ=*LIRt zpduyUoZuAQR#GYCLDdLbwIu>+ioJz^AWjnyRziuOlwf=!5EuzlfjAZDl7RU1LWRi* zbM*)OCxUJJ&RbaXg4L9Ds3Doq722J@{Ix-u_hHKGC3_-0;CdZ zX$3|+C+1(HkPE5TV&d4beVd_agj`^@dJ6E0N(XlnGyF*dR z7dSIHhn;>FtrQymDIkFnlqX6n2-8jC*oz1^FgAQI-=BS&eBX!sGCxT*3W@RLbDG3u zF@acGe17gnDm?|Zt+|t#soiWJ-LcFW@QFYwE}`kM616-uW3)KoX6)SZBwwGt$kvIN zAEtk$6~|c;p2Z3}_W;er`VE{vxs&_HoJNI6;kaZs5|O=W(#iBMUa<_ta^Ajv zY~Q{q^;@CQZf6PPtYO5hk6wP{$a`TmYOyk@@?0|Cdhd@KuJL|nx)N6F6xGnHqy7Hm zWH{A>hta-uwf@