Merge pull request #91 from irihitech/prism

Add Prism extension library to support Ursa dialog in Prism dialog system.
This commit is contained in:
Dong Bin
2024-02-06 22:12:46 +08:00
committed by GitHub
17 changed files with 313 additions and 0 deletions

View File

@@ -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<DialogResult> ShowModal(string viewName, object? vm, Window? owner = null,
DialogOptions? options = null);
public Task<TResult?> ShowCustomModal<TResult>(string viewName, object? vm, Window? owner = null,
DialogOptions? options = null);
}

View File

@@ -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<DialogResult> ShowModal(string viewName, object? vm, string? hostId = null,
OverlayDialogOptions? options = null);
public Task<TResult?> ShowCustomModal<TResult>(string viewName, object? vm, string? hostId = null,
OverlayDialogOptions? options = null);
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Ursa\Ursa.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Prism.Core" Version="8.1.97" />
</ItemGroup>
</Project>

View File

@@ -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<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
Dialog.ShowCustom(v, vm, owner, options);
}
public Task<DialogResult> ShowModal(string viewName, object? vm, Window? owner = null, DialogOptions? options = null)
{
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
return Dialog.ShowModal(v, vm, owner, options);
}
public Task<TResult?> ShowCustomModal<TResult>(string viewName, object? vm, Window? owner = null, DialogOptions? options = null)
{
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
return Dialog.ShowCustomModal<TResult>(v, vm, owner, options);
}
}

View File

@@ -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<IUrsaDialogService, UrsaDialogService>();
containerRegistry.RegisterSingleton<IUrsaOverlayDialogService, UrsaOverlayDialogService>();
}
public static void RegisterUrsaDialogView<T>(this IContainerRegistry containerRegistry, string name) where T : Control
{
containerRegistry.Register<Control, T>(UrsaDialogViewPrefix+name);
}
}

View File

@@ -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<Control>(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<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
OverlayDialog.ShowCustom(v, vm, hostId, options);
}
public Task<DialogResult> ShowModal(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null)
{
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
return OverlayDialog.ShowModal(v, vm, hostId, options);
}
public Task<TResult?> ShowCustomModal<TResult>(string viewName, object? vm, string? hostId = null, OverlayDialogOptions? options = null)
{
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
return OverlayDialog.ShowCustomModal<TResult>(v, vm, hostId, options);
}
}