Added "file exists! Overwrite?" confirmation dialog.

This commit is contained in:
hneemann 2017-04-04 13:13:29 +02:00
parent 05ba2abf42
commit 0ff369fa68
4 changed files with 47 additions and 8 deletions

View File

@ -413,7 +413,22 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
do {
repeat = false;
if (fc.showSaveDialog(Main.this) == JFileChooser.APPROVE_OPTION) {
final File selectedFile = fc.getSelectedFile();
if (selectedFile.exists()) {
Object[] options = {Lang.get("btn_overwrite"), Lang.get("btn_newName")};
int res = JOptionPane.showOptionDialog(Main.this,
Lang.get("msg_fileExists", selectedFile.getName()),
Lang.get("msg_warning"),
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
if (res == 1) {
repeat = true;
continue;
}
}
if (library.isFileAccessible(selectedFile))
saveFile(selectedFile, false);
else {

View File

@ -260,15 +260,35 @@ public class TableDialog extends JDialog {
JFileChooser fc = new JFileChooser();
if (TableDialog.this.filename != null)
fc.setSelectedFile(Main.checkSuffix(TableDialog.this.filename, "tru"));
if (fc.showSaveDialog(TableDialog.this) == JFileChooser.APPROVE_OPTION) {
try {
File file = Main.checkSuffix(fc.getSelectedFile(), "tru");
model.getTable().save(file);
TableDialog.this.filename = file;
} catch (IOException e1) {
new ErrorMessage().addCause(e1).show(TableDialog.this);
boolean repeat;
do {
repeat = false;
if (fc.showSaveDialog(TableDialog.this) == JFileChooser.APPROVE_OPTION) {
final File selectedFile = fc.getSelectedFile();
if (selectedFile.exists()) {
Object[] options = {Lang.get("btn_overwrite"), Lang.get("btn_newName")};
int res = JOptionPane.showOptionDialog(TableDialog.this,
Lang.get("msg_fileExists", selectedFile.getName()),
Lang.get("msg_warning"),
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
if (res == 1) {
repeat = true;
continue;
}
}
try {
File file = Main.checkSuffix(selectedFile, "tru");
model.getTable().save(file);
TableDialog.this.filename = file;
} catch (IOException e1) {
new ErrorMessage().addCause(e1).show(TableDialog.this);
}
}
}
} while (repeat);
}
});

View File

@ -38,6 +38,7 @@
<string name="btn_addTransitions_tt">Alle möglichen Übergänge werden als Testfälle ergänzt. Dient zur Erzeugung von Testfällen für den Simulator selbst.</string>
<string name="btn_newName">Neuer Name</string>
<string name="btn_saveAnyway">Trotzdem speichern</string>
<string name="btn_overwrite">Überschreiben</string>
<string name="msg_warning">Warnung</string>
<string name="cancel">Abbrechen</string>
<string name="digital">Digital</string>
@ -739,6 +740,7 @@ Die Icons stammen aus dem Tango Desktop Project.</string>
<string name="msg_fileNotAccessible">Dieser Dateiename ist nicht aus dem aktuellen Projekt importierbar!</string>
<string name="msg_fileIsNotUnique">Der Dateiname ist nicht eindeutig!</string>
<string name="msg_fileNotImportedYet">Die Datei wurde noch nicht importiert.</string>
<string name="msg_fileExists">Die Datei {0} existiert schon!</string>
<string name="ok">Ok</string>
<string name="rot_0"></string>

View File

@ -38,6 +38,7 @@
<string name="btn_addTransitions_tt">All possible transitions are added as test cases. Is used to create test cases to test the simulator itself.</string>
<string name="btn_newName">New Name</string>
<string name="btn_saveAnyway">Save anyway</string>
<string name="btn_overwrite">Overwrite</string>
<string name="msg_warning">Warning</string>
<string name="cancel">Cancel</string>
<string name="digital">Digital</string>
@ -726,6 +727,7 @@ The icons are taken from the Tango Desktop Project.</string>
<string name="msg_fileNotAccessible">The selected file name is not importable from the actual project!</string>
<string name="msg_fileIsNotUnique">The file name is not unique!</string>
<string name="msg_fileNotImportedYet">The file has not yet been imported.</string>
<string name="msg_fileExists">The file {0} already exists!</string>
<string name="ok">Ok</string>
<string name="rot_0"></string>