Skip to content

Commit 20e6c60

Browse files
authored
Code Quality: Fixed the way tags were initialized (#15216)
1 parent 1d543ad commit 20e6c60

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Files.App/Data/Items/ListedItem.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,27 @@ public BitmapImage CustomIcon
9292

9393
public ulong? FileFRN { get; set; }
9494

95-
private string[] fileTags; // TODO: initialize to empty array after UI is done
95+
private string[] fileTags = null!;
9696
public string[] FileTags
9797
{
9898
get => fileTags;
9999
set
100100
{
101+
// fileTags is null when the item is first created
102+
var fileTagsInitialized = fileTags is not null;
101103
if (SetProperty(ref fileTags, value))
102104
{
103105
Debug.Assert(value != null);
104-
var dbInstance = FileTagsHelper.GetDbInstance();
105-
dbInstance.SetTags(ItemPath, FileFRN, value);
106+
107+
// only set the tags if the file tags have been changed
108+
if (fileTagsInitialized)
109+
{
110+
var dbInstance = FileTagsHelper.GetDbInstance();
111+
dbInstance.SetTags(ItemPath, FileFRN, value);
112+
FileTagsHelper.WriteFileTag(ItemPath, value);
113+
}
114+
106115
HasTags = !FileTags.IsEmpty();
107-
FileTagsHelper.WriteFileTag(ItemPath, value);
108116
OnPropertyChanged(nameof(FileTagsUI));
109117
}
110118
}

0 commit comments

Comments
 (0)