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
(fix) New project and Open ask before discarding unsaved changes (#215) (#219)
Egor Khindikaynenefb2e907d9b2
diff --git a/.specify/bugs/new-project-unsaved-prompt/assessment.md b/.specify/bugs/new-project-unsaved-prompt/assessment.mdnew file mode 100644index 00000000..8621eb25--- /dev/null+++ b/.specify/bugs/new-project-unsaved-prompt/assessment.md@@ -0,0 +1,83 @@+# Bug Assessment: New project (Ctrl+N) discards unsaved changes and leaves a blank detail panel++- **Slug**: new-project-unsaved-prompt+- **Created**: 2026-10-20+- **Source**: https://github.com/nota-daw/nota/issues/215 (host: github.com — allowlisted)+- **Verdict**: valid+- **Severity**: high++## Report (verbatim or summarized)++Issue #215 — "New project (Ctrl+N) discards unsaved changes without prompting and leaves a+blank detail panel". With unsaved edits and the detail panel open, Ctrl+N opens a new project+at once (edits lost) and the detail panel stays open but blank. Expected: a Save / Don't save /+Cancel prompt (Cancel keeps the current project), and after the switch the detail panel is+closed or shows valid content — never empty.++## Symptom++File → New replaces the project without the unsaved-changes prompt, losing work; afterwards+an empty strip remains where the docked detail panel was.++## Reproduction++1. Open a project, make an edit, don't save.+2. Open the detail panel (Devices or Clip tab).+3. Press Ctrl+N (Cmd+N on macOS).++## Suspected Code Paths++- `src/managed/Nota.App/MainWindow.Files.cs:OnMenuNew()` — resets the engine and applies the+ template with no `HasUnsavedChanges()` check.+- `src/managed/Nota.App/MainWindow.Files.cs:DoOpenAsync()` and+ `src/managed/Nota.App/MainWindow.Browser.cs` (`BrowserItemKind.Project` → `OpenProject`) —+ the same gap for File → Open and opening a project from the browser.+- `src/managed/Nota.App/MainWindow.History.cs:ConfirmLeaveChangesAsync()` — the existing+ Save / Don't save / Cancel helper, used only by version switching; it always saves in place,+ which for an untitled project would open the file panel under the dialog.+- `src/managed/Nota.App/MainWindow.Recovery.cs:ConfirmCloseAsync()` — the quit prompt, which+ handles the untitled case correctly (dialog closes first, then the file panel).+- `src/managed/Nota.App/MainWindow.Files.cs:RefreshAfterLoad()` — sets only+ `DetailPanel.IsVisible = false`; the `DetailSplitter` stays visible and `BodyGrid` row 2+ keeps its height (MinHeight 120), so a blank band remains. Compare `OnCloseDetail()` in+ `MainWindow.Detail.cs`, which also hides the splitter and collapses the row. With the panel+ popped out (`DetailWindow`), the old project's device chain / clip editor stay in the window.++## Root Cause Hypothesis++Confidence: high. The unsaved-changes guard was added for quit and version switching but never+wired into the New / Open entry points. The blank panel is an incomplete close in+`RefreshAfterLoad` (panel hidden, its grid row not collapsed), which also affects Open.++## Proposed Remediation++**Preferred**: Make `ConfirmLeaveChangesAsync` handle untitled projects the way the quit prompt+does (no in-place save; on Save, run `DoSaveAsync` after the dialog closes and go on only if+it wrote the bundle), and reuse it in `ConfirmCloseAsync`. Call it at the start of `OnMenuNew`+(made async), in `DoOpenAsync` after a folder is picked, and before opening a project from the+browser. In `RefreshAfterLoad`, use `ResetClipEditor()` and close the docked panel completely+(the `OnCloseDetail` body, factored into `CloseDetail()`); when popped out, point the window's+chain at the new project's instrument track instead of the old chain.++**Files likely to change**:+- `src/managed/Nota.App/MainWindow.Files.cs`+- `src/managed/Nota.App/MainWindow.History.cs`+- `src/managed/Nota.App/MainWindow.Recovery.cs`+- `src/managed/Nota.App/MainWindow.Browser.cs`+- `src/managed/Nota.App/MainWindow.Detail.cs`+- `CHANGELOG.md`++**Tests to add or update**:+- UI-level behaviour (dialog, grid row) isn't covered by the smoke test; verify manually /+ with the headless harness: New with unsaved edits → prompt; Cancel keeps the project; Don't+ save → new project, detail row collapsed.++## Risks & Considerations++- The welcome screen also calls `OnMenuNew`; the project is clean there, so no prompt appears.+- Crash-recovery restore (`ApplyPendingRecovery`) calls `OpenProject` directly and must not prompt — unchanged.+- MCP `history` tools already refuse on unsaved changes — unaffected.++## Open Questions++- None.diff --git a/.specify/bugs/new-project-unsaved-prompt/fix.md b/.specify/bugs/new-project-unsaved-prompt/fix.mdnew file mode 100644index 00000000..2e1fe03f--- /dev/null+++ b/.specify/bugs/new-project-unsaved-prompt/fix.md@@ -0,0 +1,68 @@+# Bug Fix: New project (Ctrl+N) discards unsaved changes and leaves a blank detail panel++- **Slug**: new-project-unsaved-prompt+- **Fixed**: 2026-10-20+- **Assessment**: ./assessment.md+- **Status**: applied++## Summary++File → New, File → Open and opening a project from the browser now go through the+Save / Don't save / Cancel prompt, which now handles untitled projects like the quit prompt+does. A load now closes the docked detail panel completely (row collapsed, splitter hidden),+and a popped-out detail window is pointed at the new project's chain.++## Changes++| File | Change | Notes |+|------|--------|-------|+| `src/managed/Nota.App/MainWindow.History.cs` | modified | `ConfirmLeaveChangesAsync`: untitled → dialog closes, then `DoSaveAsync`; go on only if it saved |+| `src/managed/Nota.App/MainWindow.Recovery.cs` | modified | `ConfirmCloseAsync` reuses `ConfirmLeaveChangesAsync` (same behaviour, no duplicate) |+| `src/managed/Nota.App/MainWindow.Files.cs` | modified | `OnMenuNew` → `DoNewAsync` with the prompt; prompt in `DoOpenAsync` after the folder pick; `OpenProjectConfirmedAsync` for the browser; `RefreshAfterLoad` uses `ResetClipEditor()` + `CloseDetail()` and re-points a floating window |+| `src/managed/Nota.App/MainWindow.Browser.cs` | modified | browser Project item → `OpenProjectConfirmedAsync` |+| `src/managed/Nota.App/MainWindow.Detail.cs` | modified | `OnCloseDetail` body factored into `CloseDetail()` |+| `CHANGELOG.md` | modified | [Unreleased] → Fixed |++## Diff Highlights++```csharp+private async Task DoNewAsync()+{+ if (_vm is null) return;+ if (!await ConfirmLeaveChangesAsync("New project",+ "Save your changes before starting a new project?")) return;+ …+```++```csharp+ResetClipEditor(); // every clip editor points into the old graph+CloseDetail(); // collapse the docked row too, not just hide the panel+…+if (DetailFloating) ShowDevices(Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : TrackIdAt(0));+```++## Tests Added or Updated++- None in the repo: the smoke test drives the engine, not MainWindow dialogs. Covered by the+ headless harness below.++## Local Verification++- `scripts/build.sh` → build OK, SMOKE TEST PASSED.+- Headless harness (`/tmp/newprojharness`, real `MainWindow` on Avalonia.Headless):+ - New on a clean project → no prompt.+ - Add a track + open Devices panel → dirty, row 305 px.+ - New → "New project" prompt; Cancel → still 5 tracks, still dirty, panel unchanged.+ - New → Don't save → template (4 tracks), clean, panel/splitter hidden, row 0 px.+ - Popped-out detail window, dirty, New → prompt; Don't save → window shows track 1's chain.+- Not exercised: Save from the prompt (needs the native file panel / a named bundle on disk);+ the code path is the one the quit prompt already used.++## Deviations from Assessment++- The floating window uses the selected track, else the first track — `LastInstrumentTrack()`+ only remembers instruments added this session and is 0 right after a load.++## Follow-ups++- None.diff --git a/.specify/bugs/new-project-unsaved-prompt/test.md b/.specify/bugs/new-project-unsaved-prompt/test.mdnew file mode 100644index 00000000..e2267798--- /dev/null+++ b/.specify/bugs/new-project-unsaved-prompt/test.md@@ -0,0 +1,52 @@+# Bug Verification: New project (Ctrl+N) discards unsaved changes and leaves a blank detail panel++- **Slug**: new-project-unsaved-prompt+- **Tested**: 2026-10-20+- **Assessment**: ./assessment.md+- **Fix**: ./fix.md+- **Result**: verified++## Summary++The reproduction from the issue no longer reproduces. New with unsaved edits asks first,+Cancel keeps the project, and the detail panel closes fully. Opening from the browser and+Save from the prompt work too. The build and smoke test pass.++## Checks Performed++| Check | Command / Action | Result | Notes |+|-------|------------------|--------|-------|+| Reproduction (post-fix) | Headless harness `/tmp/newprojharness`: real `MainWindow`, add a track, open Devices panel, fire `OnMenuNew` | pass | "New project" prompt; Cancel keeps 5 tracks + dirty; Don't save → template, row 0 px, splitter hidden |+| Clean project | `OnMenuNew` with no edits | pass | no prompt |+| Popped-out detail window | `OnToggleDetailWindow`, edit, New → Don't save | pass | window shows track 1's chain, not the old one |+| Browser open | `OpenProjectConfirmedAsync(<saved bundle>)` while dirty | pass | "Open project" prompt; Cancel keeps the current project |+| Save from prompt (named) | New on a named dirty project, Enter (= Save) in the prompt | pass | saved in place, then New; reopening the bundle restores the saved 5 tracks |+| Regression suite | `scripts/build.sh` (native + managed build, smoke test) | pass | SMOKE TEST PASSED |+| Lint / type-check | C# compiler as part of the build | pass | no new warnings in changed files |++## Output Excerpts++```+New #1: prompt=New project+after Cancel: tracks=5 (was 5) dirty=True panel=True splitter=True row=305 actual=305+after Don't save: tracks=4 dirty=False panel=False splitter=False row=0 actual=0+floating after: window=True chainTrack=1 firstTrack=1 …+browser open: prompt=Open project+after Save: dialogOpen=False tracks=4 dirty=False path=null+reopen saved: prompt=False tracks=5 (expect 5)+```++## Residual Risks++- Save from the prompt on an **untitled** project (closes the prompt, then the native file+ panel) was not exercised — the headless platform has no file panel. The same sequence was+ the quit prompt's existing behaviour.+- File → Open goes through the native folder picker before the prompt. Not driven headless.+ It uses the same `ConfirmLeaveChangesAsync` call as the browser path.+- Verified headless, not on a real display with the Ctrl+N key itself. The shortcut maps to+ `file.new` → `OnMenuNew`, which was called directly.++## Recommendation++Close the bug. It is verified end-to-end through the real window code. A quick manual+Ctrl+N → Save on an untitled project before release would cover the file-panel path.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f583b2d5..c02da32d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -39,6 +39,11 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.small to read on a laptop screen, or 75 % to fit more tracks on a small one.### Fixed+- **New project and Open ask before discarding unsaved changes** (nota-daw/nota#215): File →+ New, File → Open and opening a project from the browser now offer Save / Don't save /+ Cancel, like quitting does; Cancel keeps the current project. The detail panel also closes+ cleanly on the switch instead of leaving an empty band, and a popped-out detail window+ shows the new project's devices.- Duplicating a track keeps each effect's sidechain source and tap; the compressor's keywas dropped on the copy.- A sidechain source keeps feeding its key when it is muted or another track is soloed (thediff --git a/src/managed/Nota.App/MainWindow.Browser.cs b/src/managed/Nota.App/MainWindow.Browser.csindex ed7bcda0..c22a46c0 100644--- a/src/managed/Nota.App/MainWindow.Browser.cs+++ b/src/managed/Nota.App/MainWindow.Browser.cs@@ -102,7 +102,7 @@ public partial class MainWindowTimeline.Refresh();break;case BrowserItemKind.Project:- OpenProject(item.Path);+ _ = OpenProjectConfirmedAsync(item.Path);return; // OpenProject rebuilds everything itselfcase BrowserItemKind.Preset:ApplyInsertResult(Insertion.ApplyPreset(item, new InsertTarget(Timeline.SelectedTrackId)));diff --git a/src/managed/Nota.App/MainWindow.Detail.cs b/src/managed/Nota.App/MainWindow.Detail.csindex 0eeb09a4..5e21686c 100644--- a/src/managed/Nota.App/MainWindow.Detail.cs+++ b/src/managed/Nota.App/MainWindow.Detail.cs@@ -606,7 +606,9 @@ public partial class MainWindowif (_vm is not null) _vm.StatusText = message;}- private void OnCloseDetail(object? sender, RoutedEventArgs e)+ private void OnCloseDetail(object? sender, RoutedEventArgs e) => CloseDetail();++ private void CloseDetail(){DetailPanel.IsVisible = false;DetailSplitter.IsVisible = false;diff --git a/src/managed/Nota.App/MainWindow.Files.cs b/src/managed/Nota.App/MainWindow.Files.csindex 86c5e169..4f824647 100644--- a/src/managed/Nota.App/MainWindow.Files.cs+++ b/src/managed/Nota.App/MainWindow.Files.cs@@ -170,9 +170,13 @@ public partial class MainWindow/// <summary>A crash-recovery snapshot to offer on open (set by App at launch). M7-7.</summary>public RecoveryInfo? PendingRecovery { get; init; }- private void OnMenuNew(object? sender, EventArgs e)+ private void OnMenuNew(object? sender, EventArgs e) => _ = DoNewAsync();++ private async Task DoNewAsync(){if (_vm is null) return;+ if (!await ConfirmLeaveChangesAsync("New project",+ "Save your changes before starting a new project?")) return;_links.Clear(); // no live-freeze links (cleared first: stale ids must not hit the new graph)Engine.Reset();// Reset transport to defaults (these setters drive the engine + UI).@@ -212,6 +216,16 @@ public partial class MainWindowif (folders.Count == 0) return;var dir = folders[0].TryGetLocalPath();if (dir is null) { _vm.StatusText = "Unsupported project location."; return; }+ if (!await ConfirmLeaveChangesAsync("Open project",+ "Save your changes before opening another project?")) return;+ OpenProject(dir);+ }++ // Open another project from the browser, after the unsaved-changes prompt.+ private async Task OpenProjectConfirmedAsync(string dir)+ {+ if (!await ConfirmLeaveChangesAsync("Open project",+ "Save your changes before opening another project?")) return;OpenProject(dir);}@@ -415,13 +429,12 @@ public partial class MainWindow_importEpoch++; // imports still running belong to the old graphTimeline.ClearPendingImports();Timeline.ForgetAutoTargets(); // lane targets are per-project track/device indices- _editorRoll = null;- _clipEditor = null;- _editorTrackId = -1;- _editorClipIndex = -1;- DetailPanel.IsVisible = false;+ ResetClipEditor(); // every clip editor points into the old graph+ CloseDetail(); // collapse the docked row too, not just hide the panel_deviceChain?.ForgetCardState(); // per-track preset labels belong to the old projectTimeline.Refresh();_session?.Refresh();+ // Popped out, the window stays up: show the new project's chain, not the old one's.+ if (DetailFloating) ShowDevices(Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : TrackIdAt(0));}}diff --git a/src/managed/Nota.App/MainWindow.History.cs b/src/managed/Nota.App/MainWindow.History.csindex a72d08c5..49cbb05a 100644--- a/src/managed/Nota.App/MainWindow.History.cs+++ b/src/managed/Nota.App/MainWindow.History.cs@@ -183,13 +183,17 @@ public partial class MainWindow : IHistoryHost, Nota.Mcp.IProjectVersionsAccess}// Save / Don't Save / Cancel when leaving a project with unsaved edits. True to go on.+ // A named project saves in place with the prompt up ("Saving…"); an untitled one needs+ // the file panel, so the prompt closes first. A Save that is cancelled or fails stays put.private async Task<bool> ConfirmLeaveChangesAsync(string title, string message){if (!HasUnsavedChanges()) return true;+ bool named = _projectPath is not null;var choice = await new SaveChangesWindow(title, message, ProjectDisplayName(), UnsavedAgeText(),- () => DoSaveAsync(saveAs: false))+ named ? () => DoSaveAsync(saveAs: false) : null).ShowDialog<SaveChoice>(this);- return choice != SaveChoice.Cancel;+ if (choice == SaveChoice.Cancel) return false;+ return choice != SaveChoice.Save || named || await DoSaveAsync(saveAs: false);}// "the version “With bass” (12 Oct, 14:32)" / "the version of 12 Oct, 14:32".diff --git a/src/managed/Nota.App/MainWindow.Recovery.cs b/src/managed/Nota.App/MainWindow.Recovery.csindex d1597b86..c652ac28 100644--- a/src/managed/Nota.App/MainWindow.Recovery.cs+++ b/src/managed/Nota.App/MainWindow.Recovery.cs@@ -65,16 +65,8 @@ public partial class MainWindow_closePromptOpen = true;try{- // A named project saves in place with the prompt up ("Saving…"); an untitled one- // needs the file panel, so the prompt closes first.- bool named = _projectPath is not null;- var choice = await new SaveChangesWindow("Unsaved changes",- "Do you really want to quit without saving your changes?",- ProjectDisplayName(), UnsavedAgeText(),- named ? () => DoSaveAsync(saveAs: false) : null)- .ShowDialog<SaveChoice>(this);- if (choice == SaveChoice.Cancel) return;- if (choice == SaveChoice.Save && !named && !await DoSaveAsync(saveAs: false)) return;+ if (!await ConfirmLeaveChangesAsync("Unsaved changes",+ "Do you really want to quit without saving your changes?")) return;_closeConfirmed = true;}finally { _closePromptOpen = false; }