Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
Add save changes window
Egor Khindikaynen6454ceed3721
diff --git a/src/managed/Nota.App/MainWindow.Files.cs b/src/managed/Nota.App/MainWindow.Files.csindex 3eec3f9e..70171de6 100644--- a/src/managed/Nota.App/MainWindow.Files.cs+++ b/src/managed/Nota.App/MainWindow.Files.cs@@ -180,6 +180,7 @@ public partial class MainWindowTimeline.ClearSections(); // …and a clean song structureRefreshAfterLoad();UpdateWindowTitle();+ MarkProjectClean();_vm.StatusText = "New project.";}@@ -236,6 +237,7 @@ public partial class MainWindowRecordRecentProject(dir); // surface it on the welcome screen next launchRefreshAfterLoad();UpdateWindowTitle();+ MarkProjectClean();var warnings = result.Warnings;App.Services.GetRequiredService<ILogSink>().Info($"Opened project '{System.IO.Path.GetFileName(dir)}' · {warnings.Count} warning(s)");@@ -275,9 +277,11 @@ public partial class MainWindow});}- private async Task DoSaveAsync(bool saveAs)+ /// <summary>Saves the project (prompting for a location when unnamed or Save As).+ /// Returns true only if the bundle was actually written.</summary>+ private async Task<bool> DoSaveAsync(bool saveAs){- if (_vm is null) return;+ if (_vm is null) return false;string? dir = _projectPath;if (saveAs || dir is null)@@ -294,7 +298,7 @@ public partial class MainWindow},});var chosen = file?.TryGetLocalPath();- if (chosen is null) return;+ if (chosen is null) return false;if (!chosen.EndsWith(".nota", StringComparison.OrdinalIgnoreCase)) chosen += ".nota";// The save panel may drop an empty placeholder file at the path; the// bundle is a folder, so clear it before writing.@@ -313,19 +317,46 @@ public partial class MainWindow_projectPath = dir;RecordRecentProject(dir); // surface it on the welcome screen next launchUpdateWindowTitle();+ MarkProjectClean();App.Services.GetRequiredService<ILogSink>().Info($"Saved project '{System.IO.Path.GetFileName(dir)}' · {warnings.Count} warning(s)");_vm.StatusText = warnings.Count == 0? $"Saved {System.IO.Path.GetFileName(dir)}": $"Saved {System.IO.Path.GetFileName(dir)} — {warnings.Count} unsupported item(s) skipped: {warnings[0]}";+ return true;}catch (Exception ex){App.Services.GetRequiredService<ILogSink>().Error("Save project failed", ex);_vm.StatusText = $"Save failed: {ex.Message}";+ return false;}}+ // --- unsaved-changes tracking ------------------------------------------++ // Manifest fingerprint as of the last New / Open / Save (null = never clean, e.g. a+ // recovered session). The project is dirty when the current fingerprint differs.+ private string? _cleanFingerprint;++ private string? CurrentFingerprint()+ {+ if (_vm is null) return null;+ try { return _projects.Fingerprint(Engine, TransportSnapshot()); }+ catch { return null; }+ }++ /// <summary>Record the current state as saved (after New / Open / Save).</summary>+ private void MarkProjectClean() => _cleanFingerprint = CurrentFingerprint();++ /// <summary>True if the project changed since it was last created, opened or saved.</summary>+ private bool HasUnsavedChanges()+ {+ if (_vm is null) return false;+ var now = CurrentFingerprint();+ return now is null || now != _cleanFingerprint;+ }+// A load/new swaps the whole graph and invalidates old track ids, so clear// per-clip editor state and rebuild every view (cf. RefreshAfterUndoRedo).private void RefreshAfterLoad()diff --git a/src/managed/Nota.App/MainWindow.Recovery.cs b/src/managed/Nota.App/MainWindow.Recovery.csindex 7c27c0d1..542528f0 100644--- a/src/managed/Nota.App/MainWindow.Recovery.cs+++ b/src/managed/Nota.App/MainWindow.Recovery.cs@@ -35,16 +35,48 @@ public partial class MainWindowcatch { /* autosave is best-effort — never disrupt the session */ }}+ // Set once the user has answered the unsaved-changes prompt, so the re-issued Close()+ // goes straight through; _closePromptOpen guards against a second prompt meanwhile.+ private bool _closeConfirmed;+ private bool _closePromptOpen;+private void OnMainWindowClosing(object? sender, WindowClosingEventArgs e){+ if (!_closeConfirmed && HasUnsavedChanges())+ {+ e.Cancel = true;+ if (!_closePromptOpen)+ Avalonia.Threading.Dispatcher.UIThread.Post(() => _ = ConfirmCloseAsync());+ return;+ }+CloseFloatingDetail(); // tear down the popped-out Devices/Clip window, if anyShutdownGamepad(); // stop the IOKit pad thread before the engine dies_recovery.EndSessionClean();}+ // Save / Don't Save / Cancel before quitting with unsaved edits. Save that is cancelled+ // (file panel dismissed) or fails keeps the app open.+ private async Task ConfirmCloseAsync()+ {+ _closePromptOpen = true;+ try+ {+ var choice = await new SaveChangesWindow("Unsaved changes",+ "Do you really want to quit without saving your changes?")+ .ShowDialog<SaveChoice>(this);+ if (choice == SaveChoice.Cancel) return;+ if (choice == SaveChoice.Save && !await DoSaveAsync(saveAs: false)) return;+ _closeConfirmed = true;+ }+ finally { _closePromptOpen = false; }+ Close();+ }+private async void OnOpenedRecoveryCheck(object? sender, EventArgs e){if (_vm is null) return;+ MarkProjectClean(); // the fresh startup project counts as unmodified// What's New shows once per new app version, ahead of the launcher.await ShowWhatsNewIfNeeded();@@ -74,6 +106,7 @@ public partial class MainWindowOpenProject(info.BundlePath);_projectPath = info.OriginalPath; // next Save targets the real bundle (null → prompt)UpdateWindowTitle();+ _cleanFingerprint = null; // recovered work is unsaved until the user saves itif (_vm is not null) _vm.StatusText = "Recovered unsaved work.";try { _recovery.ClearRecovery(); } catch { }}diff --git a/src/managed/Nota.App/SaveChangesWindow.cs b/src/managed/Nota.App/SaveChangesWindow.csnew file mode 100644index 00000000..7a3a958b--- /dev/null+++ b/src/managed/Nota.App/SaveChangesWindow.cs@@ -0,0 +1,58 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// Save / Don't Save / Cancel modal shown before discarding unsaved project edits.+// ShowDialog<SaveChoice> returns Cancel when the window is closed without a choice.++using Avalonia;+using Avalonia.Controls;+using Avalonia.Layout;+using Avalonia.Media;++namespace Nota.App;++public enum SaveChoice { Cancel, Save, DontSave }++public sealed class SaveChangesWindow : NotaWindow+{+ public SaveChangesWindow(string title, string message)+ {+ Title = title;+ Width = 420;+ SizeToContent = SizeToContent.Height;+ CanResize = false;+ WindowStartupLocation = WindowStartupLocation.CenterOwner;+ Background = NotaPalette.BgApp;++ var save = new Button { Content = "Save", Classes = { "primary" } };+ save.Click += (_, _) => Close(SaveChoice.Save);+ var dontSave = new Button { Content = "Don't Save", Classes = { "ghost" } };+ dontSave.Click += (_, _) => Close(SaveChoice.DontSave);+ var cancel = new Button { Content = "Cancel", Classes = { "ghost" } };+ cancel.Click += (_, _) => Close(SaveChoice.Cancel);++ SetBody(new StackPanel+ {+ Margin = new Thickness(20),+ Spacing = 16,+ Children =+ {+ new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap },+ new DockPanel+ {+ LastChildFill = false,+ Children =+ {+ dontSave,+ new StackPanel+ {+ Orientation = Orientation.Horizontal, Spacing = 8,+ [DockPanel.DockProperty] = Dock.Right,+ Children = { cancel, save },+ },+ },+ },+ },+ });+ }+}diff --git a/src/managed/Nota.Application/Ports/IProjectStore.cs b/src/managed/Nota.Application/Ports/IProjectStore.csindex 6b2aebdf..59ad42dc 100644--- a/src/managed/Nota.Application/Ports/IProjectStore.cs+++ b/src/managed/Nota.Application/Ports/IProjectStore.cs@@ -23,4 +23,9 @@ public interface IProjectStore/// <summary>Loads a bundle and applies it to a reset engine. Returns the transport/// to restore + downgrade warnings.</summary>ProjectLoadResult Load(IAudioEngine engine, string dir);++ /// <summary>A comparable snapshot of the project's current state (the serialized+ /// manifest, nothing written to disk). Two equal fingerprints mean no change —+ /// used to detect unsaved edits.</summary>+ string Fingerprint(IAudioEngine engine, TransportState transport);}diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectStore.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectStore.csindex 8edb7bfc..66b766ad 100644--- a/src/managed/Nota.Infrastructure/Persistence/ProjectStore.cs+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectStore.cs@@ -25,4 +25,7 @@ public sealed class ProjectStore : IProjectStoredoc.Transport.TimeSigNumerator, doc.Transport.TimeSigDenominator);return new ProjectLoadResult(transport, warnings);}++ public string Fingerprint(IAudioEngine engine, TransportState transport)+ => ProjectService.SerializeManifest(ProjectService.Capture(engine, transport, new List<string>()));}diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex eb6250ed..64db4215 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -8274,6 +8274,17 @@ Console.WriteLine("-- M7-7: crash recovery --");Check(!new RecoveryService(rdir).CrashDetected(), "clean shutdown clears the marker");try { System.IO.Directory.Delete(rdir, true); } catch { /* best-effort cleanup */ }++ // Unsaved-changes detection: the fingerprint is stable while nothing changes and+ // differs after an edit (drives the Save / Don't Save / Cancel prompt on quit).+ var store = new ProjectStore();+ var tr = new TransportState(120.0, 1.0, false, false);+ int fpTrack = engine.AddInstrumentTrack();+ string fp0 = store.Fingerprint(engine, tr);+ Check(store.Fingerprint(engine, tr) == fp0, "project fingerprint stable without edits");+ engine.SetTrackName(fpTrack, "Fingerprint probe");+ Check(store.Fingerprint(engine, tr) != fp0, "project fingerprint changes after an edit");+ Check(store.Fingerprint(engine, tr with { Bpm = 121.0 }) != store.Fingerprint(engine, tr), "project fingerprint tracks transport");}// ===================== M7-8: xrun / dropout telemetry ======================