Das Suffix ".Avalonia" gab es nur, weil daneben ein WinForms-IBKRTrader.App
stand. Das ist seit L5 weg, also faellt auch das Suffix. Git erkennt alle
Dateien als Umbenennung; Assembly, Wurzel-Namensraum und die
avares://-Ressourcen-URI sind mitgezogen.
Nebeneffekt der Umbenennung: die global::Avalonia-Qualifizierungen entfallen.
Sie waren noetig, weil der Namensraum IBKRTrader.App.Avalonia das
Avalonia-Paket verdeckt hat - ein Ueberbleibsel genau der Namensgebung, die
jetzt weg ist.
Inhaltlich falsch gewordene Aussagen berichtigt - das waren die eigentlichen
Ueberbleibsel, nicht die Kommentare:
- .agents/rules/grundregeln.md schrieb weiterhin "C# .NET 10 WinForms",
RichTextBox-Logging, LauncherForm und PropertyGrid vor. Das ist die Regel,
nach der kuenftig gearbeitet wird - sie haette die Portierung Stueck fuer
Stueck rueckgaengig gemacht. Jetzt: Avalonia, keine Plattform-Suffixe, die
11er-Pinnung mit Begruendung, dazu die beiden Regeln, die uns in L1b am
meisten gekostet haben (UTC persistieren + AppTimeZone statt DateTime.Now;
jede Formatierung mit ausdruecklichem IFormatProvider).
- Core: LogEntry ("wird in RichTextBox geschrieben"), IWorker/WorkerEngine/
WorkerInfo ("DataGridView-Zeile"/"-Binding"), ModuleView ("die
WinForms-Shell castet auf Form").
- Doku: ARCHITECTURE (Modul-Ui-Ordner, "designbare Forms mit Initialize"),
KONZEPT-Modul-Accounting ("UI (WinForms, ein Fenster mit Tabs)").
BEWUSST STEHEN GEBLIEBEN sind die Kommentare, die WinForms nur als
Begruendung nennen - warum LoggingService ein Ereignis hat statt einer
RichTextBox, warum ModuleView Func<object> liefert, warum es benannte
Record-Zeilentypen gibt, warum die Einstellungsmaske aus Attributen entsteht.
Das ist die Herleitung des heutigen Entwurfs; ohne sie sieht spaeter jede
dieser Stellen nach Umstaendlichkeit ohne Grund aus.
KONZEPT-Linux-Portierung.md bekommt einen Statusvermerk: umgesetzt, die
Pfadangaben im Fundstellenverzeichnis beziehen sich auf den alten Aufbau.
Zwei Abweichungen von der Schaetzung sind dort festgehalten - der geringere
Aufwand dank der PolytraderSharp-Vorlage, und dass die dort empfohlene
InvariantGlobalization ein Fehler gewesen waere.
Verifiziert: Build 0 Fehler/0 Warnungen, 193 Tests gruen, Smoke-UI
konstruiert alle 7 Ansichten + Launcher + Dialog, Daemon-Prueflauf OK,
publish -r linux-x64 fuer beide Einstiegspunkte fehlerfrei.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
161 lines
6.0 KiB
C#
161 lines
6.0 KiB
C#
using System.Globalization;
|
||
using Avalonia;
|
||
using Avalonia.Controls;
|
||
using Avalonia.Layout;
|
||
using Avalonia.Markup.Xaml;
|
||
using IBKRTrader.App.Shell;
|
||
using IBKRTrader.App.ViewModels;
|
||
using IBKRTrader.Core.Modularity;
|
||
using IBKRTrader.Core.Settings;
|
||
using IBKRTrader.Core.Time;
|
||
|
||
namespace IBKRTrader.App.Views;
|
||
|
||
/// <summary>
|
||
/// Core-Ansicht: Einstellungen. Ersetzt das <c>PropertyGrid</c> der WinForms-Fassung durch eine
|
||
/// aus den Attributen erzeugte Maske (siehe <see cref="SettingsModelBuilder"/>).
|
||
///
|
||
/// <para>Geändert wird direkt auf dem <c>AppSettings</c>-Objekt; „Speichern" schreibt es nach
|
||
/// <c>settings.json</c>, „Verwerfen" lädt die Datei neu. Zahlen werden ausdrücklich gegen
|
||
/// <see cref="CultureInfo.InvariantCulture"/> gelesen – die Datei ist maschinenlesbar und darf
|
||
/// nicht von der Kultur des Rechners abhängen.</para>
|
||
/// </summary>
|
||
public partial class SettingsWindow : Window
|
||
{
|
||
private readonly SettingsService _settings;
|
||
|
||
public SettingsWindow(IModuleUiHost uiHost, SettingsService settings)
|
||
{
|
||
_settings = settings;
|
||
|
||
InitializeComponent();
|
||
WindowMenu.Wire(this.FindControl<Menu>("WindowMenuBar")!, uiHost, "core.settings");
|
||
|
||
this.FindControl<Button>("SaveButton")!.Click += (_, _) =>
|
||
{
|
||
try
|
||
{
|
||
_settings.Save();
|
||
SetStatus("Gespeichert. Zeitzonen-Änderungen greifen erst nach einem Neustart.");
|
||
}
|
||
catch (Exception ex) { SetStatus($"Speichern fehlgeschlagen: {ex.Message}"); }
|
||
};
|
||
|
||
this.FindControl<Button>("ReloadButton")!.Click += (_, _) =>
|
||
{
|
||
_settings.Load();
|
||
BuildForm();
|
||
SetStatus("Gespeicherte Werte neu geladen.");
|
||
};
|
||
|
||
BuildForm();
|
||
SetStatus("Bereit.");
|
||
}
|
||
|
||
private void InitializeComponent() => AvaloniaXamlLoader.Load(this);
|
||
|
||
private void BuildForm()
|
||
{
|
||
var panel = this.FindControl<StackPanel>("SectionPanel")!;
|
||
panel.Children.Clear();
|
||
|
||
foreach (var section in SettingsModelBuilder.Build(_settings.Settings))
|
||
{
|
||
var grid = new Grid
|
||
{
|
||
ColumnDefinitions = new ColumnDefinitions("240,*"),
|
||
Margin = new Thickness(4, 4, 4, 12)
|
||
};
|
||
|
||
for (var i = 0; i < section.Fields.Count; i++)
|
||
{
|
||
var field = section.Fields[i];
|
||
grid.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
|
||
|
||
var label = new TextBlock
|
||
{
|
||
Text = field.DisplayName,
|
||
Margin = new Thickness(0, 6, 10, 6),
|
||
VerticalAlignment = VerticalAlignment.Center
|
||
};
|
||
if (!string.IsNullOrWhiteSpace(field.Description))
|
||
ToolTip.SetTip(label, field.Description);
|
||
|
||
var editor = CreateEditor(field);
|
||
editor.Margin = new Thickness(0, 4, 0, 4);
|
||
if (!string.IsNullOrWhiteSpace(field.Description))
|
||
ToolTip.SetTip(editor, field.Description);
|
||
|
||
Grid.SetRow(label, i); Grid.SetColumn(label, 0);
|
||
Grid.SetRow(editor, i); Grid.SetColumn(editor, 1);
|
||
grid.Children.Add(label);
|
||
grid.Children.Add(editor);
|
||
}
|
||
|
||
panel.Children.Add(new Expander
|
||
{
|
||
Header = section.Title,
|
||
IsExpanded = true,
|
||
Content = grid,
|
||
Margin = new Thickness(0, 0, 0, 6),
|
||
HorizontalContentAlignment = HorizontalAlignment.Stretch
|
||
});
|
||
}
|
||
}
|
||
|
||
/// <summary>Wählt das Eingabeelement passend zum Typ des Feldes.</summary>
|
||
private static Control CreateEditor(SettingsField field)
|
||
{
|
||
if (field.ValueType == typeof(bool))
|
||
{
|
||
var check = new CheckBox { IsChecked = (bool?)field.Get() };
|
||
check.IsCheckedChanged += (_, _) => field.Set(check.IsChecked == true);
|
||
return check;
|
||
}
|
||
|
||
if (field.ValueType.IsEnum)
|
||
{
|
||
var combo = new ComboBox
|
||
{
|
||
ItemsSource = Enum.GetValues(field.ValueType),
|
||
SelectedItem = field.Get(),
|
||
HorizontalAlignment = HorizontalAlignment.Left,
|
||
MinWidth = 200
|
||
};
|
||
combo.SelectionChanged += (_, _) => { if (combo.SelectedItem is not null) field.Set(combo.SelectedItem); };
|
||
return combo;
|
||
}
|
||
|
||
if (field.ValueType == typeof(int) || field.ValueType == typeof(long) ||
|
||
field.ValueType == typeof(double) || field.ValueType == typeof(decimal))
|
||
{
|
||
var numeric = new NumericUpDown
|
||
{
|
||
Value = ToDecimal(field.Get()),
|
||
Increment = field.ValueType == typeof(double) || field.ValueType == typeof(decimal) ? 0.5m : 1m,
|
||
FormatString = field.ValueType == typeof(double) || field.ValueType == typeof(decimal) ? "0.###" : "0",
|
||
HorizontalAlignment = HorizontalAlignment.Left,
|
||
MinWidth = 200
|
||
};
|
||
numeric.ValueChanged += (_, _) =>
|
||
{
|
||
if (numeric.Value is not { } v) return;
|
||
field.Set(Convert.ChangeType(v, field.ValueType, CultureInfo.InvariantCulture));
|
||
};
|
||
return numeric;
|
||
}
|
||
|
||
var box = new TextBox { Text = field.Get()?.ToString() ?? "" };
|
||
// Kennwortfelder (DB-Passwort, Flex-Token) nicht im Klartext anzeigen.
|
||
if (field.IsPassword) box.PasswordChar = '•';
|
||
box.TextChanged += (_, _) => field.Set(box.Text ?? "");
|
||
return box;
|
||
}
|
||
|
||
private static decimal ToDecimal(object? value) =>
|
||
value is null ? 0m : Convert.ToDecimal(value, CultureInfo.InvariantCulture);
|
||
|
||
private void SetStatus(string text) =>
|
||
this.FindControl<TextBlock>("StatusText")!.Text = $"{text} | {AppTimeZone.Now:HH:mm:ss}";
|
||
}
|