Skip to content

Commit

Permalink
GH-226 add save as behaviour when document with no stateManager chang…
Browse files Browse the repository at this point in the history
…es is saved via the toolbar. (#227)
  • Loading branch information
pcorless authored Oct 4, 2022
1 parent b8f50ee commit 6e49bbe
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3459,26 +3459,27 @@ public void dispose() {
* when the window is closed.
*/
public void saveFile() {
if (document.getStateManager().isChange()) {
if (saveFilePath != null && !saveFilePath.isEmpty()) {
File out = new File(saveFilePath);
if (out.getParentFile() != null) {
if (Files.isWritable(out.getParentFile().toPath())) {
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(out))) {
document.saveToOutputStream(stream);
stream.flush();
document.getStateManager().setChangesSnapshot();
} catch (IOException e) {
logger.log(Level.FINE, "IO Exception ", e);
}
if (document.getStateManager().isChange() &&
saveFilePath != null &&
!saveFilePath.isEmpty()) {
File out = new File(saveFilePath);
if (out.getParentFile() != null) {
if (Files.isWritable(out.getParentFile().toPath())) {
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(out))) {
document.saveToOutputStream(stream);
stream.flush();
document.getStateManager().setChangesSnapshot();
} catch (IOException e) {
logger.log(Level.FINE, "IO Exception ", e);
}
} else {
//Probably got loaded from an InputStream, can't simply save
saveFileAs();
}
} else {
//Probably got loaded from an InputStream, can't simply save
saveFileAs();
}
} else {
// show saveAs dialog as this was legacy behaviour for the save button on the toolbar
saveFileAs();
}
}

Expand Down

1 comment on commit 6e49bbe

@ctoabidmaqbool
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks this is working fine!

Please sign in to comment.