in app/src/main/java/com/oracle/javafx/scenebuilder/app/DocumentWindowController.java [1920:2036]
private ActionStatus performSaveAsAction() {
final ActionStatus result;
if (editorController.canGetFxmlText()) {
final FileChooser fileChooser = new FileChooser();
final FileChooser.ExtensionFilter f
= new FileChooser.ExtensionFilter(I18N.getString("file.filter.label.fxml"),
"*.fxml"); //NOI18N
fileChooser.getExtensionFilters().add(f);
fileChooser.setInitialDirectory(EditorController.getNextInitialDirectory());
File fxmlFile = fileChooser.showSaveDialog(getStage());
if (fxmlFile == null) {
result = ActionStatus.CANCELLED;
} else {
boolean forgetSave = false;
// It is only on Linux where you can get the case the path doesn't
// end with the extension, thanks the behavior of the FX 8 FileChooser
// on this specific OS (see RT-31956).
// Below we ask the user if the extension shall be added or not.
// See DTL-5948.
final String path = fxmlFile.getPath();
if (! path.endsWith(".fxml")) { //NOI18N
try {
URL alternateURL = new URL(fxmlFile.toURI().toURL().toExternalForm() + ".fxml"); //NOI18N
File alternateFxmlFile = new File(alternateURL.toURI());
final AlertDialog d = new AlertDialog(getStage());
d.setMessage(I18N.getString("alert.save.noextension.message", fxmlFile.getName()));
String details = I18N.getString("alert.save.noextension.details");
if (alternateFxmlFile.exists()) {
details += "\n" //NOI18N
+ I18N.getString("alert.save.noextension.details.overwrite", alternateFxmlFile.getName());
}
d.setDetails(details);
d.setOKButtonVisible(true);
d.setOKButtonTitle(I18N.getString("alert.save.noextension.savewith"));
d.setDefaultButtonID(ButtonID.OK);
d.setShowDefaultButton(true);
d.setActionButtonDisable(false);
d.setActionButtonVisible(true);
d.setActionButtonTitle(I18N.getString("alert.save.noextension.savewithout"));
switch (d.showAndWait()) {
case ACTION:
// Nothing to do, we save with the no extension name
break;
case CANCEL:
forgetSave = true;
break;
case OK:
fxmlFile = alternateFxmlFile;
break;
}
} catch (MalformedURLException | URISyntaxException ex) {
forgetSave = true;
}
}
// Transform File into URL
final URL newLocation;
try {
newLocation = fxmlFile.toURI().toURL();
} catch(MalformedURLException x) {
// Should not happen
throw new RuntimeException("Bug in " + getClass().getSimpleName(), x); //NOI18N
}
// Checks if fxmlFile is the name of an already opened document
final DocumentWindowController dwc
= SceneBuilderApp.getSingleton().lookupDocumentWindowControllers(newLocation);
if (dwc != null && dwc != this) {
final Path fxmlPath = Paths.get(fxmlFile.toString());
final String fileName = fxmlPath.getFileName().toString();
final ErrorDialog d = new ErrorDialog(getStage());
d.setMessage(I18N.getString("alert.save.conflict.message", fileName));
d.setDetails(I18N.getString("alert.save.conflict.details"));
d.showAndWait();
result = ActionStatus.CANCELLED;
} else if (forgetSave) {
result = ActionStatus.CANCELLED;
} else {
// Recalculates references if needed
// TODO(elp)
// First change the location of the fxom document
editorController.setFxmlLocation(newLocation);
updateLoadFileTime();
updateStageTitle();
// We use same DocumentWindowController BUT we change its fxml :
// => reset document preferences
resetDocumentPreferences();
watchingController.update();
// Now performs a regular save action
result = performSaveAction();
if (result.equals(ActionStatus.DONE)) {
messageBarController.setDocumentDirty(false);
saveJob = getEditorController().getJobManager().getCurrentJob();
}
// Keep track of the user choice for next time
EditorController.updateNextInitialDirectory(fxmlFile);
// Update recent items with just saved file
var recordGlobal = getPreferencesRecordGlobal();
recordGlobal.addRecentItem(fxmlFile);
}
}
} else {
result = ActionStatus.CANCELLED;
}
return result;
}