-
Notifications
You must be signed in to change notification settings - Fork 4
Popup asking to save before closing for ContingencyStoreEditor #94
Changes from 2 commits
1170fab
9bcf958
554ed1a
4b82ae4
3955e6a
7e5388c
bc1df12
6528d42
58e6687
8d2fc83
e73f008
9fc09db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,6 +286,29 @@ private ContextMenu createContingencyElementMenu() { | |
return new ContextMenu(removeItem); | ||
} | ||
|
||
private boolean alertSave() { | ||
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); | ||
alert.setHeaderText("'" + this.store.getName() + "' " + RESOURCE_BUNDLE.getString("UnsavedQuitConfirmation")); | ||
ButtonType saveAndContinue = new ButtonType(RESOURCE_BUNDLE.getString("SaveAndContinue")); | ||
ButtonType dontSaveAndContinue = new ButtonType(RESOURCE_BUNDLE.getString("DontSaveAndContinue")); | ||
ButtonType cancel = new ButtonType(RESOURCE_BUNDLE.getString("Cancel")); | ||
|
||
alert.getButtonTypes().setAll(saveAndContinue, dontSaveAndContinue, cancel); | ||
|
||
Optional<ButtonType> result = alert.showAndWait(); | ||
return result.map(type -> { | ||
if (type == saveAndContinue) { | ||
save(); | ||
return true; | ||
} else if (type == dontSaveAndContinue) { | ||
saved.set(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems weird to set saved to true here: this is not logic. Is it really needed? |
||
return true; | ||
} else { | ||
return false; | ||
} | ||
}).orElse(false); | ||
} | ||
|
||
@Override | ||
public void save() { | ||
if (!saved.get()) { | ||
|
@@ -306,6 +329,14 @@ public void view() { | |
|
||
@Override | ||
public void dispose() { | ||
// nothing to dispose | ||
//noting to dispose | ||
} | ||
|
||
@Override | ||
public boolean canBeClosed() { | ||
if (!saved.getValue()) { | ||
return alertSave(); | ||
} | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,4 +135,10 @@ public void dispose() { | |
storableScript.removeListener(this); | ||
} | ||
|
||
@Override | ||
public boolean canBeClosed() { | ||
//TODO: save before close | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return true; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ NewName=New name | |
Rename=Rename | ||
RenameContingency=Rename contingency | ||
Remove=Remove | ||
UnsavedQuitConfirmation=is not saved, its modifications will be lost. Would you like to save the file first ? | ||
SaveAndContinue=Save and Continue | ||
DontSaveAndContinue=Don't save and Continue | ||
Cancel=Cancel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort entries by alphabetical order: it will be easier to find the missing properties |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ NewName=Nouveau nom | |
Rename=Renommer | ||
RenameContingency=Renommer la contingence | ||
Remove=Supprimer | ||
UnsavedQuitConfirmation=n'est pas sauvegard�, ses modifications seront perdues. Voulez vous enregistrer ce fichier d'abord ? | ||
SaveAndContinue=Enregistrer et Continuer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo issue: |
||
DontSaveAndContinue=Continuer sans enregistrer | ||
Cancel=Annuler | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,8 @@ public class GsePane extends StackPane { | |
private final Preferences preferences; | ||
private final Application javaxApplication; | ||
|
||
private boolean canBeClosed = true; | ||
|
||
public GsePane(GseContext context, AppData data, Application app) { | ||
this.context = Objects.requireNonNull(context); | ||
this.data = Objects.requireNonNull(data); | ||
|
@@ -190,10 +192,18 @@ public List<Image> getIcons() { | |
} | ||
|
||
public void dispose() { | ||
canBeClosed = true; | ||
savePreferences(); | ||
|
||
for (Tab tab : tabPane.getTabs()) { | ||
((ProjectPane) tab).dispose(); | ||
if (!((ProjectPane) tab).canBeClosed()) { | ||
canBeClosed = false; | ||
} | ||
} | ||
} | ||
|
||
public boolean canBeClosed() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to |
||
return canBeClosed; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,8 @@ public class ProjectPane extends Tab { | |
|
||
private static final ServiceLoaderCache<ProjectFileExecutionTaskExtension> EXECUTION_TASK_EXTENSION_LOADER = new ServiceLoaderCache<>(ProjectFileExecutionTaskExtension.class); | ||
|
||
private int tabsOpen = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this counter is needed: the number of tabs can probably be retrieved elsewhere |
||
|
||
private static class TabKey { | ||
|
||
private final String nodeId; | ||
|
@@ -677,7 +679,15 @@ private void viewFile(ProjectFile file, ProjectFileViewerExtension viewerExtensi | |
Node graphic = viewerExtension.getMenuGraphic(file); | ||
ProjectFileViewer viewer = viewerExtension.newViewer(file, getContent().getScene(), context); | ||
Tab tab = new MyTab(tabName, viewer.getContent()); | ||
tab.setOnClosed(event -> viewer.dispose()); | ||
tabsOpen++; | ||
tab.setOnCloseRequest(event -> { | ||
if (!viewer.canBeClosed()) { | ||
event.consume(); | ||
} else { | ||
viewer.dispose(); | ||
} | ||
}); | ||
tab.setOnClosed(event -> tabsOpen--); | ||
tab.setGraphic(graphic); | ||
tab.setTooltip(new Tooltip(tabName)); | ||
tab.setUserData(tabKey); | ||
|
@@ -864,4 +874,8 @@ public void dispose() { | |
taskItems.dispose(); | ||
closeViews(); | ||
} | ||
|
||
public boolean canBeClosed() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ProjectPane extends Tab which already has a final isClosable() method. I did not rename it here. |
||
return tabsOpen == 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,4 +360,9 @@ public void dispose() { | |
projectCase.removeListener(this); | ||
} | ||
|
||
@Override | ||
public boolean canBeClosed() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark |
||
return true; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,4 +196,9 @@ public void view() { | |
public void dispose() { | ||
// nothing to dispose | ||
} | ||
|
||
@Override | ||
public boolean canBeClosed() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark |
||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,4 +139,9 @@ public void dispose() { | |
preContResultPane.savePreferences(); | ||
postContResultPane.savePreferences(); | ||
} | ||
|
||
@Override | ||
public boolean canBeClosed() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark |
||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ public interface ProjectFileViewer { | |
|
||
void dispose(); | ||
|
||
boolean canBeClosed(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same remark |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use MessageFormat seems better: