From a6c1ab28d67440e374d3c6db0be580b3b38044b6 Mon Sep 17 00:00:00 2001 From: NeoCodeMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Thu, 17 Sep 2026 16:15:54 +0200 Subject: [PATCH 1/7] switch active cuesheet handling --- .../Services/UI/SessionStateContainerTests.cs | 82 +++++++++++++++++-- .../Services/UI/ISessionStateContainer.cs | 4 +- .../Services/UI/SessionStateContainer.cs | 48 +++++++---- 3 files changed, 107 insertions(+), 27 deletions(-) diff --git a/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs b/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs index 93a7028a..1cf99b03 100644 --- a/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs +++ b/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs @@ -21,6 +21,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; +using System.Linq.Expressions; using System.Threading.Tasks; namespace AudioCuesheetEditor.Tests.Services.UI @@ -96,7 +97,7 @@ public async Task InitializeAsync_NotInitialized_ShouldInitializeAsync() } [TestMethod] - public async Task InitializeAsync_Initialized_ShouldNoptInitializeAsync() + public async Task InitializeAsync_Initialized_ShouldNotInitializeAsync() { // Arrange var viewOptions = new ViewOptions(); @@ -109,20 +110,83 @@ public async Task InitializeAsync_Initialized_ShouldNoptInitializeAsync() } [TestMethod] - public async Task GetActiveCuesheet_Initialized_ReturnsDetailViewCuesheeetAsync() + public async Task ActiveCuesheet_Initialized_ReturnsDetailViewCuesheet() { // Arrange var viewOptions = new ViewOptions(); _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); await _sessionStateContainer.InitializeAsync(); // Act - var result = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; // Assert - Assert.AreEqual(_sessionStateContainer.Cuesheet, result); + Assert.AreEqual(_sessionStateContainer.Cuesheet, cuesheet); } [TestMethod] - public async Task GetActiveCuesheet_InitializedWithImportView_ReturnsDetailViewCuesheeetAsync() + public async Task ActiveCuesheet_SwitchViewSignalesUpdate_ReturnsImportViewCuesheet() + { + // Arrange + var viewOptions = new ViewOptions(); + _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); + await _sessionStateContainer.InitializeAsync(); + viewOptions.ActiveTab = ViewMode.ImportView; + + _localStorageOptionsProvider.Setup(x => x.SaveOptionsAsync(viewOptions)).Callback(() => + { + _localStorageOptionsProvider.Raise(x => x.OptionSaved += null, _localStorageOptionsProvider.Object, viewOptions); + }); + + Boolean activeCuesheetChangedEventTriggered = false; + _sessionStateContainer.ActiveCuesheetChanged += delegate + { + activeCuesheetChangedEventTriggered = true; + }; + _sessionStateContainer.Cuesheet.Title = "Cuesheet"; + _sessionStateContainer.ImportCuesheet = new() + { + Title = "ImportCuesheet" + }; + await _localStorageOptionsProvider.Object.SaveOptionsAsync(viewOptions); + // Act + var cuesheet = _sessionStateContainer.ActiveCuesheet; + // Assert + Assert.AreEqual(_sessionStateContainer.ImportCuesheet, cuesheet); + Assert.IsTrue(activeCuesheetChangedEventTriggered); + } + + [TestMethod] + public async Task ActiveCuesheet_SaveOptionsSetsActiveCuesheetOnce_ReturnsDetailViewCuesheet() + { + // Arrange + var viewOptions = new ViewOptions(); + _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); + await _sessionStateContainer.InitializeAsync(); + _localStorageOptionsProvider.Setup(x => x.SaveOptionsAsync(viewOptions)).Callback(() => + { + _localStorageOptionsProvider.Raise(x => x.OptionSaved += null, _localStorageOptionsProvider.Object, viewOptions); + }); + _sessionStateContainer.Cuesheet.Title = "Cuesheet"; + _sessionStateContainer.ImportCuesheet = new() + { + Title = "ImportCuesheet" + }; + viewOptions.ActiveTab = ViewMode.ImportView; + await _localStorageOptionsProvider.Object.SaveOptionsAsync(viewOptions); + Boolean activeCuesheetChangedEventTriggered = false; + _sessionStateContainer.ActiveCuesheetChanged += delegate + { + activeCuesheetChangedEventTriggered = true; + }; + await _localStorageOptionsProvider.Object.SaveOptionsAsync(viewOptions); + // Act + var cuesheet = _sessionStateContainer.ActiveCuesheet; + // Assert + Assert.AreEqual(_sessionStateContainer.ImportCuesheet, cuesheet); + Assert.IsFalse(activeCuesheetChangedEventTriggered); + } + + [TestMethod] + public async Task ActiveCuesheet_InitializedWithImportView_ReturnsDetailViewCuesheet() { // Arrange var viewOptions = new ViewOptions() @@ -132,19 +196,19 @@ public async Task GetActiveCuesheet_InitializedWithImportView_ReturnsDetailViewC _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); await _sessionStateContainer.InitializeAsync(); // Act - var result = _sessionStateContainer.GetActiveCuesheet(); + var result = _sessionStateContainer.ActiveCuesheet; // Assert Assert.AreEqual(_sessionStateContainer.ImportCuesheet, result); } [TestMethod] - public void GetActiveCuesheet_NotInitialized_ThrowsException() + public void ActiveCuesheet_NotInitialized_ReturnsNull() { // Arrange // Act - var exception = Assert.Throws(() => _sessionStateContainer.GetActiveCuesheet()); + var cuesheet = _sessionStateContainer.ActiveCuesheet; // Assert - Assert.AreEqual("Not initialized!", exception.Message); + Assert.IsNull(cuesheet); } } } \ No newline at end of file diff --git a/AudioCuesheetEditor/Services/UI/ISessionStateContainer.cs b/AudioCuesheetEditor/Services/UI/ISessionStateContainer.cs index 24ed1896..6e9a2f44 100644 --- a/AudioCuesheetEditor/Services/UI/ISessionStateContainer.cs +++ b/AudioCuesheetEditor/Services/UI/ISessionStateContainer.cs @@ -23,6 +23,7 @@ public interface ISessionStateContainer { public event EventHandler? CuesheetChanged; public event EventHandler? ImportCuesheetChanged; + public event EventHandler? ActiveCuesheetChanged; public Cuesheet Cuesheet { get; set; } public Cuesheet? ImportCuesheet { get; set; } public IList ImportAudiofiles { get; set; } @@ -37,7 +38,6 @@ public interface ISessionStateContainer /// /// Get current cuesheet based on current view /// - /// - public Cuesheet? GetActiveCuesheet(); + public Cuesheet? ActiveCuesheet { get; } } } diff --git a/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs b/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs index 97cb8361..bf125e86 100644 --- a/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs +++ b/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs @@ -27,11 +27,13 @@ public class SessionStateContainer : ISessionStateContainer, IDisposable private Cuesheet _cuesheet = new(); private Cuesheet? _importCuesheet; - private ViewOptions? _viewOptions; + private Cuesheet? _activeCuesheet; + private Boolean _initialized = false; private bool disposedValue; public event EventHandler? CuesheetChanged; public event EventHandler? ImportCuesheetChanged; + public event EventHandler? ActiveCuesheetChanged; public SessionStateContainer(ILocalStorageOptionsProvider localStorageOptionsProvider) { @@ -70,7 +72,12 @@ public Cuesheet? ImportCuesheet /// public async Task InitializeAsync() { - _viewOptions ??= await _localStorageOptionsProvider.GetOptionsAsync(); + if (_initialized == false) + { + var viewOptions = await _localStorageOptionsProvider.GetOptionsAsync(); + SetActiveCuesheet(viewOptions); + } + _initialized = true; } public void ResetImport() @@ -81,18 +88,7 @@ public void ResetImport() } /// - public Cuesheet? GetActiveCuesheet() - { - if (_viewOptions == null) - { - throw new InvalidOperationException("Not initialized!"); - } - if (_viewOptions.ActiveTab == ViewMode.ImportView) - { - return ImportCuesheet; - } - return Cuesheet; - } + public Cuesheet? ActiveCuesheet => _activeCuesheet; protected virtual void Dispose(bool disposing) { @@ -106,11 +102,31 @@ protected virtual void Dispose(bool disposing) } } - private void LocalStorageOptionsProvider_OptionSaved(object? sender, IOptions options) + void LocalStorageOptionsProvider_OptionSaved(object? sender, IOptions options) { if (options is ViewOptions viewOptions) { - _viewOptions = viewOptions; + SetActiveCuesheet(viewOptions); + } + } + + void SetActiveCuesheet(ViewOptions viewOptions) + { + if (viewOptions.ActiveTab == ViewMode.ImportView) + { + if (_activeCuesheet != ImportCuesheet) + { + _activeCuesheet = ImportCuesheet; + ActiveCuesheetChanged?.Invoke(this, EventArgs.Empty); + } + } + else + { + if (_activeCuesheet != Cuesheet) + { + _activeCuesheet = Cuesheet; + ActiveCuesheetChanged?.Invoke(this, EventArgs.Empty); + } } } } From 921056d40285ed07a7cc9169118b8e56392825ee Mon Sep 17 00:00:00 2001 From: NeoCodeMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Thu, 17 Sep 2026 16:16:12 +0200 Subject: [PATCH 2/7] fix tests --- .../AudioCuesheet/AudiofileManagerTests.cs | 12 +++--- .../AudioCuesheet/CuesheetManagerTests.cs | 42 +++++++++---------- .../AudioCuesheet/AudiofileManager.cs | 6 +-- .../Services/AudioCuesheet/CuesheetManager.cs | 16 +++---- .../Shared/Cuesheet/Audiofiles.razor | 19 ++++++++- .../Shared/Cuesheet/CuesheetData.razor | 15 ++----- .../Shared/ViewModes/ViewModeFull.razor | 19 ++++++++- 7 files changed, 77 insertions(+), 52 deletions(-) diff --git a/AudioCuesheetEditor.Tests/Services/AudioCuesheet/AudiofileManagerTests.cs b/AudioCuesheetEditor.Tests/Services/AudioCuesheet/AudiofileManagerTests.cs index 9674ae6e..6f30d296 100644 --- a/AudioCuesheetEditor.Tests/Services/AudioCuesheet/AudiofileManagerTests.cs +++ b/AudioCuesheetEditor.Tests/Services/AudioCuesheet/AudiofileManagerTests.cs @@ -267,7 +267,7 @@ public void AddTrack_FirstTrack_AddsNewTrackWithCalulatedTrackProperties() { Audiofiles = [audiofile] }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); var track = new Track(); // Act _audiofileManager.AddTrack(audiofile, track); @@ -302,7 +302,7 @@ public void AddTrack_AddToPreviousTracks_AddsNewTrackWithCalulatedTrackPropertie { Audiofiles = [audiofile] }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); var track = new Track() { IsLinkedToPreviousTrack = true @@ -343,7 +343,7 @@ public void AddTrack_DuringRecording_AddsNewTrackWithCalulatedTrackProperties() RecordingStart = DateTime.UtcNow, Audiofiles = [audiofile] }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); var track = new Track() { IsLinkedToPreviousTrack = true @@ -372,7 +372,7 @@ public void AddTrack_FirstTrackImporting_AddsNewTrackWithCalulatedTrackPropertie { Audiofiles = [audiofile] }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(importCuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(importCuesheet); var track = new Track(); // Act _audiofileManager.AddTrack(audiofile, track); @@ -441,7 +441,7 @@ public void RemoveTracks_WithAttachedTracks_RemovesTracksAndRecalculatesRemainin track3.Cuesheet = cuesheet; track4.Cuesheet = cuesheet; track5.Cuesheet = cuesheet; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act _audiofileManager.RemoveTracks(audiofile, [track2, track4]); // Assert @@ -519,7 +519,7 @@ public void RemoveTracks_DuringImport_RemovesTracksAndRecalculatesRemainingTrack track3.Audiofile = audiofile; track4.Audiofile = audiofile; track5.Audiofile = audiofile; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(importCuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(importCuesheet); // Act _audiofileManager.RemoveTracks(audiofile, [track2, track4]); // Assert diff --git a/AudioCuesheetEditor.Tests/Services/AudioCuesheet/CuesheetManagerTests.cs b/AudioCuesheetEditor.Tests/Services/AudioCuesheet/CuesheetManagerTests.cs index 48b0dc0b..28da198f 100644 --- a/AudioCuesheetEditor.Tests/Services/AudioCuesheet/CuesheetManagerTests.cs +++ b/AudioCuesheetEditor.Tests/Services/AudioCuesheet/CuesheetManagerTests.cs @@ -64,7 +64,7 @@ public void SetProperty_NewValue_ChangesPropertyAndSetsTracedChange() { // Arrange var cuesheet = new Cuesheet(); - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act _cuesheetManager.SetProperty(x => x.Artist, "Artist"); // Assert @@ -80,7 +80,7 @@ public void SetProperty_EqualValue_DoesntChangeProperty() { Artist = "Artist" }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act _cuesheetManager.SetProperty(x => x.Artist, cuesheet.Artist); // Assert @@ -107,7 +107,7 @@ public void SetProperty_DeletedAudiofile_RevokesObjectURLs() { Audiofiles = [audiofile1, audiofile2] }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); var files = new List(cuesheet.Audiofiles); files.Remove(audiofile2); // Act @@ -390,7 +390,7 @@ public void IsMoveUpPossible_AudiofilesAbove_ReturnsTrue() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.IsMoveUpPossible([file2, file3]); // Assert @@ -408,7 +408,7 @@ public void IsMoveUpPossible_NoAudiofilesAbove_ReturnsFalse() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.IsMoveUpPossible([file1, file2]); // Assert @@ -461,7 +461,7 @@ public void IsMoveDownPossible_TracksBelow_ReturnsTrue() track1.Cuesheet = cuesheet; track2.Cuesheet = cuesheet; track3.Cuesheet = cuesheet; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.IsMoveDownPossible([track2, track1]); // Assert @@ -531,7 +531,7 @@ public void IsMoveDownPossible_AudiofilesBelow_ReturnsTrue() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.IsMoveDownPossible([file2, file1]); // Assert @@ -549,7 +549,7 @@ public void IsMoveDownPossible_NoAudiofilesBelow_ReturnsFalse() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.IsMoveDownPossible([file3, file2]); // Assert @@ -610,7 +610,7 @@ public void MoveUp_TracksSwitchingAudiofile_ReturnsSuccess() track1.Audiofile = cuesheet.Audiofiles.First(); track2.Audiofile = cuesheet.Audiofiles.Last(); track3.Audiofile = cuesheet.Audiofiles.Last(); - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.MoveUp([track2, track3]); // Assert @@ -672,7 +672,7 @@ public void MoveUp_TracksAbove_ReturnsSuccess() track1.Audiofile = cuesheet.Audiofiles.First(); track2.Audiofile = cuesheet.Audiofiles.First(); track3.Audiofile = cuesheet.Audiofiles.First(); - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.MoveUp([track2, track3]); // Assert @@ -850,19 +850,18 @@ public void MoveUp_AudiofilesAbove_ReturnsSuccess() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); track1.Cuesheet = cuesheet; track2.Cuesheet = cuesheet; track3.Cuesheet = cuesheet; track1.Audiofile = file2; track2.Audiofile = file2; track3.Audiofile = file3; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); // Act var result = _cuesheetManager.MoveUp([file2, file3]); // Assert Assert.IsTrue(result.IsSuccess); - CollectionAssert.AreEquivalent(new List([file2, file3, file1]), cuesheet.Audiofiles.ToList()); + Assert.AreSequenceEqual(new List([file2, file3, file1]), cuesheet.Audiofiles); Assert.IsEmpty(file1.Tracks); Assert.AreEqual((ushort?)1, track1.Position); Assert.AreEqual(TimeSpan.Zero, track1.Begin); @@ -890,7 +889,7 @@ public void MoveUp_NoAudiofilesAbove_ReturnsFailure() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.MoveUp([file1, file2]); // Assert @@ -911,7 +910,7 @@ public void MoveUp_NoAudiofilesSelected_ReturnsFailure() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.MoveUp(new HashSet()); // Assert @@ -965,7 +964,7 @@ public void MoveDown_TracksSwitchingAudiofile_ReturnsSuccess() track1.Audiofile = cuesheet.Audiofiles.First(); track2.Audiofile = cuesheet.Audiofiles.First(); track3.Audiofile = cuesheet.Audiofiles.Last(); - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.MoveDown([track2, track1]); // Assert @@ -1027,7 +1026,7 @@ public void MoveDown_TracksBelow_ReturnsSuccess() track1.Audiofile = cuesheet.Audiofiles.First(); track2.Audiofile = cuesheet.Audiofiles.First(); track3.Audiofile = cuesheet.Audiofiles.First(); - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.MoveDown([track2, track1]); // Assert @@ -1205,19 +1204,18 @@ public void MoveDown_AudiofilesBelow_ReturnsSuccess() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); track1.Cuesheet = cuesheet; track2.Cuesheet = cuesheet; track3.Cuesheet = cuesheet; track1.Audiofile = file2; track2.Audiofile = file2; track3.Audiofile = file3; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); // Act var result = _cuesheetManager.MoveDown([file2, file1]); // Assert Assert.IsTrue(result.IsSuccess); - CollectionAssert.AreEquivalent(new List([file3, file2, file1]), cuesheet.Audiofiles.ToList()); + Assert.AreSequenceEqual(new List([file3, file2, file1]), cuesheet.Audiofiles); Assert.AreEqual((ushort?)1, track1.Position); Assert.AreEqual(TimeSpan.Zero, track1.Begin); Assert.AreEqual(track1End, track1.End); @@ -1244,7 +1242,7 @@ public void MoveDown_NoAudiofilesBelow_ReturnsFailure() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.MoveDown([file2, file3]); // Assert @@ -1265,7 +1263,7 @@ public void MoveDown_NoAudiofilesSelected_ReturnsFailure() { Audiofiles = [file1, file2, file3], }; - _sessionStateContainer.Setup(x => x.GetActiveCuesheet()).Returns(cuesheet); + _sessionStateContainer.Setup(x => x.ActiveCuesheet).Returns(cuesheet); // Act var result = _cuesheetManager.MoveDown(new HashSet()); // Assert diff --git a/AudioCuesheetEditor/Services/AudioCuesheet/AudiofileManager.cs b/AudioCuesheetEditor/Services/AudioCuesheet/AudiofileManager.cs index a169a3cb..5f101ac4 100644 --- a/AudioCuesheetEditor/Services/AudioCuesheet/AudiofileManager.cs +++ b/AudioCuesheetEditor/Services/AudioCuesheet/AudiofileManager.cs @@ -80,7 +80,7 @@ public void AddTrack(Audiofile audiofile, Track track, Boolean setTracing = true { _traceChangeManager.BulkEdit = true; } - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; track.Cuesheet = cuesheet; track.Audiofile = audiofile; if ((cuesheet?.IsRecording == true) && cuesheet.Audiofiles.SelectMany(x => x.Tracks).Any(x => x.Position >= 1)) @@ -107,7 +107,7 @@ public void AddTrack(Audiofile audiofile, Track track, Boolean setTracing = true /// public void RemoveTracks(Audiofile audiofile, IEnumerable tracksToRemove, Boolean setTracing = true) { - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; var intersection = audiofile.Tracks.Intersect(tracksToRemove); foreach (var track in intersection) { @@ -194,7 +194,7 @@ void RecalculateTrackProperties(Cuesheet cuesheet) } } - Track? GetLastTrack(Audiofile audiofile) + static Track? GetLastTrack(Audiofile audiofile) { return audiofile.Tracks.OrderByDescending(x => x.Position.HasValue).ThenBy(x => x.Position) .ThenByDescending(x => x.Begin.HasValue).ThenBy(x => x.Begin) diff --git a/AudioCuesheetEditor/Services/AudioCuesheet/CuesheetManager.cs b/AudioCuesheetEditor/Services/AudioCuesheet/CuesheetManager.cs index 5ba287d8..2cc9153c 100644 --- a/AudioCuesheetEditor/Services/AudioCuesheet/CuesheetManager.cs +++ b/AudioCuesheetEditor/Services/AudioCuesheet/CuesheetManager.cs @@ -37,7 +37,7 @@ public class CuesheetManager(ITraceChangeManager traceChangeManager, ISessionSta public void SetProperty(Expression> propertyExpression, TProperty value) { _traceChangeManager.BulkEdit = true; - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; SetValue(cuesheet!, propertyExpression, value); _traceChangeManager.BulkEdit = false; } @@ -107,7 +107,7 @@ public bool IsMoveUpPossible(HashSet selectedAudiofiles) { return false; } - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; if (cuesheet?.Audiofiles.Count > 0) { return !selectedAudiofiles.Contains(cuesheet.Audiofiles.First()); @@ -116,7 +116,7 @@ public bool IsMoveUpPossible(HashSet selectedAudiofiles) } /// - public bool IsMoveDownPossible(HashSet selectedTracks) => selectedTracks.Count > 0 && selectedTracks.Max(x => x.Position) < _sessionStateContainer.GetActiveCuesheet()?.Audiofiles.SelectMany(x => x.Tracks).Max(x => x.Position); + public bool IsMoveDownPossible(HashSet selectedTracks) => selectedTracks.Count > 0 && selectedTracks.Max(x => x.Position) < _sessionStateContainer.ActiveCuesheet?.Audiofiles.SelectMany(x => x.Tracks).Max(x => x.Position); /// public bool IsMoveDownPossible(HashSet selectedAudiofiles) @@ -125,7 +125,7 @@ public bool IsMoveDownPossible(HashSet selectedAudiofiles) { return false; } - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; if (cuesheet?.Audiofiles.Count > 0) { return !selectedAudiofiles.Contains(cuesheet.Audiofiles.Last()); @@ -141,7 +141,7 @@ public Result MoveUp(HashSet selectedTracks) return Result.Failure(new Error(ErrorType.NotPossible, "Moving tracks up is not possible!")); } _traceChangeManager.BulkEdit = true; - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; foreach (var selectedTrack in selectedTracks.OrderBy(x => x.Position)) { var previousTrack = cuesheet?.Audiofiles.SelectMany(x => x.Tracks).FirstOrDefault(x => x.Position == selectedTrack.Position - 1); @@ -181,7 +181,7 @@ public Result MoveUp(HashSet selectedAudiofiles) { return Result.Failure(new Error(ErrorType.NotPossible, "Moving audiofiles up is not possible!")); } - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; _traceChangeManager.BulkEdit = true; var newAudiofiles = new List(cuesheet!.Audiofiles); foreach (var audiofile in selectedAudiofiles) @@ -216,7 +216,7 @@ public Result MoveDown(HashSet selectedTracks) return Result.Failure(new Error(ErrorType.NotPossible, "Moving tracks down is not possible!")); } _traceChangeManager.BulkEdit = true; - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; foreach (var selectedTrack in selectedTracks.OrderByDescending(x => x.Position)) { var nextTrack = cuesheet?.Audiofiles.SelectMany(x => x.Tracks).FirstOrDefault(x => x.Position == selectedTrack.Position + 1); @@ -255,7 +255,7 @@ public Result MoveDown(HashSet selectedAudiofiles) { return Result.Failure(new Error(ErrorType.NotPossible, "Moving audiofiles down is not possible!")); } - var cuesheet = _sessionStateContainer.GetActiveCuesheet(); + var cuesheet = _sessionStateContainer.ActiveCuesheet; _traceChangeManager.BulkEdit = true; var newAudiofiles = new List(cuesheet!.Audiofiles); foreach (var audiofile in selectedAudiofiles) diff --git a/AudioCuesheetEditor/Shared/Cuesheet/Audiofiles.razor b/AudioCuesheetEditor/Shared/Cuesheet/Audiofiles.razor index c422360c..787340cd 100644 --- a/AudioCuesheetEditor/Shared/Cuesheet/Audiofiles.razor +++ b/AudioCuesheetEditor/Shared/Cuesheet/Audiofiles.razor @@ -66,7 +66,19 @@ along with Foobar. If not, see @code { - Cuesheet? _cuesheet => _sessionStateContainer.GetActiveCuesheet(); + Cuesheet? _cuesheet => _sessionStateContainer.ActiveCuesheet; + + protected override void OnInitialized() + { + base.OnInitialized(); + _sessionStateContainer.ActiveCuesheetChanged += SessionStateContainer_ActiveCuesheetChanged; + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + _sessionStateContainer.ActiveCuesheetChanged -= SessionStateContainer_ActiveCuesheetChanged; + } [Parameter] [EditorRequired] @@ -124,4 +136,9 @@ along with Foobar. If not, see } SelectedFilesChanged.InvokeAsync(SelectedFiles); } + + void SessionStateContainer_ActiveCuesheetChanged(object? sender, EventArgs args) + { + StateHasChanged(); + } } diff --git a/AudioCuesheetEditor/Shared/Cuesheet/CuesheetData.razor b/AudioCuesheetEditor/Shared/Cuesheet/CuesheetData.razor index 097d8ee1..ffb72f59 100644 --- a/AudioCuesheetEditor/Shared/Cuesheet/CuesheetData.razor +++ b/AudioCuesheetEditor/Shared/Cuesheet/CuesheetData.razor @@ -49,7 +49,7 @@ along with Foobar. If not, see [CascadingParameter] public ViewMode CurrentViewMode { get; set; } - Cuesheet? _cuesheet => _sessionStateContainer.GetActiveCuesheet(); + Cuesheet? _cuesheet => _sessionStateContainer.ActiveCuesheet; string? _catalogueNumber; MudForm? _form; MudTextField? _catalogueNumberTextField; @@ -59,8 +59,7 @@ along with Foobar. If not, see base.OnInitialized(); TraceChangeManager.UndoDone += TraceChangeManager_UndoDone; TraceChangeManager.RedoDone += TraceChangeManager_RedoDone; - _sessionStateContainer.CuesheetChanged += SessionStateContainer_CuesheetChanged; - _sessionStateContainer.ImportCuesheetChanged += SessionStateContainer_ImportCuesheetChanged; + _sessionStateContainer.ActiveCuesheetChanged += SessionStateContainer_ActiveCuesheetChanged; } protected override void Dispose(bool disposing) @@ -68,8 +67,7 @@ along with Foobar. If not, see base.Dispose(disposing); TraceChangeManager.UndoDone -= TraceChangeManager_UndoDone; TraceChangeManager.RedoDone -= TraceChangeManager_RedoDone; - _sessionStateContainer.CuesheetChanged -= SessionStateContainer_CuesheetChanged; - _sessionStateContainer.ImportCuesheetChanged -= SessionStateContainer_ImportCuesheetChanged; + _sessionStateContainer.ActiveCuesheetChanged -= SessionStateContainer_ActiveCuesheetChanged; } protected override void OnParametersSet() @@ -145,12 +143,7 @@ along with Foobar. If not, see _catalogueNumberTextField?.ResetAsync(); } - void SessionStateContainer_CuesheetChanged(object? sender, EventArgs args) - { - StateHasChanged(); - } - - void SessionStateContainer_ImportCuesheetChanged(object? sender, EventArgs args) + void SessionStateContainer_ActiveCuesheetChanged(object? sender, EventArgs args) { StateHasChanged(); } diff --git a/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor b/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor index 9ca20ac7..da31a536 100644 --- a/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor +++ b/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor @@ -80,10 +80,22 @@ along with Foobar. If not, see @code { - Cuesheet? _cuesheet => _sessionStateContainer.GetActiveCuesheet(); + Cuesheet? _cuesheet => _sessionStateContainer.ActiveCuesheet; ICollection _audiofiles => _cuesheet != null ? _cuesheet.Audiofiles : []; HashSet _selectedAudiofiles = []; + protected override void OnInitialized() + { + base.OnInitialized(); + _sessionStateContainer.ActiveCuesheetChanged += SessionStateContainer_ActiveCuesheetChanged; + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + _sessionStateContainer.ActiveCuesheetChanged -= SessionStateContainer_ActiveCuesheetChanged; + } + void AddButtonClicked() { var files = new List(_audiofiles); @@ -113,4 +125,9 @@ along with Foobar. If not, see _cuesheetManager.SetProperty(x => x.Audiofiles, files); } } + + void SessionStateContainer_ActiveCuesheetChanged(object? sender, EventArgs args) + { + StateHasChanged(); + } } \ No newline at end of file From 21d6a33772b41266fbef025fb4d0a0de35785085 Mon Sep 17 00:00:00 2001 From: NeoCodeMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Fri, 18 Sep 2026 08:37:40 +0200 Subject: [PATCH 3/7] fix tests --- .../AudioCuesheet/CuesheetManagerTests.cs | 2 +- .../Services/UI/SessionStateContainerTests.cs | 62 +++++++++++++++++-- .../Services/UI/ISessionStateContainer.cs | 2 - .../Services/UI/SessionStateContainer.cs | 29 +++++---- 4 files changed, 71 insertions(+), 24 deletions(-) diff --git a/AudioCuesheetEditor.Tests/Services/AudioCuesheet/CuesheetManagerTests.cs b/AudioCuesheetEditor.Tests/Services/AudioCuesheet/CuesheetManagerTests.cs index 28da198f..39a36e29 100644 --- a/AudioCuesheetEditor.Tests/Services/AudioCuesheet/CuesheetManagerTests.cs +++ b/AudioCuesheetEditor.Tests/Services/AudioCuesheet/CuesheetManagerTests.cs @@ -1215,7 +1215,7 @@ public void MoveDown_AudiofilesBelow_ReturnsSuccess() var result = _cuesheetManager.MoveDown([file2, file1]); // Assert Assert.IsTrue(result.IsSuccess); - Assert.AreSequenceEqual(new List([file3, file2, file1]), cuesheet.Audiofiles); + Assert.AreSequenceEqual(new List([file3, file1, file2]), cuesheet.Audiofiles); Assert.AreEqual((ushort?)1, track1.Position); Assert.AreEqual(TimeSpan.Zero, track1.Begin); Assert.AreEqual(track1End, track1.End); diff --git a/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs b/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs index 1cf99b03..113c09cc 100644 --- a/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs +++ b/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs @@ -21,7 +21,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; -using System.Linq.Expressions; using System.Threading.Tasks; namespace AudioCuesheetEditor.Tests.Services.UI @@ -39,12 +38,15 @@ public SessionStateContainerTests() } [TestMethod] - public void Cuesheet_SetNewValue_ShouldTriggerCuesheetChangedEvent() + public async Task Cuesheet_SetNewValueInDetailView_ShouldTriggerActiveCuesheetChangedEventAsync() { // Arrange var newCuesheet = new Cuesheet(); + var viewOptions = new ViewOptions(); + _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); + await _sessionStateContainer.InitializeAsync(); bool eventTriggered = false; - _sessionStateContainer.CuesheetChanged += (sender, args) => eventTriggered = true; + _sessionStateContainer.ActiveCuesheetChanged += (sender, args) => eventTriggered = true; // Act _sessionStateContainer.Cuesheet = newCuesheet; @@ -54,12 +56,39 @@ public void Cuesheet_SetNewValue_ShouldTriggerCuesheetChangedEvent() } [TestMethod] - public void ImportCuesheet_SetNewValue_ShouldTriggerImportCuesheetChangedEvent() + public async Task Cuesheet_SetNewValueInImportView_ShouldNotTriggerActiveCuesheetChangedEventAsync() + { + // Arrange + var newCuesheet = new Cuesheet(); + var viewOptions = new ViewOptions() + { + ActiveTab = ViewMode.ImportView + }; + _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); + await _sessionStateContainer.InitializeAsync(); + bool eventTriggered = false; + _sessionStateContainer.ActiveCuesheetChanged += (sender, args) => eventTriggered = true; + + // Act + _sessionStateContainer.Cuesheet = newCuesheet; + + // Assert + Assert.IsFalse(eventTriggered); + } + + [TestMethod] + public async Task ImportCuesheet_SetNewValueInImportView_ShouldTriggerActiveCuesheetChangedEventAsync() { // Arrange var newImportCuesheet = new Cuesheet(); + var viewOptions = new ViewOptions() + { + ActiveTab = ViewMode.ImportView + }; + _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); + await _sessionStateContainer.InitializeAsync(); bool eventTriggered = false; - _sessionStateContainer.ImportCuesheetChanged += (sender, args) => eventTriggered = true; + _sessionStateContainer.ActiveCuesheetChanged += (sender, args) => eventTriggered = true; // Act _sessionStateContainer.ImportCuesheet = newImportCuesheet; @@ -69,9 +98,30 @@ public void ImportCuesheet_SetNewValue_ShouldTriggerImportCuesheetChangedEvent() } [TestMethod] - public void ResetImport_ShouldClearImportProperties() + public async Task ImportCuesheet_SetNewValueInDetailView_ShouldTriggerActiveCuesheetChangedEventAsync() + { + // Arrange + var newImportCuesheet = new Cuesheet(); + var viewOptions = new ViewOptions(); + _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); + await _sessionStateContainer.InitializeAsync(); + bool eventTriggered = false; + _sessionStateContainer.ActiveCuesheetChanged += (sender, args) => eventTriggered = true; + + // Act + _sessionStateContainer.ImportCuesheet = newImportCuesheet; + + // Assert + Assert.IsFalse(eventTriggered); + } + + [TestMethod] + public async Task ResetImport_InitializedService_ShouldClearPropertiesAsync() { // Arrange + var viewOptions = new ViewOptions(); + _localStorageOptionsProvider.Setup(x => x.GetOptionsAsync()).ReturnsAsync(viewOptions); + await _sessionStateContainer.InitializeAsync(); _sessionStateContainer.Importfile = Mock.Of(); _sessionStateContainer.ImportCuesheet = new Cuesheet(); diff --git a/AudioCuesheetEditor/Services/UI/ISessionStateContainer.cs b/AudioCuesheetEditor/Services/UI/ISessionStateContainer.cs index 6e9a2f44..a4ea5331 100644 --- a/AudioCuesheetEditor/Services/UI/ISessionStateContainer.cs +++ b/AudioCuesheetEditor/Services/UI/ISessionStateContainer.cs @@ -21,8 +21,6 @@ namespace AudioCuesheetEditor.Services.UI { public interface ISessionStateContainer { - public event EventHandler? CuesheetChanged; - public event EventHandler? ImportCuesheetChanged; public event EventHandler? ActiveCuesheetChanged; public Cuesheet Cuesheet { get; set; } public Cuesheet? ImportCuesheet { get; set; } diff --git a/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs b/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs index bf125e86..0f3d8ac9 100644 --- a/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs +++ b/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs @@ -28,11 +28,9 @@ public class SessionStateContainer : ISessionStateContainer, IDisposable private Cuesheet _cuesheet = new(); private Cuesheet? _importCuesheet; private Cuesheet? _activeCuesheet; - private Boolean _initialized = false; + private ViewOptions? _viewOptions; private bool disposedValue; - public event EventHandler? CuesheetChanged; - public event EventHandler? ImportCuesheetChanged; public event EventHandler? ActiveCuesheetChanged; public SessionStateContainer(ILocalStorageOptionsProvider localStorageOptionsProvider) @@ -53,7 +51,7 @@ public Cuesheet Cuesheet set { _cuesheet = value; - CuesheetChanged?.Invoke(this, EventArgs.Empty); + SetActiveCuesheet(); } } public Cuesheet? ImportCuesheet @@ -62,22 +60,18 @@ public Cuesheet? ImportCuesheet set { _importCuesheet = value; - ImportCuesheetChanged?.Invoke(this, EventArgs.Empty); + SetActiveCuesheet(); } } public IList ImportAudiofiles { get; set; } = []; - public IImportfile? Importfile{ get; set; } + public IImportfile? Importfile { get; set; } public Boolean ImportIsAnalyzed { get; set; } = false; /// public async Task InitializeAsync() { - if (_initialized == false) - { - var viewOptions = await _localStorageOptionsProvider.GetOptionsAsync(); - SetActiveCuesheet(viewOptions); - } - _initialized = true; + _viewOptions ??= await _localStorageOptionsProvider.GetOptionsAsync(); + SetActiveCuesheet(); } public void ResetImport() @@ -106,13 +100,18 @@ void LocalStorageOptionsProvider_OptionSaved(object? sender, IOptions options) { if (options is ViewOptions viewOptions) { - SetActiveCuesheet(viewOptions); + _viewOptions = viewOptions; + SetActiveCuesheet(); } } - void SetActiveCuesheet(ViewOptions viewOptions) + void SetActiveCuesheet() { - if (viewOptions.ActiveTab == ViewMode.ImportView) + if (_viewOptions == null) + { + throw new InvalidOperationException("Not initialized!"); + } + if (_viewOptions.ActiveTab == ViewMode.ImportView) { if (_activeCuesheet != ImportCuesheet) { From 0b77052ab6ca41ea0fdd2c9c1c7627ea021bd785 Mon Sep 17 00:00:00 2001 From: NeoCodeMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Fri, 18 Sep 2026 08:43:33 +0200 Subject: [PATCH 4/7] fix resetimport --- .../Services/UI/SessionStateContainerTests.cs | 2 ++ AudioCuesheetEditor/Services/UI/SessionStateContainer.cs | 1 + 2 files changed, 3 insertions(+) diff --git a/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs b/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs index 113c09cc..0ba87be4 100644 --- a/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs +++ b/AudioCuesheetEditor.Tests/Services/UI/SessionStateContainerTests.cs @@ -124,6 +124,7 @@ public async Task ResetImport_InitializedService_ShouldClearPropertiesAsync() await _sessionStateContainer.InitializeAsync(); _sessionStateContainer.Importfile = Mock.Of(); _sessionStateContainer.ImportCuesheet = new Cuesheet(); + _sessionStateContainer.ImportIsAnalyzed = true; // Act _sessionStateContainer.ResetImport(); @@ -132,6 +133,7 @@ public async Task ResetImport_InitializedService_ShouldClearPropertiesAsync() Assert.IsNull(_sessionStateContainer.Importfile); Assert.IsEmpty(_sessionStateContainer.ImportAudiofiles); Assert.IsNull(_sessionStateContainer.ImportCuesheet); + Assert.IsFalse(_sessionStateContainer.ImportIsAnalyzed); } [TestMethod] diff --git a/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs b/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs index 0f3d8ac9..d177360c 100644 --- a/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs +++ b/AudioCuesheetEditor/Services/UI/SessionStateContainer.cs @@ -79,6 +79,7 @@ public void ResetImport() Importfile = null; ImportAudiofiles = []; ImportCuesheet = null; + ImportIsAnalyzed = false; } /// From 86b74791695615e943d5b7ab0b52f811627094a0 Mon Sep 17 00:00:00 2001 From: NeoCodeMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Fri, 18 Sep 2026 08:46:52 +0200 Subject: [PATCH 5/7] Update DisplayAnalyzedResult.razor --- .../Shared/Import/DisplayAnalyzedResult.razor | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor b/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor index 99cee2d2..f750b9e2 100644 --- a/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor +++ b/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor @@ -36,22 +36,25 @@ along with Foobar. If not, see } else { - - - @_localizer["Common data"] - - - - - - - - @_localizer["Files"] - - - - - + @if (_sessionStateContainer.ImportCuesheet != null) + { + + + @_localizer["Common data"] + + + + + + + + @_localizer["Files"] + + + + + + } } @code { From 083e3ebef69cb3e5acda80ce60bdb1c24248e3b1 Mon Sep 17 00:00:00 2001 From: NeoCodeMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Fri, 18 Sep 2026 08:51:01 +0200 Subject: [PATCH 6/7] standardise audiofiles component --- .../Shared/Cuesheet/Audiofiles.razor | 25 +++---------------- .../Shared/Import/DisplayAnalyzedResult.razor | 2 +- .../Shared/ViewModes/ViewModeFull.razor | 2 +- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/AudioCuesheetEditor/Shared/Cuesheet/Audiofiles.razor b/AudioCuesheetEditor/Shared/Cuesheet/Audiofiles.razor index 787340cd..29222814 100644 --- a/AudioCuesheetEditor/Shared/Cuesheet/Audiofiles.razor +++ b/AudioCuesheetEditor/Shared/Cuesheet/Audiofiles.razor @@ -19,8 +19,6 @@ along with Foobar. If not, see @inject IStringLocalizer _localizer @inject IStringLocalizer _validationMessageLocalizer -@inject ISessionStateContainer _sessionStateContainer -@inject ICuesheetManager _cuesheetManager @inject IAudiofileManager _audiofileManager @inject IDialogService _dialogService @@ -28,7 +26,7 @@ along with Foobar. If not, see { case ViewMode.DetailView: case ViewMode.ImportView: - var validationResult = _cuesheet?.Validate(nameof(Cuesheet.Audiofiles)); + var validationResult = Cuesheet?.Validate(nameof(Cuesheet.Audiofiles)); if (validationResult?.Status == ValidationStatus.Error) { @@ -66,19 +64,9 @@ along with Foobar. If not, see @code { - Cuesheet? _cuesheet => _sessionStateContainer.ActiveCuesheet; - - protected override void OnInitialized() - { - base.OnInitialized(); - _sessionStateContainer.ActiveCuesheetChanged += SessionStateContainer_ActiveCuesheetChanged; - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - _sessionStateContainer.ActiveCuesheetChanged -= SessionStateContainer_ActiveCuesheetChanged; - } + [Parameter] + [EditorRequired] + public Cuesheet? Cuesheet { get; set; } [Parameter] [EditorRequired] @@ -136,9 +124,4 @@ along with Foobar. If not, see } SelectedFilesChanged.InvokeAsync(SelectedFiles); } - - void SessionStateContainer_ActiveCuesheetChanged(object? sender, EventArgs args) - { - StateHasChanged(); - } } diff --git a/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor b/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor index f750b9e2..927021be 100644 --- a/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor +++ b/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor @@ -51,7 +51,7 @@ else @_localizer["Files"] - + } diff --git a/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor b/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor index da31a536..77ae8bef 100644 --- a/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor +++ b/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor @@ -65,7 +65,7 @@ along with Foobar. If not, see - + From 083eab181e21dc00c5e2fdcadfa67c9daa0d328f Mon Sep 17 00:00:00 2001 From: NeoCodeMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Fri, 18 Sep 2026 08:54:34 +0200 Subject: [PATCH 7/7] standardise cuesheetdata component --- .../Shared/Cuesheet/CuesheetData.razor | 38 +++++++++---------- .../Shared/Import/DisplayAnalyzedResult.razor | 2 +- .../Shared/ViewModes/ViewModeFull.razor | 2 +- .../Shared/ViewModes/ViewModeRecord.razor | 2 +- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/AudioCuesheetEditor/Shared/Cuesheet/CuesheetData.razor b/AudioCuesheetEditor/Shared/Cuesheet/CuesheetData.razor index ffb72f59..f42de74b 100644 --- a/AudioCuesheetEditor/Shared/Cuesheet/CuesheetData.razor +++ b/AudioCuesheetEditor/Shared/Cuesheet/CuesheetData.razor @@ -24,20 +24,20 @@ along with Foobar. If not, see @inject ISessionStateContainer _sessionStateContainer @inject ICuesheetManager _cuesheetManager -@if (_cuesheet != null) +@if (Cuesheet != null) { - - + - @switch(CurrentViewMode) { case ViewMode.ImportView: case ViewMode.DetailView: - - + break; @@ -46,10 +46,13 @@ along with Foobar. If not, see } @code { + [Parameter] + [EditorRequired] + public Cuesheet? Cuesheet { get; set; } + [CascadingParameter] public ViewMode CurrentViewMode { get; set; } - Cuesheet? _cuesheet => _sessionStateContainer.ActiveCuesheet; string? _catalogueNumber; MudForm? _form; MudTextField? _catalogueNumberTextField; @@ -59,7 +62,6 @@ along with Foobar. If not, see base.OnInitialized(); TraceChangeManager.UndoDone += TraceChangeManager_UndoDone; TraceChangeManager.RedoDone += TraceChangeManager_RedoDone; - _sessionStateContainer.ActiveCuesheetChanged += SessionStateContainer_ActiveCuesheetChanged; } protected override void Dispose(bool disposing) @@ -67,18 +69,17 @@ along with Foobar. If not, see base.Dispose(disposing); TraceChangeManager.UndoDone -= TraceChangeManager_UndoDone; TraceChangeManager.RedoDone -= TraceChangeManager_RedoDone; - _sessionStateContainer.ActiveCuesheetChanged -= SessionStateContainer_ActiveCuesheetChanged; } protected override void OnParametersSet() { base.OnParametersSet(); - _catalogueNumber = _cuesheet?.Cataloguenumber; + _catalogueNumber = Cuesheet?.Cataloguenumber; } void OnCDTextfileSelected(IBrowserFile? browserFile) { - if (_cuesheet == null) + if (Cuesheet == null) { return; } @@ -92,10 +93,10 @@ along with Foobar. If not, see async Task CDTextFileRename() { - var newFileName = await ShowInputDialog(_cuesheet?.CDTextfile?.Name); + var newFileName = await ShowInputDialog(Cuesheet?.CDTextfile?.Name); if (String.IsNullOrEmpty(newFileName) == false) { - var cdTextFile = _cuesheet?.CDTextfile; + var cdTextFile = Cuesheet?.CDTextfile; if (cdTextFile != null) { cdTextFile.Name = newFileName; @@ -133,18 +134,13 @@ along with Foobar. If not, see void TraceChangeManager_RedoDone(object? sender, EventArgs e) { - _catalogueNumber = _cuesheet?.Cataloguenumber; + _catalogueNumber = Cuesheet?.Cataloguenumber; _catalogueNumberTextField?.ResetAsync(); } void TraceChangeManager_UndoDone(object? sender, EventArgs e) { - _catalogueNumber = _cuesheet?.Cataloguenumber; + _catalogueNumber = Cuesheet?.Cataloguenumber; _catalogueNumberTextField?.ResetAsync(); } - - void SessionStateContainer_ActiveCuesheetChanged(object? sender, EventArgs args) - { - StateHasChanged(); - } } diff --git a/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor b/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor index 927021be..c7d5889e 100644 --- a/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor +++ b/AudioCuesheetEditor/Shared/Import/DisplayAnalyzedResult.razor @@ -43,7 +43,7 @@ else @_localizer["Common data"] - + diff --git a/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor b/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor index 77ae8bef..dd1e6010 100644 --- a/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor +++ b/AudioCuesheetEditor/Shared/ViewModes/ViewModeFull.razor @@ -27,7 +27,7 @@ along with Foobar. If not, see @_localizer["Common data"] - + diff --git a/AudioCuesheetEditor/Shared/ViewModes/ViewModeRecord.razor b/AudioCuesheetEditor/Shared/ViewModes/ViewModeRecord.razor index c8c589b0..b993b1d8 100644 --- a/AudioCuesheetEditor/Shared/ViewModes/ViewModeRecord.razor +++ b/AudioCuesheetEditor/Shared/ViewModes/ViewModeRecord.razor @@ -38,7 +38,7 @@ along with Foobar. If not, see @_localizer["Common data"] - +