using System.ComponentModel;
using System.IO;
using System.Windows.Media;
namespace DeskCore;
public class CategoryItem
{
public required string Name { get; init; }
public bool IsDesktop { get; init; }
public int Count { get; set; }
public string Folder => IsDesktop ? Storage.UserDesktop : Storage.CategoryPath(Name);
public CategoryMeta? Meta => IsDesktop ? null : AppSettings.Current.Categories.GetValueOrDefault(Name);
public string Glyph => IsDesktop ? "" : Meta?.Glyph ?? "";
public Brush? GlyphBrush => CategoryColors.Brush(Meta?.Color);
public bool HasFence => !IsDesktop && AppSettings.Current.HasFence(Name);
}
/// Eintrag einer Start-Gruppe in der Seitenleiste.
public class LaunchGroupItem
{
public required LaunchGroup Group { get; init; }
public string Name => Group.Name;
public int Count => Group.Items.Count;
public string Glyph => ""; // Abspielen
public Brush? GlyphBrush => CategoryColors.Brush(Group.Color);
public bool HasFence => false;
public bool IsDesktop => true; // blendet den Umsortier-Griff der Kategorien aus
}
public static class CategoryColors
{
public static readonly (string Name, string Hex)[] All =
[
("Blau", "#3B82F6"), ("Türkis", "#12A594"), ("Grün", "#22A06B"), ("Gelb", "#E2A600"),
("Orange", "#F07A1A"), ("Rot", "#E5484D"), ("Pink", "#D6409F"), ("Lila", "#8E4EC6"), ("Grau", "#8B8D98"),
];
public static Brush? Brush(string? hex)
{
if (string.IsNullOrEmpty(hex)) return null;
try
{
var b = new SolidColorBrush((Color)ColorConverter.ConvertFromString(hex));
b.Freeze();
return b;
}
catch { return null; }
}
}
public static class CategoryGlyphs
{
public static readonly (string Glyph, string Name)[] All =
[
("", "Ordner"), ("", "Spiele"), ("", "Arbeit"), ("", "Code"),
("", "Musik"), ("", "Video"), ("", "Bilder"), ("", "Internet"),
("", "Mail"), ("", "Shopping"), ("", "System"), ("", "Werkzeuge"),
("", "Dokumente"), ("", "Favoriten"), ("", "Herz"), ("", "Cloud"),
("", "Downloads"), ("", "Personen"), ("", "Bibliothek"), ("", "Rechner"),
("", "Ideen"), ("", "Zuhause"), ("", "Lernen"), ("", "Erweiterungen"),
("", "Computer"), ("", "Sicherheit"), ("", "Ebenen"),
];
}
public class IconItem : INotifyPropertyChanged
{
public required string Path { get; init; }
public string? Category { get; init; }
private ImageSource? _icon;
public ImageSource? Icon
{
get => _icon;
set { _icon = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Icon))); }
}
/// Nur für Desktop-Icons: Kategorie, in der bereits eine Kopie liegt.
public string? SortedInto { get; init; }
public bool IsSorted => SortedInto is not null;
public string Name => Storage.DisplayName(Path);
public string TypeText
{
get
{
if (Directory.Exists(Path)) return "Ordner";
var ext = System.IO.Path.GetExtension(Path).ToLowerInvariant();
return ext switch
{
".lnk" => "Verknüpfung",
".url" => "Internetverknüpfung",
".exe" => "Programm",
"" => "Datei",
_ => ext.TrimStart('.').ToUpperInvariant() + "-Datei",
};
}
}
public string LocationText => SortedInto is not null ? $"✓ gesichert in {SortedInto}" : Category ?? "";
public string ToolTip =>
SortedInto is not null ? $"{Name}\n✓ Bereits gesichert in „{SortedInto}“ – kann vom Desktop gelöscht werden." :
Category is not null ? $"{Name}\nOrt: {Category}" : $"{Name}\n{TypeText}";
public event PropertyChangedEventHandler? PropertyChanged;
}