Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(feat) History tab in the browser

Egor Khindikaynen5b5b84efcf31
diff --git a/CHANGELOG.md b/CHANGELOG.md
index df40a9ed..31997766 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,14 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
+### Added
+- **Version history:** every save keeps a version of the project, and the new **History**
+ tab in the browser shows them as a tree. Switch back to any version, or open one as a
+ separate copy; saving on top of an older version starts a new branch, so nothing is lost.
+ Name, note, star and delete versions from the right-click menu. **File → Save Version with
+ Note…** (⌥⌘S) asks what changed. Versions share their audio, so a version costs only what it
+ adds. **Save As** takes the whole history to the new project.
+
### Changed
- **Faster saves of projects with audio:** a save now writes only new recordings and
imports instead of every sample again, and the same audio used in several places is
diff --git a/FEATURES.md b/FEATURES.md
index 625f617c..a2ca1707 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -45,6 +45,11 @@ JUCE module; the engine core is JUCE-free.
- **Project**: create / open / save (`.nota`), autosaves, undo/redo for every editing
operation.
+- **Version history**: every save records a version inside the project. The browser's
+ **History** tab draws them as a branching tree (the current one has a brass dot); switch
+ to any version, open one as a copy, or name, note, star and delete versions. Saving on top
+ of an older version branches. **Save Version with Note…** (⌥⌘S). Versions share their
+ audio, so each costs only what it adds; **Save As** carries the history along.
- **Start window**: the logo follows the theme, recent projects sit in one compact list with
their dates — click to select, double-click (or the arrow keys and Return) to open.
- **Quit without saving** dialog names the project and how long its changes have gone
@@ -676,7 +681,8 @@ and user presets, automation, persistence and cloning.
- An **island panel** with an icon rail down its left edge: **Instruments / Audio Effects /
MIDI Effects**, then **Files** (with folder tree navigation), **Presets** (a tree of
- category → device → preset), **Projects**, and **Map** (MIDI Learn mappings). A hairline
+ category → device → preset), **Projects**, **Map** (MIDI Learn mappings) and **History**
+ (the open project's versions). A hairline
separates the device tabs from the library tabs, and the active one carries a brass edge.
- **A compact index**: single-line rows, sectioned into **BUILT-IN** and **PLUG-INS** with
counts, so it is clear where Nota's own devices end and the scanned plug-ins begin. The
diff --git a/src/managed/Nota.App/BrowserView.cs b/src/managed/Nota.App/BrowserView.cs
index 216e1292..9ab76571 100644
--- a/src/managed/Nota.App/BrowserView.cs
+++ b/src/managed/Nota.App/BrowserView.cs
@@ -119,6 +119,8 @@ public sealed class BrowserView : UserControl
// MIDI-learn map — two nodes joined by a link (a control mapped to a parameter).
private const string IconMap = "M3.4 17.6 a2.6 2.6 0 1 0 5.2 0 a2.6 2.6 0 1 0 -5.2 0 M15.4 6.4 a2.6 2.6 0 1 0 5.2 0 a2.6 2.6 0 1 0 -5.2 0 M7.9 15.7 L16.1 8.3";
// Collapse / expand — a window with its left sidebar ruled off.
+ // A clock face with a counter-clockwise arrow tail: project version history.
+ private const string IconHistory = "M4.6 9.2 A8 8 0 1 1 4 12 M4.6 9.2 L3.6 5.8 M4.6 9.2 L8 8.6 M12 7.6 V12 L15 14";
private const string IconSidebar = "M3.5 5.5 h17 v13 h-17 z M9.5 5.5 v13";
// View options — three centred rules, shortening downward (a sort/·filter glyph).
private const string IconOptions = "M4 7 H20 M7 12 H17 M10 17 H14";
@@ -150,10 +152,12 @@ public sealed class BrowserView : UserControl
};
}
- private const int TabCount = 7; // Instr / FX / MIDI / Files / Preset / Proj / Map
+ private const int TabCount = 8; // Instr / FX / MIDI / Files / Preset / Proj / Map / History
private const int FilesTab = 3; // samples: the player auditions the file
private const int PresetsTab = 4; // Instr / FX / MIDI / Files / Presets carry the player
private const int MapTab = 6; // MIDI-learn mappings — hosts a MidiMapView, not a list
+ private const int HistoryTab = 7; // the open project's versions — hosts a HistoryView
+ private static bool IsCustomTab(int index) => index is MapTab or HistoryTab;
private const double RowH = 26; // single-line index row (almanac list row: 26–28, one line)
private const double GroupRowH = 22;
@@ -166,6 +170,7 @@ public sealed class BrowserView : UserControl
private BrowserViewModel? _vm;
private ISettingsService? _settings;
private MidiMapView? _midiMap;
+ private HistoryView? _historyView;
// Collapsed: only the icon rail shows; clicking an icon unfolds the browser on that tab.
private bool _collapsed;
@@ -240,6 +245,7 @@ public sealed class BrowserView : UserControl
RailTab(4, "Presets", IconBookmark),
RailTab(5, "Projects", IconDoc),
RailTab(6, "MIDI map", IconMap),
+ RailTab(7, "History", IconHistory),
};
// A hairline above Files and above Map: devices · library · mappings.
foreach (int i in new[] { 3, 6 })
@@ -407,6 +413,13 @@ public sealed class BrowserView : UserControl
if (_active == MapTab) _content.Content = _midiMap;
}
+ /// <summary>Give the browser the project's History tab.</summary>
+ internal void SetHistory(HistoryView view)
+ {
+ _historyView = view;
+ if (_active == HistoryTab) _content.Content = view;
+ }
+
/// <summary>Reveal the MIDI-mappings tab (called when learn mode is armed).</summary>
public void ShowMidiMap() { SelectTab(MapTab); SetCollapsed(false, persist: true); }
@@ -530,7 +543,7 @@ public sealed class BrowserView : UserControl
// same thing — what the active tab is showing — so they refresh together.
private void RefreshCounts()
{
- if (_active < 0 || _active == MapTab) return;
+ if (_active < 0 || IsCustomTab(_active)) return;
_matchCount.Text = VisibleCount(_active).ToString();
_statusText.Text = StatusFor(_active);
UpdateEmptyState();
@@ -601,9 +614,10 @@ public sealed class BrowserView : UserControl
_active = index;
for (int i = 0; i < _tabs.Length; i++)
_tabs[i].Classes.Set("active", !_collapsed && i == index);
- // The MIDI-map tab hosts a bespoke editor, not a filtered item list.
- bool isMap = index == MapTab;
- _content.Content = isMap ? (Control?)_midiMap : _pages[index];
+ // The MIDI-map and History tabs host bespoke views, not a filtered item list.
+ bool isMap = IsCustomTab(index);
+ _content.Content = index == MapTab ? _midiMap : index == HistoryTab ? (Control?)_historyView : _pages[index];
+ if (index == HistoryTab) _historyView?.Refresh();
_searchWrap.IsVisible = !isMap;
_optionsBtn.IsVisible = !isMap;
// The auditioner follows the list tabs: samples in Files, presets and built-in devices
diff --git a/src/managed/Nota.App/HistoryView.cs b/src/managed/Nota.App/HistoryView.cs
new file mode 100644
index 00000000..ca86ed6f
--- /dev/null
+++ b/src/managed/Nota.App/HistoryView.cs
@@ -0,0 +1,332 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// The "History" browser tab: the open project's versions as a tree, newest first, drawn
+// the way `git log --graph` draws branches (HistoryGraph lays it out). The current version
+// carries a brass dot. Selecting a version shows its details in the footer with Switch and
+// Open as copy; double-click switches; the context menu also renames, notes, stars and
+// deletes. Rebuilds whenever the window reports the history changed.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Shapes;
+using Avalonia.Input;
+using Avalonia.Layout;
+using Avalonia.Media;
+using Nota.Application;
+using Nota.Presentation;
+
+namespace Nota.App;
+
+/// <summary>What the History tab needs from the window that owns the project.</summary>
+internal interface IHistoryHost
+{
+ /// <summary>The open bundle, or null while the project has never been saved.</summary>
+ string? ProjectPath { get; }
+ bool KeepVersionHistory { get; }
+ Task<bool> SwitchToVersionAsync(string versionId);
+ Task<bool> OpenVersionAsCopyAsync(string versionId);
+ /// <summary>Show a one-line result on the window's status bar.</summary>
+ void ReportStatus(string text);
+}
+
+internal sealed class HistoryView : UserControl
+{
+ private const double RowH = 26;
+ private const double LaneW = 12;
+ private const string IconStar = "M12 3 L14.5 9 L21 9.3 L16 13.5 L17.7 20 L12 16.2 L6.3 20 L8 13.5 L3 9.3 L9.5 9 Z";
+
+ private readonly IProjectHistory _history;
+ private readonly IHistoryHost _host;
+ private readonly ListBox _list = new() { Classes = { "browser" }, Padding = new Thickness(0, 0, 0, 6) };
+ private readonly TextBlock _summary = new() { Classes = { "Mono" }, FontSize = 9, VerticalAlignment = VerticalAlignment.Center };
+ private readonly TextBlock _empty = new()
+ {
+ FontSize = 11, TextWrapping = TextWrapping.Wrap, TextAlignment = TextAlignment.Center,
+ HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
+ MaxWidth = 220, Margin = new Thickness(20, 0),
+ };
+ private readonly Border _details = new() { BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(10, 8, 10, 10) };
+ private ProjectHistoryState _state = ProjectHistoryState.Empty;
+ private Dictionary<string, int> _numbers = new(); // version id -> 1-based number in save order
+ private string? _dir;
+
+ public HistoryView(IProjectHistory history, IHistoryHost host)
+ {
+ _history = history;
+ _host = host;
+
+ var caption = new TextBlock { Text = "VERSIONS", Classes = { "GroupLabel" }, VerticalAlignment = VerticalAlignment.Center };
+ _summary.BindResource(TextBlock.ForegroundProperty, "Brush.TextTertiary");
+ var header = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), Height = RowH, Margin = new Thickness(10, 8, 10, 4) };
+ header.Children.Add(caption);
+ Grid.SetColumn(_summary, 1);
+ header.Children.Add(_summary);
+
+ _empty.BindResource(TextBlock.ForegroundProperty, "Brush.TextTertiary");
+ _details.BindResource(Border.BackgroundProperty, "Brush.Panel");
+ _details.BindResource(Border.BorderBrushProperty, "Brush.BorderDefault");
+ _details.IsVisible = false;
+
+ _list.ItemTemplate = new Avalonia.Controls.Templates.FuncDataTemplate<HistoryRow>((row, _) => row is null ? new Control() : Row(row), supportsRecycling: false);
+ _list.SelectionChanged += (_, _) => ShowDetails(_list.SelectedItem as HistoryRow);
+ _list.DoubleTapped += (_, _) => { if (_list.SelectedItem is HistoryRow r && !r.IsHead) _ = Switch(r.Version); };
+ _list.KeyDown += (_, e) =>
+ {
+ if (e.Key == Key.Enter && _list.SelectedItem is HistoryRow { IsHead: false } r) { _ = Switch(r.Version); e.Handled = true; }
+ };
+ _list.ContextRequested += (_, e) =>
+ {
+ if ((e.Source as StyledElement)?.DataContext is not HistoryRow row) return;
+ _list.SelectedItem = row;
+ BuildMenu(row).ShowAt(_list, showAtPointer: true);
+ e.Handled = true;
+ };
+
+ var body = new Grid();
+ body.Children.Add(_list);
+ body.Children.Add(_empty);
+
+ var root = new DockPanel();
+ DockPanel.SetDock(header, Dock.Top);
+ DockPanel.SetDock(_details, Dock.Bottom);
+ root.Children.Add(header);
+ root.Children.Add(_details);
+ root.Children.Add(body);
+ Content = root;
+ }
+
+ /// <summary>Re-reads the open project's history (after a save, switch, open or new).</summary>
+ public void Refresh()
+ {
+ string? keep = (_list.SelectedItem as HistoryRow)?.Version.Id;
+ _dir = _host.ProjectPath;
+ string? problem = null;
+ _state = ProjectHistoryState.Empty;
+ if (_dir is not null)
+ {
+ try { _state = _history.Read(_dir); }
+ catch (ProjectHistoryException ex) { problem = ex.Message; }
+ }
+
+ _numbers = _state.Versions.Select((v, i) => (v.Id, i)).ToDictionary(x => x.Id, x => x.i + 1);
+ var rows = HistoryGraph.Layout(_state);
+ _list.ItemsSource = rows;
+ _list.SelectedItem = rows.FirstOrDefault(r => r.Version.Id == keep);
+ ShowDetails(_list.SelectedItem as HistoryRow);
+
+ _empty.Text = problem
+ ?? (_dir is null ? "Save the project to start its history."
+ : !_host.KeepVersionHistory && rows.Count == 0 ? "Version history is turned off in Settings."
+ : rows.Count == 0 ? "Each save adds a version here." : "");
+ _empty.IsVisible = _empty.Text.Length > 0;
+ ToolTip.SetTip(_empty, problem is null ? null : "Its versions can't be listed until the file .history/versions.json is repaired.");
+
+ if (rows.Count == 0 || _dir is null) _summary.Text = "";
+ else
+ {
+ long size = 0;
+ try { size = _history.Size(_dir).HistoryOnly; } catch (Exception ex) when (ex is System.IO.IOException or UnauthorizedAccessException) { }
+ _summary.Text = $"{rows.Count} · {NotaNum.Bytes(size)}";
+ ToolTip.SetTip(_summary, $"{rows.Count} version{(rows.Count == 1 ? "" : "s")} · older versions take {NotaNum.Bytes(size)} on disk");
+ }
+ }
+
+ // --- rows ----------------------------------------------------------------
+
+ private Control Row(HistoryRow row)
+ {
+ var v = row.Version;
+ var edge = new Border { Classes = { "RowEdge" } };
+ var lanes = new LaneCell(row) { Width = 10 + row.LaneCount * LaneW, Height = RowH };
+
+ var name = new TextBlock { Text = Title(v), Classes = { "RowName" }, TextTrimming = TextTrimming.CharacterEllipsis, VerticalAlignment = VerticalAlignment.Center };
+ if (v.Label is null) name.Classes.Add("child"); // an unnamed version reads quieter
+ var when = new TextBlock { Text = ShortTime(v.CreatedAt), Classes = { "RowTag" }, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6, 0, 9, 0) };
+
+ var grid = new Grid { Height = RowH, ColumnDefinitions = new ColumnDefinitions("Auto,Auto,*,Auto,Auto") };
+ grid.Children.Add(edge);
+ Grid.SetColumn(lanes, 1);
+ grid.Children.Add(lanes);
+ Grid.SetColumn(name, 2);
+ grid.Children.Add(name);
+ if (v.Starred)
+ {
+ var star = new Path { Data = Geometry.Parse(IconStar), Stretch = Stretch.Uniform, Width = 9, Height = 9, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6, 0, 0, 0) };
+ star.BindResource(Shape.FillProperty, "Brush.Accent");
+ Grid.SetColumn(star, 3);
+ grid.Children.Add(star);
+ }
+ Grid.SetColumn(when, 4);
+ grid.Children.Add(when);
+ ToolTip.SetTip(grid, v.Note is { Length: > 0 } note ? $"{Title(v)} · {note}" : Title(v));
+ return grid;
+ }
+
+ /// <summary>Draws one row's slice of the tree: lanes passing by, branches joining in,
+ /// and the version's dot (brass for the current one).</summary>
+ private sealed class LaneCell(HistoryRow row) : Control
+ {
+ public override void Render(DrawingContext ctx)
+ {
+ double h = Bounds.Height, cy = h / 2;
+ double X(int lane) => 6 + lane * LaneW + LaneW / 2;
+ var pen = new Pen(NotaPalette.TextDisabled, 1.5, lineCap: PenLineCap.Round);
+ foreach (int l in row.Through) ctx.DrawLine(pen, new Point(X(l), 0), new Point(X(l), h));
+ double x = X(row.Lane);
+ if (row.FromAbove) ctx.DrawLine(pen, new Point(x, 0), new Point(x, cy));
+ if (row.ToBelow) ctx.DrawLine(pen, new Point(x, cy), new Point(x, h));
+ foreach (int j in row.Joins)
+ {
+ var g = new StreamGeometry();
+ using (var c = g.Open())
+ {
+ c.BeginFigure(new Point(X(j), 0), false);
+ c.QuadraticBezierTo(new Point(X(j), cy), new Point(x, cy));
+ }
+ ctx.DrawGeometry(null, pen, g);
+ }
+ if (row.IsHead) ctx.DrawEllipse(NotaPalette.Accent, null, new Point(x, cy), 4, 4);
+ else ctx.DrawEllipse(NotaPalette.SurfaceCard, new Pen(NotaPalette.TextMuted, 1.5), new Point(x, cy), 3.25, 3.25);
+ }
+ }
+
+ // --- details footer ------------------------------------------------------
+
+ private void ShowDetails(HistoryRow? row)
+ {
+ _details.IsVisible = row is not null;
+ if (row is null) { _details.Child = null; return; }
+ var v = row.Version;
+
+ var name = new TextBlock { Text = Title(v), Classes = { "Name" }, TextTrimming = TextTrimming.CharacterEllipsis };
+ name.BindResource(TextBlock.ForegroundProperty, "Brush.TextPrimary");
+ var meta = new List<string> { LongTime(v.CreatedAt) };
+ if (v.AppVersion.Length > 0) meta.Add("Nota " + v.AppVersion);
+ if (v.AddedBytes > 0) meta.Add("+" + NotaNum.Bytes(v.AddedBytes));
+ var metaText = new TextBlock { Text = string.Join(" · ", meta), Classes = { "Value" }, TextWrapping = TextWrapping.Wrap };
+ metaText.BindResource(TextBlock.ForegroundProperty, "Brush.TextSecondary");
+
+ var stack = new StackPanel { Spacing = 4, Children = { name, metaText } };
+ if (v.Note is { Length: > 0 } note && note != Title(v)) // the title already shows a one-line note
+ stack.Children.Add(new TextBlock { Text = note, Classes = { "Caption" }, TextWrapping = TextWrapping.Wrap, MaxHeight = 64 });
+ if (!v.CanOpen)
+ stack.Children.Add(new TextBlock { Text = "Saved by a newer Nota — update to open it.", Classes = { "Caption" }, TextWrapping = TextWrapping.Wrap });
+
+ var switchBtn = new Button
+ {
+ Content = ButtonText(row.IsHead ? "Current" : "Switch"),
+ Classes = { "primary" },
+ IsEnabled = !row.IsHead && v.CanOpen,
+ HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Center,
+ };
+ if (row.IsHead) switchBtn.Classes.Remove("primary");
+ ToolTip.SetTip(switchBtn, row.IsHead ? "The project is at this version" : "Switch the project to this version");
+ switchBtn.Click += (_, _) => _ = Switch(v);
+ var copyBtn = new Button
+ {
+ Content = ButtonText("Open copy"),
+ IsEnabled = v.CanOpen,
+ HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Center,
+ };
+ ToolTip.SetTip(copyBtn, "Open this version as a new project, keeping this one as it is");
+ copyBtn.Click += (_, _) => _ = _host.OpenVersionAsCopyAsync(v.Id);
+ var buttons = new Grid { ColumnDefinitions = new ColumnDefinitions("*,6,*"), Margin = new Thickness(0, 4, 0, 0) };
+ buttons.Children.Add(switchBtn);
+ Grid.SetColumn(copyBtn, 2);
+ buttons.Children.Add(copyBtn);
+ stack.Children.Add(buttons);
+ _details.Child = stack;
+ }
+
+ // Button captions trim instead of the button clipping when the browser is narrow.
+ private static TextBlock ButtonText(string text) => new() { Text = text, TextTrimming = TextTrimming.CharacterEllipsis };
+
+ // --- actions -------------------------------------------------------------
+
+ private async Task Switch(ProjectVersion v)
+ {
+ if (!v.CanOpen) return;
+ await _host.SwitchToVersionAsync(v.Id);
+ }
+
+ private MenuFlyout BuildMenu(HistoryRow row)
+ {
+ var v = row.Version;
+ var menu = new MenuFlyout();
+ MenuItem Item(string header, Action onClick, bool enabled = true, GlyphKind? icon = null)
+ {
+ var mi = new MenuItem { Header = header, IsEnabled = enabled };
+ if (icon is { } k) mi.Icon = MenuKit.Icon(k);
+ mi.Click += (_, _) => onClick();
+ menu.Items.Add(mi);
+ return mi;
+ }
+
+ Item("Switch to this version", () => _ = Switch(v), !row.IsHead && v.CanOpen, GlyphKind.Arrow);
+ Item("Open as copy…", () => _ = _host.OpenVersionAsCopyAsync(v.Id), v.CanOpen, GlyphKind.Duplicate);
+ menu.Items.Add(new Separator());
+ Item(v.Label is null ? "Name…" : "Rename…", () => _ = Prompt("Name version", "Version name", v.Label, t => _history.SetLabel(_dir!, v.Id, t)), icon: GlyphKind.Edit);
+ if (v.Label is not null) Item("Remove name", () => Apply(() => _history.SetLabel(_dir!, v.Id, null)));
+ Item(v.Note is null ? "Add note…" : "Edit note…", () => _ = Prompt("Version note", "What changed in this version?", v.Note, t => _history.SetNote(_dir!, v.Id, t)), icon: GlyphKind.Note);
+ if (v.Note is not null) Item("Remove note", () => Apply(() => _history.SetNote(_dir!, v.Id, null)));
+ Item(v.Starred ? "Remove star" : "Star", () => Apply(() => _history.SetStarred(_dir!, v.Id, !v.Starred)));
+ menu.Items.Add(new Separator());
+ var del = Item("Delete version…", () => _ = Delete(v), !row.IsHead, GlyphKind.Trash);
+ if (row.IsHead) ToolTip.SetTip(del, "Switch to another version to delete this one");
+ return menu;
+ }
+
+ private async Task Prompt(string title, string prompt, string? initial, Action<string> apply)
+ {
+ if (TopLevel.GetTopLevel(this) is not Window owner) return;
+ var text = await new TextPromptWindow(title, prompt, initial ?? "").ShowDialog<string?>(owner);
+ if (text is not null) Apply(() => apply(text));
+ }
+
+ private async Task Delete(ProjectVersion v)
+ {
+ if (TopLevel.GetTopLevel(this) is not Window owner || _dir is null) return;
+ bool ok = await new ConfirmWindow("Delete version",
+ $"Delete {Title(v)}? Audio that only this version uses is deleted from the project folder too. This can't be undone.",
+ "Delete", "Cancel").ShowDialog<bool>(owner);
+ if (ok) Apply(() => _history.Delete(_dir, v.Id));
+ }
+
+ // Runs a history edit, reporting a failure on the status line, then rebuilds.
+ private void Apply(Action edit)
+ {
+ if (_dir is null) return;
+ try { edit(); }
+ catch (Exception ex) when (ex is ProjectHistoryException or System.IO.IOException or UnauthorizedAccessException)
+ {
+ _host.ReportStatus($"Couldn't change the version: {ex.Message}");
+ }
+ Refresh();
+ }
+
+ // --- text ----------------------------------------------------------------
+
+ // The row's name: the label, else the note's first line, else its number in save order.
+ private string Title(ProjectVersion v)
+ => v.Label ?? v.Note?.Split('\n')[0] ?? (_numbers.TryGetValue(v.Id, out int n) ? $"Version {n}" : "Version");
+
+ // "14:32" today, "1 Oct" this year, "1 Oct 2025" before.
+ private static string ShortTime(DateTimeOffset t)
+ {
+ var local = t.LocalDateTime;
+ var now = DateTime.Now;
+ string f = local.Date == now.Date ? "HH:mm" : local.Year == now.Year ? "d MMM" : "d MMM yyyy";
+ return local.ToString(f, NotaNum.Culture);
+ }
+
+ private static string LongTime(DateTimeOffset t)
+ {
+ var local = t.LocalDateTime;
+ return local.ToString(local.Year == DateTime.Now.Year ? "d MMM, HH:mm" : "d MMM yyyy, HH:mm", NotaNum.Culture);
+ }
+}
diff --git a/src/managed/Nota.App/MainWindow.Files.cs b/src/managed/Nota.App/MainWindow.Files.cs
index c902e4a0..89c2b93e 100644
--- a/src/managed/Nota.App/MainWindow.Files.cs
+++ b/src/managed/Nota.App/MainWindow.Files.cs
@@ -178,6 +178,7 @@ public partial class MainWindow
RefreshAfterLoad();
UpdateWindowTitle();
MarkProjectClean();
+ HistoryChanged?.Invoke(); // a new project has no history yet
_vm.StatusText = "New project.";
}
@@ -236,6 +237,7 @@ public partial class MainWindow
RefreshAfterLoad();
UpdateWindowTitle();
MarkProjectClean();
+ HistoryChanged?.Invoke(); // the History tab shows this project's versions
var warnings = result.Warnings;
App.Services.GetRequiredService<ILogSink>()
.Info($"Opened project '{System.IO.Path.GetFileName(dir)}' · {warnings.Count} warning(s)");
diff --git a/src/managed/Nota.App/MainWindow.History.cs b/src/managed/Nota.App/MainWindow.History.cs
index 8654cd7f..e8b8f470 100644
--- a/src/managed/Nota.App/MainWindow.History.cs
+++ b/src/managed/Nota.App/MainWindow.History.cs
@@ -15,9 +15,24 @@ using Nota.Application;
namespace Nota.App;
-public partial class MainWindow
+public partial class MainWindow : IHistoryHost
{
private IProjectHistory _history = default!;
+ private HistoryView? _historyView;
+
+ string? IHistoryHost.ProjectPath => _projectPath;
+ bool IHistoryHost.KeepVersionHistory => KeepVersionHistory;
+ Task<bool> IHistoryHost.SwitchToVersionAsync(string versionId) => SwitchToVersionAsync(versionId);
+ Task<bool> IHistoryHost.OpenVersionAsCopyAsync(string versionId) => OpenVersionAsCopyAsync(versionId);
+ void IHistoryHost.ReportStatus(string text) { if (_vm is not null) _vm.StatusText = text; }
+
+ /// <summary>Builds the browser's History tab and keeps it in step with the project.</summary>
+ private void SetUpHistoryTab()
+ {
+ _historyView = new HistoryView(_history, this);
+ Browser.SetHistory(_historyView);
+ HistoryChanged += _historyView.Refresh;
+ }
/// <summary>The open project's history changed (a version was recorded, switched to, or
/// the project itself changed). The History tab listens.</summary>
@@ -93,7 +108,6 @@ public partial class MainWindow
return false;
}
OpenProject(dir);
- HistoryChanged?.Invoke();
if (_history.Read(dir).HeadVersion is { } v) _vm.StatusText = $"Switched to {DescribeVersion(v)}";
return true;
}
@@ -128,7 +142,6 @@ public partial class MainWindow
return false;
}
OpenProject(dst);
- HistoryChanged?.Invoke();
_vm.StatusText = $"Opened {DescribeVersion(version)} as {Path.GetFileName(dst)}";
return true;
}
diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.cs
index 779c6729..4657d45e 100644
--- a/src/managed/Nota.App/MainWindow.axaml.cs
+++ b/src/managed/Nota.App/MainWindow.axaml.cs
@@ -161,6 +161,7 @@ public partial class MainWindow : Window
_projects = App.Services.GetRequiredService<IProjectStore>();
_history = App.Services.GetRequiredService<IProjectHistory>();
+ SetUpHistoryTab();
_presets = App.Services.GetRequiredService<IPresetStore>();
_factory = App.Services.GetRequiredService<IFactoryPresets>();
_kits = App.Services.GetRequiredService<IDrumKits>();
diff --git a/src/managed/Nota.App/Theme/NotaNum.cs b/src/managed/Nota.App/Theme/NotaNum.cs
index d3188e6f..a5356cc6 100644
--- a/src/managed/Nota.App/Theme/NotaNum.cs
+++ b/src/managed/Nota.App/Theme/NotaNum.cs
@@ -70,6 +70,15 @@ public static class NotaNum
public static string Time(double seconds)
=> seconds < 0.9995 ? (seconds * 1000).ToString("0", Culture) + Thin + "ms" : seconds.ToString("0.00", Culture) + Thin + "s";
+ /// <summary>Disk size: "640 KB", "1.2 MB", "3.40 GB" (whole KB, one decimal MB, two GB).</summary>
+ public static string Bytes(long bytes)
+ {
+ const double K = 1024, M = K * K, G = M * K;
+ return bytes < M ? Math.Max(1, Math.Round(bytes / K)).ToString("0", Culture) + Thin + "KB"
+ : bytes < G ? (bytes / M).ToString("0.0", Culture) + Thin + "MB"
+ : (bytes / G).ToString("0.00", Culture) + Thin + "GB";
+ }
+
/// <summary>A number followed by its unit, thin-spaced.</summary>
public static string Unit(double v, string format, string unit) => v.ToString(format, Culture) + Thin + unit;
}
diff --git a/src/managed/Nota.Presentation/ViewModels/HistoryGraph.cs b/src/managed/Nota.Presentation/ViewModels/HistoryGraph.cs
new file mode 100644
index 00000000..5ca4eda5
--- /dev/null
+++ b/src/managed/Nota.Presentation/ViewModels/HistoryGraph.cs
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Lays a project's version tree out as rows, newest first, the way `git log --graph`
+// does: each branch keeps a lane (a column), a version sits on its lane, lanes that
+// branch off it join it from above. Pure — the History tab only draws the result.
+
+using Nota.Application;
+
+namespace Nota.Presentation;
+
+/// <summary>One row of the version graph.</summary>
+/// <param name="Lane">Column of this version's dot.</param>
+/// <param name="Through">Lanes that pass this row top to bottom (other branches).</param>
+/// <param name="Joins">Lanes that end here, coming in from above: branches started on this version.</param>
+/// <param name="FromAbove">A newer version on the same lane continues from this one.</param>
+/// <param name="ToBelow">This version has a parent (the lane continues down).</param>
+/// <param name="LaneCount">Width of the graph in lanes (same for every row).</param>
+public sealed record HistoryRow(
+ ProjectVersion Version, bool IsHead, int Lane,
+ IReadOnlyList<int> Through, IReadOnlyList<int> Joins,
+ bool FromAbove, bool ToBelow, int LaneCount);
+
+public static class HistoryGraph
+{
+ public static IReadOnlyList<HistoryRow> Layout(ProjectHistoryState state)
+ {
+ var order = NewestFirst(state.Versions);
+ var lanes = new List<string?>(); // lane -> the version id it is waiting for
+ var rows = new List<(ProjectVersion V, int Lane, List<int> Through, List<int> Joins, bool Above)>();
+
+ foreach (var v in order)
+ {
+ var waiting = new List<int>();
+ for (int i = 0; i < lanes.Count; i++)
+ if (lanes[i] == v.Id) waiting.Add(i);
+
+ int lane;
+ bool above = waiting.Count > 0;
+ if (above) lane = waiting[0];
+ else
+ {
+ lane = lanes.IndexOf(null); // a tip: first free lane
+ if (lane < 0) { lane = lanes.Count; lanes.Add(null); }
+ }
+ var joins = waiting.Skip(1).ToList();
+ foreach (int j in joins) lanes[j] = null;
+
+ var through = new List<int>();
+ for (int i = 0; i < lanes.Count; i++)
+ if (i != lane && lanes[i] is not null) through.Add(i);
+
+ // A parent that isn't in the list (deleted out from under) ends the lane here.
+ lanes[lane] = v.Parent is { } p && state.Versions.Any(x => x.Id == p) ? p : null;
+ rows.Add((v, lane, through, joins, above));
+ }
+
+ int width = Math.Max(1, lanes.Count);
+ return rows.Select(r => new HistoryRow(
+ r.V, r.V.Id == state.Head, r.Lane, r.Through, r.Joins,
+ r.Above, ToBelow: r.V.Parent is { } p && state.Versions.Any(x => x.Id == p), width))
+ .ToList();
+ }
+
+ // Newest first, but never a parent above its child (a clock change can put a child's
+ // time before its parent's): repeatedly take the newest version none of whose
+ // children are still waiting.
+ private static List<ProjectVersion> NewestFirst(IReadOnlyList<ProjectVersion> versions)
+ {
+ var ids = versions.Select(v => v.Id).ToHashSet();
+ var pendingChildren = versions.ToDictionary(v => v.Id, _ => 0);
+ foreach (var v in versions)
+ if (v.Parent is { } p && ids.Contains(p)) pendingChildren[p]++;
+
+ var ready = new PriorityQueue<ProjectVersion, (long, int)>();
+ var index = versions.Select((v, i) => (v.Id, i)).ToDictionary(x => x.Id, x => x.i);
+ void Offer(ProjectVersion v) => ready.Enqueue(v, (-v.CreatedAt.UtcTicks, -index[v.Id]));
+ foreach (var v in versions)
+ if (pendingChildren[v.Id] == 0) Offer(v);
+
+ var byId = versions.ToDictionary(v => v.Id);
+ var order = new List<ProjectVersion>(versions.Count);
+ while (ready.TryDequeue(out var v, out _))
+ {
+ order.Add(v);
+ if (v.Parent is { } p && byId.TryGetValue(p, out var parent) && --pendingChildren[p] == 0) Offer(parent);
+ }
+ return order;
+ }
+}
diff --git a/tests/Nota.SmokeTest/HistoryTests.cs b/tests/Nota.SmokeTest/HistoryTests.cs
index 232c0489..0d9d8bc6 100644
--- a/tests/Nota.SmokeTest/HistoryTests.cs
+++ b/tests/Nota.SmokeTest/HistoryTests.cs
@@ -14,6 +14,35 @@ namespace Nota.SmokeTest;
internal static class HistoryTests
{
+ /// <summary>The History tab's tree layout (HistoryGraph): lanes, joins, ordering.</summary>
+ public static IEnumerable<(bool Ok, string Label)> RunGraph()
+ {
+ var t0 = new DateTimeOffset(2026, 10, 1, 12, 0, 0, TimeSpan.Zero);
+ ProjectVersion V(string id, string? parent, int minutes)
+ => new(id, parent, t0.AddMinutes(minutes), null, null, false, "test", 1, 0, true);
+
+ var linear = Nota.Presentation.HistoryGraph.Layout(new ProjectHistoryState([V("a", null, 0), V("b", "a", 1), V("c", "b", 2)], "c"));
+ yield return (string.Concat(linear.Select(r => r.Version.Id)) == "cba" && linear.All(r => r.Lane == 0 && r.LaneCount == 1),
+ "a linear history is one lane, newest first");
+ yield return (linear[0] is { IsHead: true, FromAbove: false, ToBelow: true } && linear[2] is { FromAbove: true, ToBelow: false },
+ "the newest version opens the lane, the root closes it");
+
+ // a ← b ← c, and d branched from a later.
+ var branch = Nota.Presentation.HistoryGraph.Layout(new ProjectHistoryState(
+ [V("a", null, 0), V("b", "a", 1), V("c", "b", 2), V("d", "a", 3)], "d"));
+ var byId = branch.ToDictionary(r => r.Version.Id);
+ yield return (string.Concat(branch.Select(r => r.Version.Id)) == "dcba", $"branches interleave by time ({string.Concat(branch.Select(r => r.Version.Id))})");
+ yield return (byId["d"].Lane == 0 && byId["c"].Lane == 1 && byId["b"].Lane == 1 && byId["b"].Through.SequenceEqual([0]),
+ "a second branch takes its own lane while the first passes by");
+ yield return (byId["a"].Lane == 0 && byId["a"].Joins.SequenceEqual([1]) && branch.All(r => r.LaneCount == 2),
+ "both branches join at the version they started from");
+
+ // A clock change: the child claims to be older than its parent — it still draws above it.
+ var skew = Nota.Presentation.HistoryGraph.Layout(new ProjectHistoryState([V("a", null, 10), V("b", "a", 5)], "b"));
+ yield return (string.Concat(skew.Select(r => r.Version.Id)) == "ba" && skew.All(r => r.Lane == 0),
+ "a child is never drawn below its parent");
+ }
+
public static IEnumerable<(bool Ok, string Label)> Run()
{
string tmp = Path.GetTempPath();
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index a30fae2a..1530e81c 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -146,6 +146,7 @@ if (args.Length >= 1 && args[0] == "--history")
{
Console.WriteLine("-- project: version history --");
foreach (var (ok, label) in HistoryTests.Run()) Check(ok, label);
+ foreach (var (ok, label) in HistoryTests.RunGraph()) Check(ok, label);
Console.WriteLine(failures == 0 ? "HISTORY PASSED" : $"HISTORY FAILED ({failures})");
return failures == 0 ? 0 : 1;
}
@@ -13601,6 +13602,7 @@ Console.WriteLine("-- project: content-addressed bundle --");
foreach (var (ok, label) in BundleContentTests.Run()) Check(ok, label);
Console.WriteLine("-- project: version history --");
foreach (var (ok, label) in HistoryTests.Run()) Check(ok, label);
+foreach (var (ok, label) in HistoryTests.RunGraph()) Check(ok, label);
// --- get plug-ins: registry index, install/uninstall from local archives ---
Console.WriteLine("-- get plug-ins: registry store --");