Skip to content

Commit

Permalink
fix: PreferencesFx.persistWindowState does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
unknowIfGuestInDream committed Sep 12, 2023
1 parent 6da9ef5 commit 3b5e3ed
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class PreferencesFxDialog extends DialogPane {

private Dialog dialog = new Dialog();
private StorageHandler storageHandler;
private boolean persistWindowState;
private boolean saveSettings;
private boolean modalityInitialized;
private ButtonType closeWindowBtnType = ButtonType.CLOSE;
Expand All @@ -53,13 +52,11 @@ public class PreferencesFxDialog extends DialogPane {
public PreferencesFxDialog(PreferencesFxModel model, PreferencesFxView preferencesFxView) {
this.model = model;
this.preferencesFxView = preferencesFxView;
persistWindowState = model.isPersistWindowState();
saveSettings = model.isSaveSettings();
storageHandler = model.getStorageHandler();
model.loadSettingValues();
layoutForm();
setupDialogClose();
loadLastWindowState();
setupButtons();
setupValueChangedListeners();
if (model.getHistoryDebugState()) {
Expand All @@ -84,6 +81,7 @@ public void show() {
* the {@link PreferencesFxDialog}, as long as it is open.
*/
public void show(boolean modal) {
loadLastWindowState();
if (!modalityInitialized) {
// only set modality once to avoid exception:
// java.lang.IllegalStateException: Cannot set modality once stage has been set visible
Expand Down Expand Up @@ -133,7 +131,7 @@ private void setupDialogClose() {
model.discardChanges();
} else {
LOGGER.trace("Dialog - Close Button or 'x' was pressed");
if (persistWindowState) {
if (model.isPersistWindowState()) {
saveWindowState();
}
model.saveSettings();
Expand All @@ -154,15 +152,19 @@ private void saveWindowState() {
* Loads last saved size and position of the window.
*/
private void loadLastWindowState() {
if (persistWindowState) {
if (model.isPersistWindowState()) {
setPrefSize(storageHandler.loadWindowWidth(), storageHandler.loadWindowHeight());
getScene().getWindow().setX(storageHandler.loadWindowPosX());
getScene().getWindow().setY(storageHandler.loadWindowPosY());
model.setDividerPosition(storageHandler.loadDividerPosition());
model.setDisplayedCategory(model.loadSelectedCategory());
if (!modalityInitialized) {
getScene().getWindow().setX(storageHandler.loadWindowPosX());
getScene().getWindow().setY(storageHandler.loadWindowPosY());
}
} else {
setPrefSize(Constants.DEFAULT_PREFERENCES_WIDTH, Constants.DEFAULT_PREFERENCES_HEIGHT);
getScene().getWindow().centerOnScreen();
if (!modalityInitialized) {
getScene().getWindow().centerOnScreen();
}
}
}

Expand Down

0 comments on commit 3b5e3ed

Please sign in to comment.