Files
quiver-launcher/Services/TagHelper.cs
T
Thomas GeorgiadisandCursor 81708d075f feat: ship Quiver Launcher v3.2.0
Add manually managed apps, library search, and catalog review that keeps extra local tags and pins.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-19 20:17:01 +10:00

100 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using QuiverLauncher;
namespace QuiverLauncher.Services
{
public static class TagHelper
{
public static List<string> NormalizeTags(IEnumerable<string>? tags)
{
if (tags == null)
return [];
return tags
.Select(t => t?.Trim().ToLowerInvariant() ?? string.Empty)
.Where(t => t.Length > 0)
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToList();
}
public static List<string> ParseCommaSeparatedTags(string? input) =>
NormalizeTags(input?.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries));
public static string FormatTagsForDisplay(IEnumerable<string>? tags)
{
var normalized = NormalizeTags(tags);
return normalized.Count == 0 ? string.Empty : string.Join(", ", normalized);
}
public static List<string> MergeTags(IEnumerable<string>? primary, IEnumerable<string>? secondary)
{
var merged = new List<string>();
merged.AddRange(NormalizeTags(primary));
merged.AddRange(NormalizeTags(secondary));
return NormalizeTags(merged);
}
/// <summary>
/// True when every catalog tag is present locally. Extra local tags are allowed.
/// </summary>
public static bool ContainsAllTags(IEnumerable<string>? localTags, IEnumerable<string>? catalogTags) =>
MatchesAllFilterTags(localTags, catalogTags);
public static bool MatchesAnyFilterTags(IEnumerable<string>? appTags, IEnumerable<string>? filterTags)
{
var normalizedAppTags = NormalizeTags(appTags);
var normalizedFilterTags = NormalizeTags(filterTags);
if (normalizedFilterTags.Count == 0)
return true;
if (normalizedAppTags.Count == 0)
return false;
return normalizedFilterTags.Any(filterTag =>
normalizedAppTags.Contains(filterTag, StringComparer.OrdinalIgnoreCase));
}
public static bool MatchesAllFilterTags(IEnumerable<string>? appTags, IEnumerable<string>? filterTags)
{
var normalizedAppTags = NormalizeTags(appTags);
var normalizedFilterTags = NormalizeTags(filterTags);
if (normalizedFilterTags.Count == 0)
return true;
if (normalizedAppTags.Count == 0)
return false;
return normalizedFilterTags.All(filterTag =>
normalizedAppTags.Contains(filterTag, StringComparer.OrdinalIgnoreCase));
}
public static bool MatchesFilterTags(
IEnumerable<string>? appTags,
IEnumerable<string>? filterTags,
TagFilterMatchMode matchMode) =>
matchMode == TagFilterMatchMode.All
? MatchesAllFilterTags(appTags, filterTags)
: MatchesAnyFilterTags(appTags, filterTags);
public static bool MatchesDisplayFilter(
IEnumerable<string>? appTags,
IEnumerable<string>? includeTags,
TagFilterMatchMode includeMode,
IEnumerable<string>? excludeTags,
TagFilterMatchMode excludeMode)
{
if (!MatchesFilterTags(appTags, includeTags, includeMode))
return false;
if (NormalizeTags(excludeTags).Count == 0)
return true;
return !MatchesFilterTags(appTags, excludeTags, excludeMode);
}
}
}