From c9738a3044948ee9355e5e6bd7a709e86cf25bfe Mon Sep 17 00:00:00 2001 From: Nick Logozzo Date: Sat, 21 Oct 2023 23:44:46 -0400 Subject: [PATCH] All - Remeber Format String Used --- NickvisionTagger.GNOME/Controls/ComboBoxDialog.cs | 15 ++++++++++++++- NickvisionTagger.GNOME/Program.cs | 1 + NickvisionTagger.GNOME/Views/MainWindow.cs | 4 ++-- .../Controllers/MainWindowController.cs | 12 ++++++++++++ NickvisionTagger.Shared/Models/Configuration.cs | 10 ++++++++++ .../org.nickvision.tagger.metainfo.xml.in | 1 + NickvisionTagger.WinUI/App.xaml.cs | 1 + .../Controls/ComboBoxDialog.xaml.cs | 14 +++++++++++++- NickvisionTagger.WinUI/Views/MainWindow.xaml.cs | 4 ++-- 9 files changed, 56 insertions(+), 6 deletions(-) diff --git a/NickvisionTagger.GNOME/Controls/ComboBoxDialog.cs b/NickvisionTagger.GNOME/Controls/ComboBoxDialog.cs index 3e98adc3..de09284a 100644 --- a/NickvisionTagger.GNOME/Controls/ComboBoxDialog.cs +++ b/NickvisionTagger.GNOME/Controls/ComboBoxDialog.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using static Nickvision.Aura.Localization.Gettext; @@ -34,9 +35,11 @@ public partial class ComboBoxDialog /// The message of the dialog /// The title of the choices of the dialog /// The choices of the dialog + /// Whether or not a custom entry is supported + /// The previous choice used if available /// The text of the cancel button /// The text of the suggested button - public ComboBoxDialog(Gtk.Window parentWindow, string iconName, string title, string message, string choicesTitle, string[] choices, bool supportCustom, string cancelText, string suggestedText) + public ComboBoxDialog(Gtk.Window parentWindow, string iconName, string title, string message, string choicesTitle, string[] choices, bool supportCustom, string? previousChoice, string cancelText, string suggestedText) { Response = ""; _choices = choices; @@ -76,6 +79,16 @@ public ComboBoxDialog(Gtk.Window parentWindow, string iconName, string title, st _dialog.SetDefaultResponse("suggested"); _dialog.SetCloseResponse("cancel"); _dialog.OnResponse += (sender, e) => SetResponse(e.Response); + var previous = Array.IndexOf(_choices, previousChoice); + if (previous != -1) + { + _choicesRow.SetSelected((uint)previous); + } + else if (!string.IsNullOrEmpty(previousChoice)) + { + _choicesRow.SetSelected((uint)(_choices.Length - 1)); + _customRow.SetText(previousChoice); + } } public event GObject.SignalHandler OnResponse diff --git a/NickvisionTagger.GNOME/Program.cs b/NickvisionTagger.GNOME/Program.cs index ae4d86af..36fcf3f4 100644 --- a/NickvisionTagger.GNOME/Program.cs +++ b/NickvisionTagger.GNOME/Program.cs @@ -39,6 +39,7 @@ public Program(string[] args) * Added an option in Preferences to limit file name characters to those only supported by Windows * Tagger will now watch a music folder library for changes on disk and prompt the user to reload if necessary * Tagger will now display front album art within a music file row itself if available + * Tagger will now remember previously used format strings for file name to tag and tag to file name conversions * Fixed an issue where downloaded lyrics would sometimes contain html encoded characters * Fixed an issue where file names containing the ""<"" character caused the music file row to not display * Improved create playlist dialog ux diff --git a/NickvisionTagger.GNOME/Views/MainWindow.cs b/NickvisionTagger.GNOME/Views/MainWindow.cs index 3a91d584..2ffb73cc 100644 --- a/NickvisionTagger.GNOME/Views/MainWindow.cs +++ b/NickvisionTagger.GNOME/Views/MainWindow.cs @@ -1016,7 +1016,7 @@ private void RemoveFromPlaylist(Gio.SimpleAction sender, EventArgs e) /// EventArgs private void FilenameToTag(Gio.SimpleAction sender, EventArgs e) { - var dialog = new ComboBoxDialog(this, _controller.AppInfo.ID, _("File Name to Tag"), _("Please select a format string."), _("Format String"), _controller.FormatStrings, true, _("Cancel"), _("Convert")); + var dialog = new ComboBoxDialog(this, _controller.AppInfo.ID, _("File Name to Tag"), _("Please select a format string."), _("Format String"), _controller.FormatStrings, true, _controller.PreviousFTTFormatString, _("Cancel"), _("Convert")); dialog.OnResponse += async (s, ea) => { if (!string.IsNullOrEmpty(dialog.Response)) @@ -1035,7 +1035,7 @@ private void FilenameToTag(Gio.SimpleAction sender, EventArgs e) /// EventArgs private void TagToFilename(Gio.SimpleAction sender, EventArgs e) { - var dialog = new ComboBoxDialog(this, _controller.AppInfo.ID, _("Tag to File Name"), _("Please select a format string."), _("Format String"), _controller.FormatStrings, true, _("Cancel"), _("Convert")); + var dialog = new ComboBoxDialog(this, _controller.AppInfo.ID, _("Tag to File Name"), _("Please select a format string."), _("Format String"), _controller.FormatStrings, true, _controller.PreviousTTFFormatString, _("Cancel"), _("Convert")); dialog.OnResponse += async (s, ea) => { if (!string.IsNullOrEmpty(dialog.Response)) diff --git a/NickvisionTagger.Shared/Controllers/MainWindowController.cs b/NickvisionTagger.Shared/Controllers/MainWindowController.cs index 4cf40623..672f6cca 100644 --- a/NickvisionTagger.Shared/Controllers/MainWindowController.cs +++ b/NickvisionTagger.Shared/Controllers/MainWindowController.cs @@ -81,6 +81,14 @@ public class MainWindowController : IDisposable /// The list of paths to corrupted music files in the music library /// public List CorruptedFiles => _musicLibrary?.CorruptedFiles ?? new List(); + /// + /// The previous format string used by filename to tag + /// + public string PreviousFTTFormatString => Configuration.Current.PreviousFTTFormatString; + /// + /// The previous format string used by tag to filename + /// + public string PreviousTTFFormatString => Configuration.Current.PreviousTTFFormatString; /// /// Occurs when a notification is sent @@ -969,6 +977,8 @@ await Task.Run(() => if (success > 0) { UpdateSelectedMusicFilesProperties(); + Configuration.Current.PreviousFTTFormatString = formatString; + Aura.Active.SaveConfig("config"); } MusicFileSaveStatesChanged?.Invoke(this, MusicFileSaveStates.Any(x => !x)); NotificationSent?.Invoke(this, new NotificationSentEventArgs(_n("Converted {0} file name to tag successfully", "Converted {0} file names to tags successfully", success, success), NotificationSeverity.Success, "format")); @@ -1003,6 +1013,8 @@ await Task.Run(() => if (success > 0) { UpdateSelectedMusicFilesProperties(); + Configuration.Current.PreviousTTFFormatString = formatString; + Aura.Active.SaveConfig("config"); } MusicFileSaveStatesChanged?.Invoke(this, MusicFileSaveStates.Any(x => !x)); NotificationSent?.Invoke(this, new NotificationSentEventArgs(_n("Converted {0} tag to file name successfully", "Converted {0} tags to file names successfully", success, success), NotificationSeverity.Success, "format")); diff --git a/NickvisionTagger.Shared/Models/Configuration.cs b/NickvisionTagger.Shared/Models/Configuration.cs index b94633f2..3d1e2663 100644 --- a/NickvisionTagger.Shared/Models/Configuration.cs +++ b/NickvisionTagger.Shared/Models/Configuration.cs @@ -85,6 +85,14 @@ public class Configuration : ConfigurationBase /// public string AcoustIdUserAPIKey { get; set; } /// + /// The previous format string used by filename to tag + /// + public string PreviousFTTFormatString { get; set; } + /// + /// The previous format string used by tag to filename + /// + public string PreviousTTFFormatString { get; set; } + /// /// Whether or not to show the Extras Pane /// /// Used on WinUI only @@ -110,6 +118,8 @@ public Configuration() OverwriteAlbumArtWithMusicBrainz = true; OverwriteLyricsWithWebService = true; AcoustIdUserAPIKey = ""; + PreviousFTTFormatString = ""; + PreviousTTFFormatString = ""; ExtrasPane = true; } diff --git a/NickvisionTagger.Shared/org.nickvision.tagger.metainfo.xml.in b/NickvisionTagger.Shared/org.nickvision.tagger.metainfo.xml.in index 0811d233..c07dfd24 100644 --- a/NickvisionTagger.Shared/org.nickvision.tagger.metainfo.xml.in +++ b/NickvisionTagger.Shared/org.nickvision.tagger.metainfo.xml.in @@ -48,6 +48,7 @@

- Added an option in Preferences to limit file name characters to those only supported by Windows

- Tagger will now watch a music folder library for changes on disk and prompt the user to reload if necessary

- Tagger will now display front album art within a music file row itself if available

+

- Tagger will now remember previously used format strings for file name to tag and tag to file name conversions

- Fixed an issue where downloaded lyrics would sometimes contain html encoded characters

- Fixed an issue where file names containing the less than character caused the music file row to not display

- Improved create playlist dialog ux

diff --git a/NickvisionTagger.WinUI/App.xaml.cs b/NickvisionTagger.WinUI/App.xaml.cs index 890ab297..537f1cb3 100644 --- a/NickvisionTagger.WinUI/App.xaml.cs +++ b/NickvisionTagger.WinUI/App.xaml.cs @@ -29,6 +29,7 @@ public App() - Added information dialog for album art - Tagger will now watch a music folder library for changes on disk and prompt the user to reload if necessary - Tagger will now display front album art within a music file row itself if available +- Tagger will now remember previously used format strings for file name to tag and tag to file name conversions - Fixed an issue where downloaded lyrics would sometimes contain html encoded characters - Improved create playlist dialog ux - Updated translations (Thanks everyone on Weblate!)"; diff --git a/NickvisionTagger.WinUI/Controls/ComboBoxDialog.xaml.cs b/NickvisionTagger.WinUI/Controls/ComboBoxDialog.xaml.cs index e9ff29e6..587da9d9 100644 --- a/NickvisionTagger.WinUI/Controls/ComboBoxDialog.xaml.cs +++ b/NickvisionTagger.WinUI/Controls/ComboBoxDialog.xaml.cs @@ -23,9 +23,10 @@ public sealed partial class ComboBoxDialog : ContentDialog /// The title of the choices of the dialog /// The choices of the dialog /// Whether or not a custom entry is supported + /// The previous choice used if available /// The text of the close button /// The text of the primary button - public ComboBoxDialog(string title, string message, string choicesTitle, string[] choices, bool supportCustom, string closeText, string primaryText) + public ComboBoxDialog(string title, string message, string choicesTitle, string[] choices, bool supportCustom, string? previousChoice, string closeText, string primaryText) { InitializeComponent(); _choices = choices; @@ -51,6 +52,17 @@ public ComboBoxDialog(string title, string message, string choicesTitle, string[ CardCustom.Header = _("Custom"); TxtCustom.PlaceholderText = _("Enter custom choice here"); CmbChoices.SelectedIndex = 0; + //Load Previous + var previous = Array.IndexOf(_choices, previousChoice); + if (previous != -1) + { + CmbChoices.SelectedIndex = previous; + } + else if (!string.IsNullOrEmpty(previousChoice)) + { + CmbChoices.SelectedIndex = _choices.Length - 1; + TxtCustom.Text = previousChoice; + } } /// diff --git a/NickvisionTagger.WinUI/Views/MainWindow.xaml.cs b/NickvisionTagger.WinUI/Views/MainWindow.xaml.cs index 702f3311..70513aec 100644 --- a/NickvisionTagger.WinUI/Views/MainWindow.xaml.cs +++ b/NickvisionTagger.WinUI/Views/MainWindow.xaml.cs @@ -1120,7 +1120,7 @@ private async void AddCustomProperty(object sender, RoutedEventArgs e) /// RoutedEventArgs private async void FilenameToTag(object sender, RoutedEventArgs e) { - var dialog = new ComboBoxDialog(_("File Name to Tag"), _("Please select a format string."), _("Format String"), _controller.FormatStrings, true, _("Cancel"), _("Convert")) + var dialog = new ComboBoxDialog(_("File Name to Tag"), _("Please select a format string."), _("Format String"), _controller.FormatStrings, true, _controller.PreviousFTTFormatString, _("Cancel"), _("Convert")) { XamlRoot = MainGrid.XamlRoot }; @@ -1138,7 +1138,7 @@ private async void FilenameToTag(object sender, RoutedEventArgs e) /// RoutedEventArgs private async void TagToFilename(object sender, RoutedEventArgs e) { - var dialog = new ComboBoxDialog(_("Tag to File Name"), _("Please select a format string."), _("Format String"), _controller.FormatStrings, true, _("Cancel"), _("Convert")) + var dialog = new ComboBoxDialog(_("Tag to File Name"), _("Please select a format string."), _("Format String"), _controller.FormatStrings, true, _controller.PreviousTTFFormatString, _("Cancel"), _("Convert")) { XamlRoot = MainGrid.XamlRoot };