From b889fe177f0cf5b235e8d8f62e2186220682cd22 Mon Sep 17 00:00:00 2001 From: Flaky Date: Tue, 13 Jan 2026 20:19:17 +0000 Subject: [PATCH] disallow tag deletion if tag has children/sub-tags, fix parent string refresh --- UI/ViewModels/MainWindowViewModel.cs | 1 - UI/ViewModels/TagItemViewModel.cs | 19 ++++++++++++++----- UI/Views/MainWindow.axaml | 12 +++++++++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/UI/ViewModels/MainWindowViewModel.cs b/UI/ViewModels/MainWindowViewModel.cs index d038aaa..a14e0f2 100644 --- a/UI/ViewModels/MainWindowViewModel.cs +++ b/UI/ViewModels/MainWindowViewModel.cs @@ -147,7 +147,6 @@ public partial class MainWindowViewModel : ViewModelBase TagBindings = this.Database!.DefaultTagBindings } ); - this.SelectedTag.BeginEdit(); this.UnsavedChanges = true; } diff --git a/UI/ViewModels/TagItemViewModel.cs b/UI/ViewModels/TagItemViewModel.cs index 9c4ea7a..78654dd 100644 --- a/UI/ViewModels/TagItemViewModel.cs +++ b/UI/ViewModels/TagItemViewModel.cs @@ -42,6 +42,8 @@ public partial class TagItemViewModel(Tag tag, Func? getNameById = public string Notes => this.Tag.Notes; public bool OnDatabase => this.Id != 0; + + public bool HasChildren => this.Children.Count > 0; public string TagBindings => this.Tag.TagBindings.Count > 0 @@ -52,7 +54,7 @@ public partial class TagItemViewModel(Tag tag, Func? getNameById = private bool IsTopLevel => this.Tag.IsTopLevel; - private string Parents => getNameById != null && this.Tag.ParentIds.Count > 0 + private string Parents => getNameById != null && this.Tag.ParentIds is { Count: > 0 } ? string.Join("; ", this.Tag.ParentIds.Select(getNameById).Where(n => n != null)) : string.Empty; @@ -60,7 +62,10 @@ public partial class TagItemViewModel(Tag tag, Func? getNameById = { this._isInitialising = true; this.EditingName = this.Tag.Name; - this.EditingParents = this.Parents; + + if (this.OnDatabase || string.IsNullOrEmpty(this.EditingParents)) + this.EditingParents = this.Parents; + this.EditingIsTopLevel = this.IsTopLevel; this.EditingTagBindings = this.TagBindings; this.EditingAliases = this.Aliases; @@ -95,15 +100,19 @@ public partial class TagItemViewModel(Tag tag, Func? getNameById = this.OnPropertyChanged(nameof(this.TagBindings)); this.OnPropertyChanged(nameof(this.Notes)); this.OnPropertyChanged(nameof(this.IsTopLevel)); - + this.OnPropertyChanged(nameof(this.HasChildren)); } public void RefreshParentsString() { this._isInitialising = true; this.OnPropertyChanged(nameof(this.Parents)); - this.EditingParents = this.Parents; - this.OnPropertyChanged(nameof(this.EditingParents)); + var newParents = this.Parents; + if (!string.IsNullOrEmpty(newParents)) + { + this.EditingParents = newParents; + this.OnPropertyChanged(nameof(this.EditingParents)); + } this._isInitialising = false; } diff --git a/UI/Views/MainWindow.axaml b/UI/Views/MainWindow.axaml index e4a6609..b152251 100644 --- a/UI/Views/MainWindow.axaml +++ b/UI/Views/MainWindow.axaml @@ -124,9 +124,15 @@ -