Skip to content

Commit

Permalink
feat(Studio): Don't ask about discarding changes for empty scratch file
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Sep 22, 2024
1 parent 8314699 commit afc8022
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Studio/CelesteStudio/Studio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,22 @@ protected override void OnClosing(CancelEventArgs e) {
}

private bool ShouldDiscardChanges(bool checkTempFile = true) {
if (Editor.Document.Dirty || checkTempFile && Editor.Document.FilePath == Document.ScratchFile) {
bool showConfirmation = Editor.Document.Dirty;

// Only ask for discarding changes if scratch file actually contains something
if (checkTempFile && Editor.Document.FilePath == Document.ScratchFile) {
bool containsInputs = false;
foreach (string line in Editor.Document.Lines) {
if (ActionLine.TryParse(line, out var actionLine) && (actionLine.Actions != Actions.None || actionLine.FeatherAngle != null || actionLine.FeatherMagnitude != null)) {
containsInputs = true;
break;
}
}

showConfirmation |= containsInputs;
}

if (showConfirmation) {
var confirm = MessageBox.Show("""
You have unsaved changes.
Are you sure you want to discard them?
Expand Down

0 comments on commit afc8022

Please sign in to comment.