From 430dccc9584fb88e5b50147e7c43fb28c2366ad5 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 25 Jan 2024 00:50:27 +0800 Subject: [PATCH] feat: ultimate refactoring to separate default dialog and custom dialog. --- demo/Ursa.Demo/Dialogs/DialogWithAction.axaml | 4 +- .../Dialogs/DialogWithActionViewModel.cs | 9 +- demo/Ursa.Demo/Dialogs/PlainDialog.axaml | 1 - .../ViewModels/DialogDemoViewModel.cs | 17 +- src/Ursa.Themes.Semi/Controls/Dialog.axaml | 155 ++++++++++++++-- .../Controls/MessageBoxWindow.axaml | 1 - src/Ursa/Common/EventHelper.cs | 23 +++ .../Controls/Dialog/DefaultDialogControl.cs | 133 ++++++++++++++ .../Controls/Dialog/DefaultDialogWindow.cs | 125 +++++++++++++ src/Ursa/Controls/Dialog/Dialog.cs | 165 +++++++++++++----- src/Ursa/Controls/Dialog/DialogControl.cs | 164 +++-------------- src/Ursa/Controls/Dialog/DialogIcon.cs | 11 ++ src/Ursa/Controls/Dialog/DialogOptions.cs | 11 -- src/Ursa/Controls/Dialog/DialogWindow.cs | 16 +- src/Ursa/Controls/Dialog/IDialogContext.cs | 2 +- src/Ursa/Controls/Dialog/OverlayDialogHost.cs | 23 +-- 16 files changed, 605 insertions(+), 255 deletions(-) create mode 100644 src/Ursa/Common/EventHelper.cs create mode 100644 src/Ursa/Controls/Dialog/DefaultDialogControl.cs create mode 100644 src/Ursa/Controls/Dialog/DefaultDialogWindow.cs create mode 100644 src/Ursa/Controls/Dialog/DialogIcon.cs delete mode 100644 src/Ursa/Controls/Dialog/DialogOptions.cs diff --git a/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml b/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml index b3132df..104e746 100644 --- a/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml +++ b/demo/Ursa.Demo/Dialogs/DialogWithAction.axaml @@ -7,8 +7,8 @@ x:CompileBindings="True" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Ursa.Demo.Dialogs.DialogWithAction"> - - + + diff --git a/demo/Ursa.Demo/Dialogs/DialogWithActionViewModel.cs b/demo/Ursa.Demo/Dialogs/DialogWithActionViewModel.cs index 37c0cdc..5f43a7f 100644 --- a/demo/Ursa.Demo/Dialogs/DialogWithActionViewModel.cs +++ b/demo/Ursa.Demo/Dialogs/DialogWithActionViewModel.cs @@ -11,7 +11,12 @@ public partial class DialogWithActionViewModel: ObservableObject, IDialogContext { [ObservableProperty] private string _title; [ObservableProperty] private DateTime _date; - public object? DefaultCloseResult { get; set; } = true; + + public void Close() + { + Closed?.Invoke(this, false); + } + public event EventHandler? Closed; public ICommand OKCommand { get; set; } @@ -40,6 +45,6 @@ public partial class DialogWithActionViewModel: ObservableObject, IDialogContext private async Task ShowDialog() { - await OverlayDialog.ShowModalAsync(new DialogWithActionViewModel()); + await OverlayDialog.ShowCustomModalAsync(new DialogWithActionViewModel()); } } \ No newline at end of file diff --git a/demo/Ursa.Demo/Dialogs/PlainDialog.axaml b/demo/Ursa.Demo/Dialogs/PlainDialog.axaml index 3888975..f5688f2 100644 --- a/demo/Ursa.Demo/Dialogs/PlainDialog.axaml +++ b/demo/Ursa.Demo/Dialogs/PlainDialog.axaml @@ -5,7 +5,6 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Ursa.Demo.Dialogs.PlainDialog"> - diff --git a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs index 558cd69..55dc3ae 100644 --- a/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/DialogDemoViewModel.cs @@ -15,13 +15,10 @@ public class DialogDemoViewModel: ObservableObject public ICommand ShowLocalOverlayModalDialogCommand { get; } public ICommand ShowGlobalOverlayModalDialogCommand { get; } public ICommand ShowGlobalModalDialogCommand { get; } - public ICommand ShowGlobalOverlayDialogCommand { get; } - public ICommand ShowPlainGlobalOverlayDialogCommand { get; } private object? _result; - public object? Result { get => _result; @@ -54,31 +51,27 @@ public class DialogDemoViewModel: ObservableObject private async Task ShowGlobalModalDialog() { - var result = await Dialog.ShowModalAsync(DialogViewModel); + var result = await Dialog.ShowCustomModalAsync(DialogViewModel); Result = result; } private async Task ShowGlobalOverlayModalDialog() { - Result = await OverlayDialog.ShowModalAsync(DialogViewModel); + Result = await OverlayDialog.ShowCustomModalAsync(DialogViewModel); } private async Task ShowLocalOverlayModalDialog() { var vm = new DialogWithActionViewModel(); - var result = await OverlayDialog.ShowModalAsync( - DialogViewModel, new DialogOptions() { ExtendToClientArea = true}, "LocalHost"); + var result = await OverlayDialog.ShowCustomModalAsync( + DialogViewModel, "LocalHost"); Result = result; } public async Task ShowPlainGlobalOverlayDialog() { - var result = await OverlayDialog.ShowModalAsync( + var result = await OverlayDialog.ShowCustomModalAsync( new PlainDialogViewModel(), - new DialogOptions() - { - DefaultButtons = DialogButton.OKCancel, - }, "LocalHost"); } } \ No newline at end of file diff --git a/src/Ursa.Themes.Semi/Controls/Dialog.axaml b/src/Ursa.Themes.Semi/Controls/Dialog.axaml index c9d55c4..0d0b285 100644 --- a/src/Ursa.Themes.Semi/Controls/Dialog.axaml +++ b/src/Ursa.Themes.Semi/Controls/Dialog.axaml @@ -13,9 +13,96 @@ Padding="0" HorizontalAlignment="Center" VerticalAlignment="Center" + Classes="Shadow" + CornerRadius="12" IsHitTestVisible="True" Theme="{DynamicResource CardBorder}"> - + + + + +