diff --git a/Core/Models/TagDatabase/TagDatabase.ImportMethods.cs b/Core/Models/TagDatabase/TagDatabase.ImportMethods.cs index a833858..7e0e7b1 100644 --- a/Core/Models/TagDatabase/TagDatabase.ImportMethods.cs +++ b/Core/Models/TagDatabase/TagDatabase.ImportMethods.cs @@ -28,7 +28,7 @@ public partial class TagDatabase // phase 2: add the parents and aliases. foreach (var tag in importDict.Values) { - var currentTag = this.Tags.SingleOrDefault(t => t.Name == tag.Name); + var currentTag = this.Tags.Single(t => t.Name == tag.Name); var parentIds = tag.Parents.Select(parentName => nameToId[parentName]).ToList(); @@ -47,6 +47,8 @@ public partial class TagDatabase private async Task WriteImportedParentsToDatabase(SqliteTransaction transaction, int targetId, List parentIds) { + if (this._currentConnection is null) + throw new InvalidOperationException(ErrorMessages.TagDatabaseNotInitialised); var valuesClauses = new List(); var parameters = new List(); diff --git a/Core/Models/TagDatabase/TagDatabase.cs b/Core/Models/TagDatabase/TagDatabase.cs index 1d6db23..5588b11 100644 --- a/Core/Models/TagDatabase/TagDatabase.cs +++ b/Core/Models/TagDatabase/TagDatabase.cs @@ -21,7 +21,7 @@ public partial class TagDatabase private const string TopLevelColumnName = "top_level"; private SqliteConnection? _currentConnection; - private List _defaultBindings = ["genre"]; + private readonly List _defaultBindings = ["genre"]; /// /// Initializes a new instance of the class. @@ -45,7 +45,7 @@ public partial class TagDatabase /// Gets or sets a List(string) of tag binding(s) that will be added to a tag by default. Defaults to genre /// (e.g. Festival Progressive House::genre). /// - public List DefaultTagBindings { get; set; } + public List DefaultTagBindings { get; set; } = []; /// /// Gets the location of the .thdb file associated with the , inferred from the current diff --git a/UI/ViewModels/HierarchyTreeViewModel.cs b/UI/ViewModels/HierarchyTreeViewModel.cs index 5e56708..fae7aa6 100644 --- a/UI/ViewModels/HierarchyTreeViewModel.cs +++ b/UI/ViewModels/HierarchyTreeViewModel.cs @@ -265,7 +265,7 @@ public partial class HierarchyTreeViewModel : ViewModelBase, IDisposable // public ICommand NewTagCommand => this._mainWindow.NewTagCommand; // ReSharper disable once PartialMethodParameterNameMismatch - partial void OnSelectedTagChanged(TagItemViewModel? _, TagItemViewModel? newValue) + partial void OnSelectedTagChanged(TagItemViewModel? oldValue, TagItemViewModel? newValue) { if (newValue is null || this._mainWindow.SelectedTagId == newValue.Id) return; this._mainWindow.SelectedTag = newValue; diff --git a/UI/ViewModels/TagItemViewModel.cs b/UI/ViewModels/TagItemViewModel.cs index 65de304..151987e 100644 --- a/UI/ViewModels/TagItemViewModel.cs +++ b/UI/ViewModels/TagItemViewModel.cs @@ -21,8 +21,6 @@ public partial class TagItemViewModel(Tag tag, Func, List> get [ObservableProperty] private string _editingTagBindings = string.Empty; - private bool _isInitialising; - public string Aliases => this.Tag.Aliases.Count > 0 ? string.Join("; ", this.Tag.Aliases) @@ -58,7 +56,6 @@ public partial class TagItemViewModel(Tag tag, Func, List> get public void BeginEdit() { - this._isInitialising = true; this.EditingName = this.Tag.Name; if (this.OnDatabase || string.IsNullOrEmpty(this.EditingParents)) @@ -68,7 +65,6 @@ public partial class TagItemViewModel(Tag tag, Func, List> get this.EditingTagBindings = this.CurrentTagBindings; this.EditingAliases = this.Aliases; this.EditingNotes = this.CurrentNotes; - this._isInitialising = false; } public void CommitEdit(Tag savedTag) @@ -87,7 +83,6 @@ public partial class TagItemViewModel(Tag tag, Func, List> get public void RefreshParentsString() { - this._isInitialising = true; this.OnPropertyChanged(nameof(this.CurrentParentsString)); var newParents = this.CurrentParentsString; if (!string.IsNullOrEmpty(newParents)) @@ -95,8 +90,6 @@ public partial class TagItemViewModel(Tag tag, Func, List> get this.EditingParents = newParents; this.OnPropertyChanged(nameof(this.EditingParents)); } - - this._isInitialising = false; } public void RefreshSelf() diff --git a/UI/Views/ValueConverters/AllNotNullOrEmptyConverter.cs b/UI/Views/ValueConverters/AllNotNullOrEmptyConverter.cs index 97f8452..a284215 100644 --- a/UI/Views/ValueConverters/AllNotNullOrEmptyConverter.cs +++ b/UI/Views/ValueConverters/AllNotNullOrEmptyConverter.cs @@ -10,7 +10,7 @@ public class AllNotNullOrEmptyMultiConverter : IMultiValueConverter { public static readonly AllNotNullOrEmptyMultiConverter Instance = new(); - public object Convert(IList values, Type targetType, object parameter, CultureInfo culture) + public object Convert(IList values, Type targetType, object? parameter, CultureInfo culture) { return values.All(v => v is string s ? !string.IsNullOrEmpty(s) : v is not null); } diff --git a/UI/Views/ValueConverters/AnyNotNullOrEmptyConverter.cs b/UI/Views/ValueConverters/AnyNotNullOrEmptyConverter.cs index a38c6ac..f61d8c8 100644 --- a/UI/Views/ValueConverters/AnyNotNullOrEmptyConverter.cs +++ b/UI/Views/ValueConverters/AnyNotNullOrEmptyConverter.cs @@ -10,7 +10,7 @@ public class AnyNotNullOrEmptyMultiConverter : IMultiValueConverter { public static readonly AnyNotNullOrEmptyMultiConverter Instance = new(); - public object Convert(IList values, Type targetType, object parameter, CultureInfo culture) + public object Convert(IList values, Type targetType, object? parameter, CultureInfo culture) { return values.Any(v => v is string s ? !string.IsNullOrEmpty(s) : v is not null); } diff --git a/UI/Views/ValueConverters/TruncationConverter.cs b/UI/Views/ValueConverters/TruncationConverter.cs index 00db90b..426b74c 100644 --- a/UI/Views/ValueConverters/TruncationConverter.cs +++ b/UI/Views/ValueConverters/TruncationConverter.cs @@ -8,7 +8,7 @@ public class TruncationConverter : IValueConverter { public static readonly TruncationConverter Instance = new(); - public object Convert(object? value, Type targetType, object parameter, CultureInfo culture) + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { if (value is not string s) return value; var limit = parameter is string p && int.TryParse(p, out var l) ? l : 50;