- Editor gefixt :) Sauberes Syntax hervorheben nun Fehler war, avalonia etc zu updaten! regelmäßig updates machen also xD

- UI Überarbeitet im ServerDashboard, bepinex status wird jetzt kleiner wenn nix weiter angezeigt wird und modliste größer. Löschen und update buttons eingefügt in modsliste

TODO: Update und Delete function Mods, Ladeanimation für Modupload und so :P
- Lschen und Update buttons in liste sollen ganz rechts immer sein!
This commit is contained in:
tbS
2025-08-28 23:13:34 +02:00
parent cf6bd3765f
commit 32cbe40921
8 changed files with 215 additions and 122 deletions

View File

@@ -20,78 +20,93 @@ public partial class App : Application
AvaloniaXamlLoader.Load(this);
}
static HighlightingBrush HB(string key)
{
var obj = Application.Current!.FindResource(key);
if (obj is ISolidColorBrush scb) return new SimpleHighlightingBrush(scb.Color);
return new SimpleHighlightingBrush(Colors.LightGray);
}
private void RegisterCfgHighlighting()
{
static HighlightingBrush HB(string key)
{
var obj = Application.Current!.FindResource(key);
if (obj is ISolidColorBrush scb)
return new SimpleHighlightingBrush(scb.Color); // <-- Color, nicht IBrush
throw new InvalidOperationException($"Resource '{key}' must be a SolidColorBrush.");
}
var section = new HighlightingColor { Foreground = HB("Cfg.SectionBrush"), FontWeight = FontWeight.Bold };
var comment = new HighlightingColor { Foreground = HB("Cfg.CommentBrush"), FontStyle = FontStyle.Italic };
var key = new HighlightingColor { Foreground = HB("Cfg.KeyBrush") };
var keyCol = new HighlightingColor { Foreground = HB("Cfg.KeyBrush") };
var equal = new HighlightingColor { Foreground = HB("Cfg.EqualBrush") };
var value = new HighlightingColor { Foreground = HB("Cfg.ValueBrush") };
var number = new HighlightingColor { Foreground = HB("Cfg.NumberBrush") };
var rules = new HighlightingRuleSet();
// 1) Kommentare: ^\s*#.*
// 0) Volle Kommentarzeilen
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"^\s*#.*", RegexOptions.Compiled | RegexOptions.Multiline),
Regex = new Regex(@"^[ \t]*[;#].*$", RegexOptions.Multiline),
Color = comment
});
// 2) Sektionen: [Name]
// 1) Sektionen: [Section]
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"^\s*\[[^\]\r\n]+\]\s*$", RegexOptions.Compiled | RegexOptions.Multiline),
Regex = new Regex(@"^\s*\[[^\]\r\n]+\]\s*$", RegexOptions.Multiline),
Color = section
});
// 3a) Schl<68>ssel (von Zeilenbeginn bis vor "=")
rules.Spans.Add(new HighlightingSpan
{
StartExpression = new Regex(@"^\s*", RegexOptions.Compiled | RegexOptions.Multiline),
EndExpression = new Regex(@"=", RegexOptions.Compiled),
SpanColor = key
});
// 3b) Gleichheitszeichen
// 2) Key (nur der Text vor '=' auf derselben Zeile)
// - ignoriert f<>hrende Spaces (Lookbehind)
// - endet direkt vor '=' (Lookahead)
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"=", RegexOptions.Compiled),
Regex = new Regex(@"(?<=^[ \t]*)[^=\r\n\[\];#][^=\r\n]*?(?=\s*=)", RegexOptions.Multiline),
Color = keyCol
});
// 3) '=' rot
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"=", RegexOptions.None),
Color = equal
});
// 3c) Werte (von "=" bis Zeilenende; Kommentar nicht einschlie<69>en)
rules.Spans.Add(new HighlightingSpan
{
StartExpression = new Regex(@"=(?!.*#)", RegexOptions.Compiled), // bis Zeilenende ohne #
EndExpression = new Regex(@"$", RegexOptions.Compiled | RegexOptions.Multiline),
SpanColor = value
});
// 3d) Zahlen im Wert hervorheben
// 4a) Zahlen im Value
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"\b-?\d+(\.\d+)?\b", RegexOptions.Compiled),
Regex = new Regex(@"(?<==\s*)(-?\d+(\.\d+)?)", RegexOptions.Multiline),
Color = number
});
var def = new CustomHighlightingDefinition("CfgDark", rules);
HighlightingManager.Instance.RegisterHighlighting("CfgDark", new[] { ".cfg", ".cfg.txt", ".properties" }, def);
// 4b) Bool-Werte im Value
var boolVal = new HighlightingColor { Foreground = HB("Cfg.BoolBrush") };
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"(?<==\s*)(On|Off|True|False)\b", RegexOptions.IgnoreCase | RegexOptions.Multiline),
Color = boolVal
});
IBrush? TryRes(string key) => (IBrush?)Current?.FindResource(key);
// 4c) Allgemeine Werte (kein Zahl, kein Bool)
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"(?<==\s*)(?!On\b|Off\b|True\b|False\b)([A-Za-z_][^\r\n#;]*)",
RegexOptions.IgnoreCase | RegexOptions.Multiline),
Color = value
});
// 6) Inline-Kommentare rechts vom Wert
rules.Rules.Add(new HighlightingRule
{
Regex = new Regex(@"[ \t][;#].*$", RegexOptions.Multiline),
Color = comment
});
var def = new InlineHighlightingDefinition("CfgDark", rules);
HighlightingManager.Instance.RegisterHighlighting("CfgDark", new[] { ".cfg", ".properties" }, def);
}
// kleine Helper-Definition
sealed class CustomHighlightingDefinition : IHighlightingDefinition
sealed class InlineHighlightingDefinition : IHighlightingDefinition
{
public CustomHighlightingDefinition(string name, HighlightingRuleSet rules) { Name = name; MainRuleSet = rules; }
public InlineHighlightingDefinition(string name, HighlightingRuleSet rules)
{ Name = name; MainRuleSet = rules; }
public string Name { get; }
public HighlightingRuleSet MainRuleSet { get; }
public IEnumerable<HighlightingColor> NamedHighlightingColors => Array.Empty<HighlightingColor>();
@@ -99,7 +114,6 @@ public partial class App : Application
public HighlightingRuleSet? GetNamedRuleSet(string name) => null;
public HighlightingColor? GetNamedColor(string name) => null;
}
public override void OnFrameworkInitializationCompleted()
{