using System.Collections.Concurrent; using Avalonia.Media.Imaging; using Avalonia.Platform; using IBKRTrader.Core.Modularity; namespace IBKRTrader.App.Shell; /// /// Löst die toolkit-neutralen -Schlüssel gegen die /// Avalonia-Bildressourcen auf. Gegenstück zum gleichnamigen Helfer der WinForms-Shell – /// dieselben Schlüssel, dieselben PNG-Dateien, sodass Core und Module unverändert bleiben. /// public static class ViewIcons { /// Symbol-Schlüssel → Dateiname unter Resources/ (als Avalonia-Asset eingebettet). private static readonly Dictionary FileByKey = new(StringComparer.OrdinalIgnoreCase) { ["dashboard"] = "dashboard.png", ["workers"] = "system_time.png", ["logs"] = "error_log.png", ["settings"] = "setting_tools.png", ["congresstrading"] = "cross_reference.png", ["accounting"] = "coins_in_hand.png", ["supervisor"] = "token_quantifier.png", }; /// Standard-Symbolschlüssel je View-ID – identisch zur WinForms-Shell. private static readonly Dictionary DefaultKeyByViewId = new(StringComparer.OrdinalIgnoreCase) { ["core.dashboard"] = "dashboard", ["core.workers"] = "workers", ["core.logs"] = "logs", ["core.settings"] = "settings", ["congresstrading.main"] = "congresstrading", ["accounting.main"] = "accounting", ["supervisor.main"] = "supervisor", }; private static readonly ConcurrentDictionary Cache = new(); /// Bild zum Schlüssel, oder null (kein Symbol / Datei fehlt). public static Bitmap? Resolve(string? iconKey) { if (iconKey is null || !FileByKey.TryGetValue(iconKey, out var file)) return null; return Cache.GetOrAdd(iconKey, _ => { try { using var stream = AssetLoader.Open( new Uri($"avares://IBKRTrader.App/Assets/{file}")); return new Bitmap(stream); } catch { // Ein fehlendes Symbol darf die Oberfläche nie aufhalten – dann eben nur Text. return null; } }); } /// Setzt bei allen registrierten Views den Standard-Schlüssel, falls noch keiner gesetzt ist. public static void AssignDefaults(IModuleUiHost host) { foreach (var view in host.Views) if (view.IconKey is null && DefaultKeyByViewId.TryGetValue(view.Id, out var key)) view.IconKey = key; } }