Skip to content

Use native FileDialog on OSX #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/main/java/com/tagtraum/perf/gcviewer/action/OpenFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tagtraum.perf.gcviewer.action;

import java.awt.FileDialog;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
Expand All @@ -17,6 +18,7 @@
import com.tagtraum.perf.gcviewer.GCViewerGui;
import com.tagtraum.perf.gcviewer.util.ExtensionFileFilter;
import com.tagtraum.perf.gcviewer.util.LocalisationHelper;
import com.tagtraum.perf.gcviewer.util.OSXSupport;

/**
*
Expand Down Expand Up @@ -59,6 +61,18 @@ public OpenFile(final GCViewerGui gcViewer) {
}

public void actionPerformed(final ActionEvent e) {
if(OSXSupport.isOSX()) {
// there is no way to show a checkbox on the native dialog so
// open a new window instead
FileDialog dialog = new FileDialog(gcViewer, LocalisationHelper.getString("fileopen_dialog_title"), FileDialog.LOAD);
dialog.setMultipleMode(true);
dialog.setVisible(true);
// dialog.setFilenameFilter doesn't do much on OSX
openFiles(dialog.getFiles(), false);
dialog.dispose();
return;
}

final boolean aDocumentIsAlreadyOpen = gcViewer.getSelectedGCDocument() != null;
addURLCheckBox.setVisible(aDocumentIsAlreadyOpen);
addURLCheckBox.setEnabled(aDocumentIsAlreadyOpen);
Expand All @@ -70,16 +84,24 @@ public void actionPerformed(final ActionEvent e) {
}
final int val = openDialog.showOpenDialog(gcViewer);
if (val == JFileChooser.APPROVE_OPTION) {
lastSelectedFiles = openDialog.getSelectedFiles();
if (addURLCheckBox.isSelected()) {
gcViewer.add(lastSelectedFiles);
}
else {
gcViewer.open(lastSelectedFiles);
}
openFiles(openDialog.getSelectedFiles(), addURLCheckBox.isSelected());
}
}

private void openFiles(File[] files, boolean shouldAdd) {
if (files == null || files.length == 0) {
return;
}
lastSelectedFiles = files;
if (shouldAdd) {
gcViewer.add(lastSelectedFiles);
}
else {
gcViewer.open(lastSelectedFiles);
}
}


public void setSelectedFile(final File file) {
openDialog.setCurrentDirectory(file.getParentFile());
openDialog.setSelectedFile(file);
Expand Down