From 1b3ff1f07452bdd4cfbf370a02aaaf2617ff6db6 Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:01:56 +0200 Subject: [PATCH] added EditImportOptions component --- .../AudioCuesheetEditor.csproj | 4 + .../Model/Options/ImportOptions.cs | 21 +-- AudioCuesheetEditor/Pages/EditSections.razor | 10 +- .../Localization/EditImportOptions/de.json | 21 +++ .../Localization/EditImportOptions/en.json | 21 +++ .../Services/IO/TextImportService.cs | 1 + .../Shared/EditImportOptions.razor | 171 ++++++++++++++++++ .../Shared/EditTrackModal.razor | 22 +-- AudioCuesheetEditor/Shared/TracksTable.razor | 12 +- AudioCuesheetEditor/_Imports.razor | 2 + 10 files changed, 252 insertions(+), 33 deletions(-) create mode 100644 AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json create mode 100644 AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json create mode 100644 AudioCuesheetEditor/Shared/EditImportOptions.razor diff --git a/AudioCuesheetEditor/AudioCuesheetEditor.csproj b/AudioCuesheetEditor/AudioCuesheetEditor.csproj index 7bb5869e..f0b6f137 100644 --- a/AudioCuesheetEditor/AudioCuesheetEditor.csproj +++ b/AudioCuesheetEditor/AudioCuesheetEditor.csproj @@ -53,6 +53,8 @@ + + @@ -98,6 +100,8 @@ + + diff --git a/AudioCuesheetEditor/Model/Options/ImportOptions.cs b/AudioCuesheetEditor/Model/Options/ImportOptions.cs index 1ee000a1..6231381d 100644 --- a/AudioCuesheetEditor/Model/Options/ImportOptions.cs +++ b/AudioCuesheetEditor/Model/Options/ImportOptions.cs @@ -21,18 +21,13 @@ namespace AudioCuesheetEditor.Model.Options { public class ImportOptions : IOptions { - public TextImportScheme TextImportScheme { get; set; } - public TimeSpanFormat? TimeSpanFormat { get; set; } - - public ImportOptions() - { - TextImportScheme = TextImportScheme.DefaultTextImportScheme; - } - - public ImportOptions(TextImportfile textImportfile) - { - TextImportScheme = textImportfile.TextImportScheme; - TimeSpanFormat = textImportfile.TimeSpanFormat; - } + public TextImportScheme TextImportScheme { get; set; } = TextImportScheme.DefaultTextImportScheme; + public TimeSpanFormat TimeSpanFormat { get; set; } = new(); + //TODO + //public ImportOptions(TextImportfile textImportfile) + //{ + // TextImportScheme = textImportfile.TextImportScheme; + // TimeSpanFormat = textImportfile.TimeSpanFormat; + //} } } diff --git a/AudioCuesheetEditor/Pages/EditSections.razor b/AudioCuesheetEditor/Pages/EditSections.razor index 4f9c19ea..3a2c4ddf 100644 --- a/AudioCuesheetEditor/Pages/EditSections.razor +++ b/AudioCuesheetEditor/Pages/EditSections.razor @@ -20,7 +20,7 @@ along with Foobar. If not, see @inject ITextLocalizer _localizer @inject SessionStateContainer _sessionStateContainer @inject ITextLocalizer _validationMessageLocalizer -@inject DateTimeUtility _dateTimeUtility +@inject ApplicationOptionsTimeSpanParser _applicationOptionsTimeSpanParser @inject ITextLocalizerService _localizationService @inject TraceChangeManager _traceChangeManager @inject IJSRuntime _jsRuntime @@ -77,7 +77,7 @@ along with Foobar. If not, see - + @@ -86,7 +86,7 @@ along with Foobar. If not, see - + @@ -161,7 +161,9 @@ along with Foobar. If not, see switch (_sessionStateContainer.CurrentViewMode) { case ViewMode.ViewModeImport: - cuesheet = _sessionStateContainer.ImportCuesheet; + //TODO + // cuesheet = _sessionStateContainer.ImportCuesheet; + cuesheet = null; break; default: cuesheet = _sessionStateContainer.Cuesheet; diff --git a/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json new file mode 100644 index 00000000..4003da94 --- /dev/null +++ b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/de.json @@ -0,0 +1,21 @@ +{ + "culture": "de", + "translations": { + "Enter textimportscheme cuesheet tooltip": "Textschema für den Import von Cuesheeteigenschaften hier eingeben. Die Identifikation wird über reguläre Ausdrücke ausgeführt.", + "Enter textimportscheme cuesheet here": "Textschema für den Import von Cuesheeteigenschaften hier eingeben", + "Select placeholder": "Platzhalter auswählen", + "Enter textimportscheme track tooltip": "Textschema für den Import von Titeleigenschaften hier eingeben. Die Identifikation wird über reguläre Ausdrücke ausgeführt.", + "Enter textimportscheme track here": "Textschema für den Import von Titeleigenschaften hier eingeben", + "Textimportscheme cuesheet": "Import Schema Cuesheet", + "Textimportscheme track": "Import Schema Titel", + "Import Options": "Importoptionen", + "ENTER REGULAR EXPRESSION HERE": "Hier regulären Ausdruck eingeben", + "Enter custom timespan format here": "Hier können Sie bei Bedarf ein angepasstes Format für Zeitspannen eingeben. Details können der Hilfe entnommen werden.", + "Customized timespan format import": "Zeitspannenformat für Import", + "Days": "Tage", + "Hours": "Stunden", + "Minutes": "Minuten", + "Seconds": "Sekunden", + "Milliseconds": "Millisekunden" + } +} \ No newline at end of file diff --git a/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json new file mode 100644 index 00000000..e5966508 --- /dev/null +++ b/AudioCuesheetEditor/Resources/Localization/EditImportOptions/en.json @@ -0,0 +1,21 @@ +{ + "culture": "en", + "translations": { + "Enter textimportscheme cuesheet tooltip": "Enter textscheme for cuesheet properties import here. Identification will be done using regular expressions.", + "Enter textimportscheme cuesheet here": "Enter textscheme for cuesheet properties import here", + "Select placeholder": "Select placeholder", + "Enter textimportscheme track tooltip": "Enter textscheme for track properties import here. Identification will be done using regular expressions.", + "Enter textimportscheme track here": "Enter textscheme for track properties import here", + "Textimportscheme cuesheet": "Textimport scheme cuesheet", + "Textimportscheme track": "Textimport scheme track", + "Import Options": "Import options", + "ENTER REGULAR EXPRESSION HERE": "Enter regular expression here", + "Enter custom timespan format here": "You can enter a custom format for timespan here. Details can be found in help.", + "Customized timespan format import": "Timespan format for import", + "Days": "Days", + "Hours": "Hours", + "Minutes": "Minutes", + "Seconds": "Seconds", + "Milliseconds": "Milliseconds" + } +} \ No newline at end of file diff --git a/AudioCuesheetEditor/Services/IO/TextImportService.cs b/AudioCuesheetEditor/Services/IO/TextImportService.cs index 5edfb5a3..faca1fad 100644 --- a/AudioCuesheetEditor/Services/IO/TextImportService.cs +++ b/AudioCuesheetEditor/Services/IO/TextImportService.cs @@ -35,6 +35,7 @@ public TextImportfile Analyse(ImportOptions importOptions, IEnumerable TextImportfile importfile = new(); try { + importfile.FileContent = fileContent; ImportOptions = importOptions; AnalysedCuesheet = new ImportCuesheet(); Boolean cuesheetRecognized = false; diff --git a/AudioCuesheetEditor/Shared/EditImportOptions.razor b/AudioCuesheetEditor/Shared/EditImportOptions.razor new file mode 100644 index 00000000..b6308d71 --- /dev/null +++ b/AudioCuesheetEditor/Shared/EditImportOptions.razor @@ -0,0 +1,171 @@ + + +@implements IDisposable + +@inject ITextLocalizerService _localizationService +@inject ITextLocalizer _localizer +@inject ITextLocalizer _validationMessageLocalizer +@inject LocalStorageOptionsProvider _localStorageOptionsProvider + + + + + + + @_localizer["Textimportscheme cuesheet"] + + + + + + + + + + + + + + + @_localizer["Select placeholder"] + + + @foreach (var availableSchemeTrack in TextImportScheme.AvailableSchemeCuesheet) + { + @_localizer[availableSchemeTrack.Key] + } + + + + + + + + + + + + @_localizer["Textimportscheme track"] + + + + + + + + + + + + + + + @_localizer["Select placeholder"] + + + @foreach (var availableSchemeTrack in TextImportScheme.AvailableSchemesTrack) + { + @_localizer[availableSchemeTrack.Key] + } + + + + + + + + + + + + @_localizer["Customized timespan format import"] + + + + + + + + + + + + + + + @_localizer["Select placeholder"] + + + @foreach (var availableFormat in TimeSpanFormat.AvailableTimespanScheme) + { + @_localizer[availableFormat.Key] + } + + + + + + + + + +@code{ + //TODO: Changes to ImportOptions need to do a reanalysis + public ImportOptions? ImportOptions { get; private set; } + + public void Dispose() + { + _localizationService.LocalizationChanged -= LocalizationService_LocalizationChanged; + _localStorageOptionsProvider.OptionSaved -= LocalStorageOptionsProvider_OptionsSaved; + } + + protected override async Task OnInitializedAsync() + { + _localizationService.LocalizationChanged += LocalizationService_LocalizationChanged; + _localStorageOptionsProvider.OptionSaved += LocalStorageOptionsProvider_OptionsSaved; + + ImportOptions = await _localStorageOptionsProvider.GetOptions(); + + await base.OnInitializedAsync(); + } + + void LocalizationService_LocalizationChanged(object? sender, EventArgs args) + { + StateHasChanged(); + } + + void LocalStorageOptionsProvider_OptionsSaved(object? sender, IOptions options) + { + if (options is ImportOptions importOptions) + { + ImportOptions = importOptions; + StateHasChanged(); + } + } + + async Task TextChangedAsync(Action setter, string text) + { + if (ImportOptions == null) + { + throw new NullReferenceException(); + } + setter(ImportOptions, text); + await _localStorageOptionsProvider.SaveOptions(ImportOptions); + } +} \ No newline at end of file diff --git a/AudioCuesheetEditor/Shared/EditTrackModal.razor b/AudioCuesheetEditor/Shared/EditTrackModal.razor index b0b83d9c..3f42c390 100644 --- a/AudioCuesheetEditor/Shared/EditTrackModal.razor +++ b/AudioCuesheetEditor/Shared/EditTrackModal.razor @@ -25,7 +25,7 @@ along with Foobar. If not, see @inject TraceChangeManager _traceChangeManager @inject HotKeys _hotKeys @inject ITextLocalizer _validationMessageLocalizer -@inject DateTimeUtility _dateTimeUtility +@inject ApplicationOptionsTimeSpanParser _applicationOptionsTimeSpanParser @@ -102,7 +102,7 @@ along with Foobar. If not, see @_localizer["Begin"] - + @@ -114,7 +114,7 @@ along with Foobar. If not, see @_localizer["End"] - + @@ -126,7 +126,7 @@ along with Foobar. If not, see @_localizer["Length"] - + @@ -149,7 +149,7 @@ along with Foobar. If not, see @_localizer["PreGap"] - + @@ -161,7 +161,7 @@ along with Foobar. If not, see @_localizer["PostGap"] - + @@ -253,7 +253,7 @@ along with Foobar. If not, see - + @@ -271,7 +271,7 @@ along with Foobar. If not, see - + @@ -289,7 +289,7 @@ along with Foobar. If not, see - + @@ -319,7 +319,7 @@ along with Foobar. If not, see - + @@ -337,7 +337,7 @@ along with Foobar. If not, see - + diff --git a/AudioCuesheetEditor/Shared/TracksTable.razor b/AudioCuesheetEditor/Shared/TracksTable.razor index 6252e512..e47751ff 100644 --- a/AudioCuesheetEditor/Shared/TracksTable.razor +++ b/AudioCuesheetEditor/Shared/TracksTable.razor @@ -26,7 +26,7 @@ along with Foobar. If not, see @inject ITextLocalizerService _localizationService @inject MusicBrainzDataProvider _musicBrainzDataProvider @inject ITextLocalizer _validationMessageLocalizer -@inject DateTimeUtility _dateTimeUtility +@inject ApplicationOptionsTimeSpanParser _applicationOptionsTimeSpanParser @if (_sessionStateContainer.CurrentViewMode == ViewMode.ViewModeFull) @@ -341,7 +341,7 @@ along with Foobar. If not, see } - + @@ -353,7 +353,7 @@ along with Foobar. If not, see - + @@ -364,7 +364,7 @@ along with Foobar. If not, see - + @@ -408,7 +408,9 @@ along with Foobar. If not, see switch (_sessionStateContainer.CurrentViewMode) { case ViewMode.ViewModeImport: - cuesheet = _sessionStateContainer.ImportCuesheet; + //TODO + cuesheet = null; + // cuesheet = _sessionStateContainer.ImportCuesheet; break; default: cuesheet = _sessionStateContainer.Cuesheet; diff --git a/AudioCuesheetEditor/_Imports.razor b/AudioCuesheetEditor/_Imports.razor index f00ca655..b86c652b 100644 --- a/AudioCuesheetEditor/_Imports.razor +++ b/AudioCuesheetEditor/_Imports.razor @@ -24,6 +24,8 @@ @using AudioCuesheetEditor.Data.Options @using AudioCuesheetEditor.Model.Utility @using AudioCuesheetEditor.Data.Services +@using AudioCuesheetEditor.Services.IO +@using AudioCuesheetEditor.Services.UI @using Microsoft.Extensions.Logging @using Blazorise @using Blazorise.Components