if(command == "New") {
Moosique.clearSequence();
} else if (command == "Open...") {
+ // Shows a file chooser. If shown previously, starts in the current directory.
if (directory != null) {
chooser = new JFileChooser(directory);
} else {
}
chooser.addChoosableFileFilter(new MidiFileFilter());
int returnVal = chooser.showOpenDialog(this);
- if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
+
+ // Stores the current directory and loads the selected file.
+ File file = chooser.getSelectedFile();
+ if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
directory = chooser.getSelectedFile().getParentFile();
Moosique.load(chooser.getSelectedFile().getAbsolutePath());
}
} else if (command == "Save") {
Moosique.save();
} else if (command == "Save as...") {
+ // Shows a file chooser. If shown previously, starts in the current directory.
if (directory != null) {
chooser = new JFileChooser(directory);
} else {
}
chooser.addChoosableFileFilter(new MidiFileFilter());
int returnVal = chooser.showSaveDialog(this);
- if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
- directory = chooser.getSelectedFile().getParentFile();
- Moosique.saveAs(chooser.getSelectedFile().getAbsolutePath());
+
+ // Stores the current directory and loads the selected file.
+ File file = chooser.getSelectedFile();
+ if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
+ directory = file.getParentFile();
+ Moosique.saveAs(file.getAbsolutePath());
}
} else if (command == "Exit") {
Moosique.quit();