Skip to content

Commit

Permalink
feat(gui): add alternative file open dialog (#1709)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 26, 2022
1 parent 6844a46 commit 1a9cb83
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 211 deletions.
9 changes: 9 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class JadxSettings extends JadxCLIArgs {

private boolean showHeapUsageBar = false;
private boolean alwaysSelectOpened = false;
private boolean useAlternativeFileDialog = false;

private Map<String, WindowLocation> windowPos = new HashMap<>();
private int mainWindowExtendedState = JFrame.NORMAL;
Expand Down Expand Up @@ -268,6 +269,14 @@ public void setAlwaysSelectOpened(boolean alwaysSelectOpened) {
partialSync(settings -> settings.alwaysSelectOpened = alwaysSelectOpened);
}

public boolean isUseAlternativeFileDialog() {
return useAlternativeFileDialog;
}

public void setUseAlternativeFileDialog(boolean useAlternativeFileDialog) {
this.useAlternativeFileDialog = useAlternativeFileDialog;
}

public String getExcludedPackages() {
return excludedPackages;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ private SettingsGroup makeOtherGroup() {
jumpOnDoubleClick.setSelected(settings.isJumpOnDoubleClick());
jumpOnDoubleClick.addItemListener(e -> settings.setJumpOnDoubleClick(e.getStateChange() == ItemEvent.SELECTED));

JCheckBox useAltFileDialog = new JCheckBox();
useAltFileDialog.setSelected(settings.isUseAlternativeFileDialog());
useAltFileDialog.addItemListener(e -> settings.setUseAlternativeFileDialog(e.getStateChange() == ItemEvent.SELECTED));

JCheckBox update = new JCheckBox();
update.setSelected(settings.isCheckForUpdates());
update.addItemListener(e -> settings.setCheckForUpdates(e.getStateChange() == ItemEvent.SELECTED));
Expand All @@ -665,6 +669,7 @@ private SettingsGroup makeOtherGroup() {
group.addRow(NLS.str("preferences.language"), languageCbx);
group.addRow(NLS.str("preferences.lineNumbersMode"), lineNumbersMode);
group.addRow(NLS.str("preferences.jumpOnDoubleClick"), jumpOnDoubleClick);
group.addRow(NLS.str("preferences.useAlternativeFileDialog"), useAltFileDialog);
group.addRow(NLS.str("preferences.check_for_updates"), update);
group.addRow(NLS.str("preferences.cfg"), cfg);
group.addRow(NLS.str("preferences.raw_cfg"), rawCfg);
Expand Down
19 changes: 10 additions & 9 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@
import jadx.gui.ui.codearea.EditorViewState;
import jadx.gui.ui.dialog.ADBDialog;
import jadx.gui.ui.dialog.AboutDialog;
import jadx.gui.ui.dialog.FileDialog;
import jadx.gui.ui.dialog.LogViewerDialog;
import jadx.gui.ui.dialog.RenameDialog;
import jadx.gui.ui.dialog.SearchDialog;
import jadx.gui.ui.filedialog.FileDialogWrapper;
import jadx.gui.ui.filedialog.FileOpenMode;
import jadx.gui.ui.panel.ContentPanel;
import jadx.gui.ui.panel.IssuesPanel;
import jadx.gui.ui.panel.JDebuggerPanel;
Expand Down Expand Up @@ -293,19 +294,19 @@ public void onUpdate(Release r) {
}

public void openFileDialog() {
showOpenDialog(FileDialog.OpenMode.OPEN);
showOpenDialog(FileOpenMode.OPEN);
}

public void openProjectDialog() {
showOpenDialog(FileDialog.OpenMode.OPEN_PROJECT);
showOpenDialog(FileOpenMode.OPEN_PROJECT);
}

private void showOpenDialog(FileDialog.OpenMode mode) {
private void showOpenDialog(FileOpenMode mode) {
saveAll();
if (!ensureProjectIsSaved()) {
return;
}
FileDialog fileDialog = new FileDialog(this, mode);
FileDialogWrapper fileDialog = new FileDialogWrapper(this, mode);
List<Path> openPaths = fileDialog.show();
if (!openPaths.isEmpty()) {
settings.setLastOpenFilePath(fileDialog.getCurrentDir());
Expand All @@ -314,7 +315,7 @@ private void showOpenDialog(FileDialog.OpenMode mode) {
}

public void addFiles() {
FileDialog fileDialog = new FileDialog(this, FileDialog.OpenMode.ADD);
FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.ADD);
List<Path> addPaths = fileDialog.show();
if (!addPaths.isEmpty()) {
addFiles(addPaths);
Expand Down Expand Up @@ -346,7 +347,7 @@ private void saveProject() {
}

private void saveProjectAs() {
FileDialog fileDialog = new FileDialog(this, FileDialog.OpenMode.SAVE_PROJECT);
FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.SAVE_PROJECT);
if (project.getFilePaths().size() == 1) {
// If there is only one file loaded we suggest saving the jadx project file next to the loaded file
Path projectPath = getProjectPathForFile(this.project.getFilePaths().get(0));
Expand Down Expand Up @@ -377,7 +378,7 @@ private void saveProjectAs() {
}

private void exportMappings(MappingFormat mappingFormat) {
FileDialog fileDialog = new FileDialog(this, FileDialog.OpenMode.CUSTOM_SAVE);
FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.CUSTOM_SAVE);
fileDialog.setTitle(NLS.str("file.export_mappings_as"));
Path workingDir = project.getWorkingDir();
Path baseDir = workingDir != null ? workingDir : settings.getLastSaveFilePath();
Expand Down Expand Up @@ -659,7 +660,7 @@ public void cancelBackgroundJobs() {
}

private void saveAll(boolean export) {
FileDialog fileDialog = new FileDialog(this, FileDialog.OpenMode.EXPORT);
FileDialogWrapper fileDialog = new FileDialogWrapper(this, FileOpenMode.EXPORT);
List<Path> saveDirs = fileDialog.show();
if (saveDirs.isEmpty()) {
return;
Expand Down
202 changes: 0 additions & 202 deletions jadx-gui/src/main/java/jadx/gui/ui/dialog/FileDialog.java

This file was deleted.

Loading

0 comments on commit 1a9cb83

Please sign in to comment.