Skip to content

Commit

Permalink
unsaved changes dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
steam0r committed Mar 27, 2024
1 parent f68dd27 commit e9a681a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/electron/electron_endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,14 @@ class ElectronEndpoint
const pos = title.lastIndexOf(" *");
let newTitle = title;
if (pos !== -1) newTitle = title.substring(0, pos);
electronApp.editorWindow.setDocumentEdited(false);
electronApp.editorWindow.setTitle(newTitle);
}

setIconUnsaved()
{
const title = electronApp.editorWindow.getTitle();
electronApp.editorWindow.setDocumentEdited(true);
electronApp.editorWindow.setTitle(title + " *");
}

Expand Down
19 changes: 17 additions & 2 deletions src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,26 @@ class ElectronApp
"v8CacheOptions": "none"
}
});
// TODO: show proper dialog here...
this.editorWindow.webContents.on("will-prevent-unload", (event) =>
{
event.preventDefault();
if (this.editorWindow.isDocumentEdited())
{
const choice = dialog.showMessageBoxSync(this.editorWindow, {
"type": "question",
"buttons": ["Leave", "Stay"],
"title": "unsaved content!",
"message": "unsaved content!",
"defaultId": 0,
"cancelId": 1
});
const leave = (choice === 0);
if (leave)
{
event.preventDefault();
}
}
});

this.openPatch(patchFile);
}

Expand Down

0 comments on commit e9a681a

Please sign in to comment.