Skip to content

Commit

Permalink
Code Quality: Fixed the way tags were initialized (files-community#15216
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hez2010 authored Apr 17, 2024
1 parent 1d543ad commit 20e6c60
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Files.App/Data/Items/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,27 @@ public BitmapImage CustomIcon

public ulong? FileFRN { get; set; }

private string[] fileTags; // TODO: initialize to empty array after UI is done
private string[] fileTags = null!;
public string[] FileTags
{
get => fileTags;
set
{
// fileTags is null when the item is first created
var fileTagsInitialized = fileTags is not null;
if (SetProperty(ref fileTags, value))
{
Debug.Assert(value != null);
var dbInstance = FileTagsHelper.GetDbInstance();
dbInstance.SetTags(ItemPath, FileFRN, value);

// only set the tags if the file tags have been changed
if (fileTagsInitialized)
{
var dbInstance = FileTagsHelper.GetDbInstance();
dbInstance.SetTags(ItemPath, FileFRN, value);
FileTagsHelper.WriteFileTag(ItemPath, value);
}

HasTags = !FileTags.IsEmpty();
FileTagsHelper.WriteFileTag(ItemPath, value);
OnPropertyChanged(nameof(FileTagsUI));
}
}
Expand Down

0 comments on commit 20e6c60

Please sign in to comment.