diff --git a/Ursa.sln b/Ursa.sln index 9b2953a..d46008b 100644 --- a/Ursa.sln +++ b/Ursa.sln @@ -16,6 +16,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ursa.Demo.iOS", "demo\Ursa. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ursa.Demo.Browser", "demo\Ursa.Demo.Browser\Ursa.Demo.Browser.csproj", "{D1942476-8473-4608-BB9F-5AC01083BBDA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ursa.PrismExtension", "src\Ursa.PrismExtension\Ursa.PrismExtension.csproj", "{2E934F60-F5DF-4856-B05A-B949C7F9D948}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ursa.PrismDialogDemo", "demo\Ursa.PrismDialogDemo\Ursa.PrismDialogDemo.csproj", "{F99B3D07-4560-4B05-892C-0FF2757FEF2E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -50,6 +54,14 @@ Global {D1942476-8473-4608-BB9F-5AC01083BBDA}.Debug|Any CPU.Build.0 = Debug|Any CPU {D1942476-8473-4608-BB9F-5AC01083BBDA}.Release|Any CPU.ActiveCfg = Release|Any CPU {D1942476-8473-4608-BB9F-5AC01083BBDA}.Release|Any CPU.Build.0 = Release|Any CPU + {2E934F60-F5DF-4856-B05A-B949C7F9D948}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E934F60-F5DF-4856-B05A-B949C7F9D948}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E934F60-F5DF-4856-B05A-B949C7F9D948}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E934F60-F5DF-4856-B05A-B949C7F9D948}.Release|Any CPU.Build.0 = Release|Any CPU + {F99B3D07-4560-4B05-892C-0FF2757FEF2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F99B3D07-4560-4B05-892C-0FF2757FEF2E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F99B3D07-4560-4B05-892C-0FF2757FEF2E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F99B3D07-4560-4B05-892C-0FF2757FEF2E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {407A91FD-A88B-459B-8DCE-8C6AA98279FE} = {A41BAF0D-DA61-4A63-889A-084BAD36FD66} @@ -57,5 +69,6 @@ Global {B6BAB821-A9FE-44F3-B9CD-06E27FDB63F6} = {A41BAF0D-DA61-4A63-889A-084BAD36FD66} {94C2BBD9-8B57-4AE9-AAFD-7D4335B15A8E} = {A41BAF0D-DA61-4A63-889A-084BAD36FD66} {D1942476-8473-4608-BB9F-5AC01083BBDA} = {A41BAF0D-DA61-4A63-889A-084BAD36FD66} + {F99B3D07-4560-4B05-892C-0FF2757FEF2E} = {A41BAF0D-DA61-4A63-889A-084BAD36FD66} EndGlobalSection EndGlobal diff --git a/demo/Ursa.PrismDialogDemo/App.axaml b/demo/Ursa.PrismDialogDemo/App.axaml new file mode 100644 index 0000000..60f2b2d --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/App.axaml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/demo/Ursa.PrismDialogDemo/App.axaml.cs b/demo/Ursa.PrismDialogDemo/App.axaml.cs new file mode 100644 index 0000000..9e71d4c --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/App.axaml.cs @@ -0,0 +1,29 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using Prism.DryIoc; +using Prism.Ioc; +using Ursa.PrismExtension; + +namespace Ursa.PrismDialogDemo; + +public partial class App : PrismApplication +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + base.Initialize(); + } + + protected override void RegisterTypes(IContainerRegistry containerRegistry) + { + containerRegistry.Register(); + containerRegistry.RegisterUrsaDialogService(); + containerRegistry.RegisterUrsaDialogView("Default"); + } + + protected override AvaloniaObject CreateShell() + { + return Container.Resolve(); + } +} \ No newline at end of file diff --git a/demo/Ursa.PrismDialogDemo/DefaultDialog.axaml b/demo/Ursa.PrismDialogDemo/DefaultDialog.axaml new file mode 100644 index 0000000..4353519 --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/DefaultDialog.axaml @@ -0,0 +1,8 @@ + + Welcome to Ursa Avalonia Dialog! + diff --git a/demo/Ursa.PrismDialogDemo/DefaultDialog.axaml.cs b/demo/Ursa.PrismDialogDemo/DefaultDialog.axaml.cs new file mode 100644 index 0000000..8a778b4 --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/DefaultDialog.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Ursa.PrismDialogDemo; + +public partial class DefaultDialog : UserControl +{ + public DefaultDialog() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/demo/Ursa.PrismDialogDemo/MainWindow.axaml b/demo/Ursa.PrismDialogDemo/MainWindow.axaml new file mode 100644 index 0000000..6acc99a --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/MainWindow.axaml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/demo/Ursa.PrismDialogDemo/MainWindow.axaml.cs b/demo/Ursa.PrismDialogDemo/MainWindow.axaml.cs new file mode 100644 index 0000000..ad95fd4 --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/MainWindow.axaml.cs @@ -0,0 +1,21 @@ +using Avalonia.Controls; +using Avalonia.Interactivity; +using DryIoc; +using Ursa.PrismExtension; + +namespace Ursa.PrismDialogDemo; + +public partial class MainWindow : Window +{ + private IUrsaOverlayDialogService _ursa; + public MainWindow(IUrsaOverlayDialogService ursa) + { + InitializeComponent(); + _ursa = ursa; + } + + private void Button_OnClick(object? sender, RoutedEventArgs e) + { + _ursa.ShowModal("Default", null, null, null); + } +} \ No newline at end of file diff --git a/demo/Ursa.PrismDialogDemo/Program.cs b/demo/Ursa.PrismDialogDemo/Program.cs new file mode 100644 index 0000000..7d86295 --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace Ursa.PrismDialogDemo; + +class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} \ No newline at end of file diff --git a/demo/Ursa.PrismDialogDemo/Ursa.PrismDialogDemo.csproj b/demo/Ursa.PrismDialogDemo/Ursa.PrismDialogDemo.csproj new file mode 100644 index 0000000..2d2c855 --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/Ursa.PrismDialogDemo.csproj @@ -0,0 +1,28 @@ + + + WinExe + net8.0 + enable + true + app.manifest + true + + + + + + + + + + + + + + + + + + + + diff --git a/demo/Ursa.PrismDialogDemo/app.manifest b/demo/Ursa.PrismDialogDemo/app.manifest new file mode 100644 index 0000000..6fe501d --- /dev/null +++ b/demo/Ursa.PrismDialogDemo/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/global.json b/global.json new file mode 100644 index 0000000..b5b37b6 --- /dev/null +++ b/global.json @@ -0,0 +1,7 @@ +{ + "sdk": { + "version": "8.0.0", + "rollForward": "latestMajor", + "allowPrerelease": false + } +} \ No newline at end of file diff --git a/src/Ursa.PrismExtension/IUrsaDialogService.cs b/src/Ursa.PrismExtension/IUrsaDialogService.cs new file mode 100644 index 0000000..26a3844 --- /dev/null +++ b/src/Ursa.PrismExtension/IUrsaDialogService.cs @@ -0,0 +1,15 @@ +using Avalonia.Controls; +using Ursa.Controls; + +namespace Ursa.PrismExtension; + +public interface IUrsaDialogService +{ + public void ShowCustom(string viewName, object? vm, Window? owner = null, DialogOptions? options = null); + + public Task ShowModal(string viewName, object? vm, Window? owner = null, + DialogOptions? options = null); + + public Task ShowCustomModal(string viewName, object? vm, Window? owner = null, + DialogOptions? options = null); +} \ No newline at end of file diff --git a/src/Ursa.PrismExtension/IUrsaOverlayDialogService.cs b/src/Ursa.PrismExtension/IUrsaOverlayDialogService.cs new file mode 100644 index 0000000..fd282e4 --- /dev/null +++ b/src/Ursa.PrismExtension/IUrsaOverlayDialogService.cs @@ -0,0 +1,17 @@ +using Avalonia.Controls; +using Ursa.Controls; + +namespace Ursa.PrismExtension; + +public interface IUrsaOverlayDialogService +{ + public void Show(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null); + + public void ShowCustom(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null); + + public Task ShowModal(string viewName, object? vm, string? hostId = null, + OverlayDialogOptions? options = null); + + public Task ShowCustomModal(string viewName, object? vm, string? hostId = null, + OverlayDialogOptions? options = null); +} \ No newline at end of file diff --git a/src/Ursa.PrismExtension/Ursa.PrismExtension.csproj b/src/Ursa.PrismExtension/Ursa.PrismExtension.csproj new file mode 100644 index 0000000..e7e7976 --- /dev/null +++ b/src/Ursa.PrismExtension/Ursa.PrismExtension.csproj @@ -0,0 +1,18 @@ + + + + netstandard2.0 + enable + enable + latest + + + + + + + + + + + diff --git a/src/Ursa.PrismExtension/UrsaDialogService.cs b/src/Ursa.PrismExtension/UrsaDialogService.cs new file mode 100644 index 0000000..41a8c9d --- /dev/null +++ b/src/Ursa.PrismExtension/UrsaDialogService.cs @@ -0,0 +1,26 @@ +using Avalonia.Controls; +using Prism.Ioc; +using Ursa.Controls; + +namespace Ursa.PrismExtension; + +public class UrsaDialogService(IContainerExtension container) : IUrsaDialogService +{ + public void ShowCustom(string viewName, object? vm, Window? owner = null, DialogOptions? options = null) + { + var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName); + Dialog.ShowCustom(v, vm, owner, options); + } + + public Task ShowModal(string viewName, object? vm, Window? owner = null, DialogOptions? options = null) + { + var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName); + return Dialog.ShowModal(v, vm, owner, options); + } + + public Task ShowCustomModal(string viewName, object? vm, Window? owner = null, DialogOptions? options = null) + { + var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName); + return Dialog.ShowCustomModal(v, vm, owner, options); + } +} \ No newline at end of file diff --git a/src/Ursa.PrismExtension/UrsaDialogServiceExtension.cs b/src/Ursa.PrismExtension/UrsaDialogServiceExtension.cs new file mode 100644 index 0000000..7e57ffb --- /dev/null +++ b/src/Ursa.PrismExtension/UrsaDialogServiceExtension.cs @@ -0,0 +1,20 @@ +using Avalonia.Controls; +using Prism.Ioc; + +namespace Ursa.PrismExtension; + +public static class UrsaDialogServiceExtension +{ + internal const string UrsaDialogViewPrefix = "URSA_DIALOG_VIEW_"; + + public static void RegisterUrsaDialogService(this IContainerRegistry containerRegistry) + { + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + } + + public static void RegisterUrsaDialogView(this IContainerRegistry containerRegistry, string name) where T : Control + { + containerRegistry.Register(UrsaDialogViewPrefix+name); + } +} \ No newline at end of file diff --git a/src/Ursa.PrismExtension/UrsaOverlayDialogService.cs b/src/Ursa.PrismExtension/UrsaOverlayDialogService.cs new file mode 100644 index 0000000..25c6c0c --- /dev/null +++ b/src/Ursa.PrismExtension/UrsaOverlayDialogService.cs @@ -0,0 +1,32 @@ +using Avalonia.Controls; +using Prism.Ioc; +using Ursa.Controls; + +namespace Ursa.PrismExtension; + +public class UrsaOverlayDialogService(IContainerExtension container): IUrsaOverlayDialogService +{ + public void Show(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null) + { + var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName); + OverlayDialog.Show(v, vm, hostId, options); + } + + public void ShowCustom(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null) + { + var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName); + OverlayDialog.ShowCustom(v, vm, hostId, options); + } + + public Task ShowModal(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null) + { + var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName); + return OverlayDialog.ShowModal(v, vm, hostId, options); + } + + public Task ShowCustomModal(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null) + { + var v = container.Resolve(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName); + return OverlayDialog.ShowCustomModal(v, vm, hostId, options); + } +} \ No newline at end of file