diff --git a/apps/samples/RichTextAreaDemo/src/com/oracle/demo/richtext/editor/Actions.java b/apps/samples/RichTextAreaDemo/src/com/oracle/demo/richtext/editor/Actions.java index 7192931bc09..7814deb767c 100644 --- a/apps/samples/RichTextAreaDemo/src/com/oracle/demo/richtext/editor/Actions.java +++ b/apps/samples/RichTextAreaDemo/src/com/oracle/demo/richtext/editor/Actions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2024, Oracle and/or its affiliates. + * Copyright (c) 2023, 2025, Oracle and/or its affiliates. * All rights reserved. Use is subject to license terms. * * This file is available and licensed under the following license: @@ -273,13 +273,12 @@ void open() { FileChooser ch = new FileChooser(); ch.setTitle("Open File"); ch.getExtensionFilters().addAll( - filterAll(), filterRich(), - filterRtf() + filterRtf(), + filterAll() ); - Window w = FX.getParentWindow(control); - File f = ch.showOpenDialog(w); + File f = ch.showOpenDialog(parentWindow()); if (f != null) { try { DataFormat fmt = guessFormat(f); @@ -294,11 +293,12 @@ void save() { File f = getFile(); if (f == null) { f = chooseFileForSave(); - if (f != null) { + if (f == null) { return; } } + file.set(f); try { writeFile(f); } catch (Exception e) { @@ -309,7 +309,6 @@ void save() { boolean saveAs() { File f = chooseFileForSave(); if (f != null) { - // TODO ask to overwrite if file exists file.set(f); try { writeFile(f); @@ -333,10 +332,9 @@ private File chooseFileForSave() { filterRich(), filterRtf(), filterTxt() - //filterAll() ); - Window w = FX.getParentWindow(control); - return ch.showSaveDialog(w); + + return ch.showSaveDialog(parentWindow()); } private void readFile(File f, DataFormat fmt) throws Exception { @@ -500,7 +498,7 @@ enum UserChoiceToSave { private UserChoiceToSave askSaveChanges() { Dialog d = new Dialog<>(); - d.initOwner(FX.getParentWindow(control)); + d.initOwner(parentWindow()); d.setTitle("Save Changes?"); d.setContentText("Do you want to save changes?"); @@ -540,4 +538,8 @@ public boolean askToSave() { } return false; } + + private Window parentWindow() { + return FX.getParentWindow(control); + } }