Skip to content

Commit

Permalink
All - Remeber Format String Used
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Oct 22, 2023
1 parent e6b5f24 commit c9738a3
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 6 deletions.
15 changes: 14 additions & 1 deletion NickvisionTagger.GNOME/Controls/ComboBoxDialog.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using static Nickvision.Aura.Localization.Gettext;

Expand Down Expand Up @@ -34,9 +35,11 @@ public partial class ComboBoxDialog
/// <param name="message">The message of the dialog</param>
/// <param name="choicesTitle">The title of the choices of the dialog</param>
/// <param name="choices">The choices of the dialog</param>
/// <param name="supportCustom">Whether or not a custom entry is supported</param>
/// <param name="previousChoice">The previous choice used if available</param>
/// <param name="cancelText">The text of the cancel button</param>
/// <param name="suggestedText">The text of the suggested button</param>
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;
Expand Down Expand Up @@ -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<Adw.MessageDialog, Adw.MessageDialog.ResponseSignalArgs> OnResponse
Expand Down
1 change: 1 addition & 0 deletions NickvisionTagger.GNOME/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions NickvisionTagger.GNOME/Views/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ private void RemoveFromPlaylist(Gio.SimpleAction sender, EventArgs e)
/// <param name="e">EventArgs</param>
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))
Expand All @@ -1035,7 +1035,7 @@ private void FilenameToTag(Gio.SimpleAction sender, EventArgs e)
/// <param name="e">EventArgs</param>
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))
Expand Down
12 changes: 12 additions & 0 deletions NickvisionTagger.Shared/Controllers/MainWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public class MainWindowController : IDisposable
/// The list of paths to corrupted music files in the music library
/// </summary>
public List<string> CorruptedFiles => _musicLibrary?.CorruptedFiles ?? new List<string>();
/// <summary>
/// The previous format string used by filename to tag
/// </summary>
public string PreviousFTTFormatString => Configuration.Current.PreviousFTTFormatString;
/// <summary>
/// The previous format string used by tag to filename
/// </summary>
public string PreviousTTFFormatString => Configuration.Current.PreviousTTFFormatString;

/// <summary>
/// Occurs when a notification is sent
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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"));
Expand Down
10 changes: 10 additions & 0 deletions NickvisionTagger.Shared/Models/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public class Configuration : ConfigurationBase
/// </summary>
public string AcoustIdUserAPIKey { get; set; }
/// <summary>
/// The previous format string used by filename to tag
/// </summary>
public string PreviousFTTFormatString { get; set; }
/// <summary>
/// The previous format string used by tag to filename
/// </summary>
public string PreviousTTFFormatString { get; set; }
/// <summary>
/// Whether or not to show the Extras Pane
/// </summary>
/// <remarks>Used on WinUI only</remarks>
Expand All @@ -110,6 +118,8 @@ public Configuration()
OverwriteAlbumArtWithMusicBrainz = true;
OverwriteLyricsWithWebService = true;
AcoustIdUserAPIKey = "";
PreviousFTTFormatString = "";
PreviousTTFFormatString = "";
ExtrasPane = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<p>- Added an option in Preferences to limit file name characters to those only supported by Windows</p>
<p>- Tagger will now watch a music folder library for changes on disk and prompt the user to reload if necessary</p>
<p>- Tagger will now display front album art within a music file row itself if available</p>
<p>- Tagger will now remember previously used format strings for file name to tag and tag to file name conversions</p>
<p>- Fixed an issue where downloaded lyrics would sometimes contain html encoded characters</p>
<p>- Fixed an issue where file names containing the less than character caused the music file row to not display</p>
<p>- Improved create playlist dialog ux</p>
Expand Down
1 change: 1 addition & 0 deletions NickvisionTagger.WinUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!)";
Expand Down
14 changes: 13 additions & 1 deletion NickvisionTagger.WinUI/Controls/ComboBoxDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public sealed partial class ComboBoxDialog : ContentDialog
/// <param name="choicesTitle">The title of the choices of the dialog</param>
/// <param name="choices">The choices of the dialog</param>
/// <param name="supportCustom">Whether or not a custom entry is supported</param>
/// <param name="previousChoice">The previous choice used if available</param>
/// <param name="closeText">The text of the close button</param>
/// <param name="primaryText">The text of the primary button</param>
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;
Expand All @@ -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;
}
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions NickvisionTagger.WinUI/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ private async void AddCustomProperty(object sender, RoutedEventArgs e)
/// <param name="e">RoutedEventArgs</param>
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
};
Expand All @@ -1138,7 +1138,7 @@ private async void FilenameToTag(object sender, RoutedEventArgs e)
/// <param name="e">RoutedEventArgs</param>
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
};
Expand Down

0 comments on commit c9738a3

Please sign in to comment.