From 8b484e6b21ebeadac03ef886321558a22b2db617 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Fri, 22 Nov 2024 13:02:26 +0800 Subject: [PATCH] feat: use common separator. --- src/Ursa/Common/Constants.cs | 6 ++++++ src/Ursa/Controls/Dialog/Dialog.cs | 5 +++-- src/Ursa/Controls/Dialog/OverlayDialog.cs | 5 +++-- src/Ursa/Controls/Drawer/Drawer.cs | 5 +++-- src/Ursa/Controls/MessageBox/MessageBox.cs | 7 ++++--- 5 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 src/Ursa/Common/Constants.cs diff --git a/src/Ursa/Common/Constants.cs b/src/Ursa/Common/Constants.cs new file mode 100644 index 00000000..b24eee86 --- /dev/null +++ b/src/Ursa/Common/Constants.cs @@ -0,0 +1,6 @@ +namespace Ursa.Common; + +internal static class Constants +{ + public static char[] SpaceSeparator = [' ']; +} \ No newline at end of file diff --git a/src/Ursa/Controls/Dialog/Dialog.cs b/src/Ursa/Controls/Dialog/Dialog.cs index 459ff818..73ddc053 100644 --- a/src/Ursa/Controls/Dialog/Dialog.cs +++ b/src/Ursa/Controls/Dialog/Dialog.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; +using Ursa.Common; namespace Ursa.Controls; @@ -216,7 +217,7 @@ private static void ConfigureDialogWindow(DialogWindow window, DialogOptions? op } if (!string.IsNullOrWhiteSpace(options.StyleClass)) { - var styles = options.StyleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = options.StyleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); window.Classes.AddRange(styles); } } @@ -247,7 +248,7 @@ private static void ConfigureDefaultDialogWindow(DefaultDialogWindow window, Dia } if (!string.IsNullOrWhiteSpace(options.StyleClass)) { - var styles = options.StyleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = options.StyleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); window.Classes.AddRange(styles); } } diff --git a/src/Ursa/Controls/Dialog/OverlayDialog.cs b/src/Ursa/Controls/Dialog/OverlayDialog.cs index fe67222c..bc6e01a5 100644 --- a/src/Ursa/Controls/Dialog/OverlayDialog.cs +++ b/src/Ursa/Controls/Dialog/OverlayDialog.cs @@ -2,6 +2,7 @@ using Avalonia.Controls; using Avalonia.Input; using Avalonia.Layout; +using Ursa.Common; namespace Ursa.Controls; @@ -207,7 +208,7 @@ private static void ConfigureCustomDialogControl(CustomDialogControl control, Ov control.CanResize = options.CanResize; if (!string.IsNullOrWhiteSpace(options.StyleClass)) { - var styles = options.StyleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = options.StyleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); control.Classes.AddRange(styles); } DialogControlBase.SetCanDragMove(control, options.CanDragMove); @@ -238,7 +239,7 @@ private static void ConfigureDefaultDialogControl(DefaultDialogControl control, control.CanResize = options.CanResize; if (!string.IsNullOrWhiteSpace(options.StyleClass)) { - var styles = options.StyleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = options.StyleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); control.Classes.AddRange(styles); } DialogControlBase.SetCanDragMove(control, options.CanDragMove); diff --git a/src/Ursa/Controls/Drawer/Drawer.cs b/src/Ursa/Controls/Drawer/Drawer.cs index 048a7aa8..f2e0b858 100644 --- a/src/Ursa/Controls/Drawer/Drawer.cs +++ b/src/Ursa/Controls/Drawer/Drawer.cs @@ -3,6 +3,7 @@ using Avalonia.Input; using Ursa.Common; using Ursa.Controls.Options; +// ReSharper disable RedundantExplicitArrayCreation namespace Ursa.Controls; @@ -220,7 +221,7 @@ private static void ConfigureCustomDrawer(CustomDrawerControl drawer, DrawerOpti if (!string.IsNullOrWhiteSpace(options.StyleClass)) { - var styles = options.StyleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = options.StyleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); drawer.Classes.AddRange(styles); } } @@ -247,7 +248,7 @@ private static void ConfigureDefaultDrawer(DefaultDrawerControl drawer, DrawerOp } if (!string.IsNullOrWhiteSpace(options.StyleClass)) { - var styles = options.StyleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = options.StyleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); drawer.Classes.AddRange(styles); } } diff --git a/src/Ursa/Controls/MessageBox/MessageBox.cs b/src/Ursa/Controls/MessageBox/MessageBox.cs index d090b597..e998bb46 100644 --- a/src/Ursa/Controls/MessageBox/MessageBox.cs +++ b/src/Ursa/Controls/MessageBox/MessageBox.cs @@ -2,6 +2,7 @@ using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Input; +using Ursa.Common; namespace Ursa.Controls; @@ -22,7 +23,7 @@ public static async Task ShowAsync( }; if (!string.IsNullOrWhiteSpace(styleClass)) { - var styles = styleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = styleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); messageWindow.Classes.AddRange(styles); } var lifetime = Application.Current?.ApplicationLifetime; @@ -54,7 +55,7 @@ public static async Task ShowAsync( }; if (!string.IsNullOrWhiteSpace(styleClass)) { - var styles = styleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = styleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); messageWindow.Classes.AddRange(styles!); } var result = await messageWindow.ShowDialog(owner); @@ -82,7 +83,7 @@ public static async Task ShowOverlayAsync( }; if (!string.IsNullOrWhiteSpace(styleClass)) { - var styles = styleClass!.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); + var styles = styleClass!.Split(Constants.SpaceSeparator, StringSplitOptions.RemoveEmptyEntries); messageControl.Classes.AddRange(styles!); } host.AddModalDialog(messageControl);