Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit 642d39a

Browse files
author
Matt York
committed
- Added potential solution for windows directory selection
1 parent a8cbc47 commit 642d39a

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

AndroidGears/src/Forms/SettingsForm.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package Forms;
22

33
import Singletons.SettingsManager;
4+
import Utilities.OSValidator;
45
import Utilities.Utils;
56
import Workers.Git.GitWorker;
67
import Workers.Settings.SetCreateIgnoreEntryWorker;
@@ -76,28 +77,43 @@ public void actionPerformed(ActionEvent actionEvent) {
7677
FindURLButton.addActionListener(new ActionListener() {
7778
@Override
7879
public void actionPerformed(ActionEvent actionEvent) {
79-
//Get top level frame
80-
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel);
81-
82-
//Create dialog for choosing gearspec file
83-
System.setProperty("apple.awt.fileDialogForDirectories", "true");
84-
FileDialog fd = new FileDialog(topFrame, "Choose a directory", FileDialog.LOAD);
85-
fd.setDirectory(SettingsManager.getInstance().getSpecsPath());
86-
fd.setVisible(true);
87-
88-
//Get file
89-
String filename = fd.getFile();
90-
if (filename == null)
91-
System.out.println("You cancelled the choice");
92-
else {
93-
System.out.println("You chose " + filename);
9480

95-
//Get spec file
96-
File specsDirectory = new File(fd.getDirectory()+Utils.pathSeparator()+filename);
81+
if(OSValidator.isWindows()){
82+
JFileChooser chooser = new JFileChooser();
83+
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
84+
chooser.setCurrentDirectory(new File(SettingsManager.getInstance().getSpecsPath()));
85+
int returnVal = chooser.showOpenDialog(MasterPanel.getTopLevelAncestor());
86+
87+
if (returnVal == JFileChooser.APPROVE_OPTION) {
88+
File specsDirectory = chooser.getSelectedFile();
89+
90+
setSpecsRepoDirectory(specsDirectory);
91+
}
92+
}
93+
else if (OSValidator.isMac()){
94+
//Get top level frame
95+
JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(MasterPanel);
96+
97+
//Create dialog for choosing gearspec file
98+
System.setProperty("apple.awt.fileDialogForDirectories", "true");
99+
FileDialog fd = new FileDialog(topFrame, "Choose a directory", FileDialog.LOAD);
100+
fd.setDirectory(SettingsManager.getInstance().getSpecsPath());
101+
fd.setVisible(true);
102+
103+
//Get file
104+
String filename = fd.getFile();
105+
if (filename == null)
106+
System.out.println("You cancelled the choice");
107+
else {
108+
System.out.println("You chose " + filename);
109+
110+
//Get spec file
111+
File specsDirectory = new File(fd.getDirectory()+Utils.pathSeparator()+filename);
97112

98-
//If it exists, set it as the selected file path
99-
setSpecsRepoDirectory(specsDirectory);
113+
//If it exists, set it as the selected file path
114+
setSpecsRepoDirectory(specsDirectory);
100115

116+
}
101117
}
102118
}
103119
});

0 commit comments

Comments
 (0)