Moosique.load(chooser.getSelectedFile().getAbsolutePath());
}
} else if (command == "Save") {
- Moosique.save();
+ if (!Moosique.save()) showSaveAsDialog();
} 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 = new JFileChooser();
- }
- chooser.addChoosableFileFilter(new MidiFileFilter());
- int returnVal = chooser.showSaveDialog(this);
-
- // 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());
- }
+ showSaveAsDialog();
} else if (command == "Exit") {
Moosique.quit();
} else if (command == "Copy") {
}
}
+ private void showSaveAsDialog() {
+ // Shows a file chooser. If shown previously, starts in the current directory.
+ if (directory != null) {
+ chooser = new JFileChooser(directory);
+ } else {
+ chooser = new JFileChooser();
+ }
+ chooser.addChoosableFileFilter(new MidiFileFilter());
+ int returnVal = chooser.showSaveDialog(this);
+
+ // 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());
+ }
+ }
+
class MidiFileFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File f) {
if(f != null) {