Files
PolyTraderSharp/Ui/ViewIcons.cs
T
RichardandClaude Opus 5 ad1593bfc1 P1a: PolyTrader.Core auf net8.0 - UI-Contract toolkit-neutral
Der Core traegt keine WinForms-/System.Drawing-Abhaengigkeit mehr und baut als
plattformneutrales net8.0 (verifiziert: publish -r linux-x64 erfolgreich).

- ModuleView.CreateForm (Func<Form>) -> CreateView (Func<object>): die Shell kennt
  ihr Toolkit und castet, der Core nicht. Avalonia kann denselben Contract nutzen.
- ModuleView.Icon (System.Drawing.Image, seit .NET 7 Windows-only) -> IconKey (string).
  Aufloesung Schluessel->Bildressource neu in Ui/ViewIcons.cs, ersetzt Program.AssignMenuIcons.
- WindowMenu.cs (reine WinForms-Logik) aus dem Core nach Ui/ verschoben.
- WindowMenuTests entfernt: testet die eingefrorene WinForms-Menuelogik, die das
  Testprojekt nach dem Core-Schnitt nicht mehr erreicht. Im Tag winforms-final erhalten;
  das Avalonia-Gegenstueck bekommt eigene Tests (P6/P9).

Module und App bleiben vorerst net8.0-windows - ihre UI zieht erst mit der
Avalonia-Portierung um. Windows-App unveraendert lauffaehig (--smoke-ui gruen).

442 Tests gruen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-06 17:10:41 +02:00

62 lines
2.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using System.Drawing;
using PolyTrader.Core.Modularity;
namespace PolyTraderSharp.Ui
{
/// <summary>
/// Löst die toolkit-neutralen <see cref="ModuleView.IconKey"/>-Schlüssel gegen die WinForms-
/// Bildressourcen der App auf. Diese Zuordnung ist die einzige Stelle, an der Views und
/// Bilddaten zusammenkommen Core und Module kennen nur noch den Schlüssel als Zeichenkette.
///
/// Die Avalonia-Shell bekommt später ein eigenes Gegenstück mit denselben Schlüsseln; die
/// Registrierungen in Core und Modulen bleiben dabei unverändert.
/// </summary>
internal static class ViewIcons
{
/// <summary>Symbol-Schlüssel → Bildressource. Unbekannte Schlüssel liefern <c>null</c> (Text-only-Menüeintrag).</summary>
private static readonly Dictionary<string, Image> Map = new()
{
["dashboard"] = Properties.Resources.dashboard,
["settings"] = Properties.Resources.setting_tools,
["terminal"] = Properties.Resources.error_log,
["jobs"] = Properties.Resources.system_time,
["accounting"] = Properties.Resources.coins_in_hand,
["copytrading"] = Properties.Resources.cross_reference,
["resolutionfarming"] = Properties.Resources.file_start_workflow,
["supervisor"] = Properties.Resources.emotion_batman,
};
/// <summary>
/// Standard-Symbolschlüssel je View-ID. Greift für Views, die selbst keinen
/// <see cref="ModuleView.IconKey"/> setzen u.a. die Modul-Fenster, die die App-Ressourcen
/// nicht kennen. Ersetzt die frühere Icon-Zuweisung in <c>Program.AssignMenuIcons</c>.
/// </summary>
private static readonly Dictionary<string, string> DefaultKeyByViewId = new()
{
["core.dashboard"] = "dashboard",
["core.settings"] = "settings",
["core.terminal"] = "terminal",
["core.jobs"] = "jobs",
["accounting.main"] = "accounting",
["copytrading.main"] = "copytrading",
["resolutionfarming.main"] = "resolutionfarming",
["supervisor.main"] = "supervisor",
};
/// <summary>Bildressource zum Schlüssel, oder <c>null</c> (kein Symbol / unbekannter Schlüssel).</summary>
public static Image? Resolve(string? iconKey) =>
iconKey != null && Map.TryGetValue(iconKey, out var img) ? img : null;
/// <summary>
/// Setzt bei allen registrierten Views den Standard-Symbolschlüssel, sofern noch keiner gesetzt ist.
/// </summary>
public static void AssignDefaults(IModuleUiHost uiHost)
{
foreach (var view in uiHost.Views)
if (view.IconKey == null && DefaultKeyByViewId.TryGetValue(view.Id, out var key))
view.IconKey = key;
}
}
}