avalonia structure refactoring
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using VisionBuilder.UI.Common.ViewModel;
|
||||
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;
|
||||
using VisionBuilder.UI.Avalonia.Views;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
namespace VisionBuilder.UI.Avalonia.Services;
|
||||
|
||||
public class AvaloniaImagePreviewService : IImagePreviewService
|
||||
{
|
||||
public async Task ShowImagePreviewAsync(ErrorPreviewVM errorPreviewVm)
|
||||
{
|
||||
var dialog = new ImagePreviewDialog(errorPreviewVm);
|
||||
var parent = GetMainWindow();
|
||||
if (parent != null)
|
||||
await dialog.ShowDialog(parent);
|
||||
}
|
||||
|
||||
private static Window? GetMainWindow()
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
return desktop.MainWindow;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
17
VisionBuilder.UI.Avalonia/Services/AvaloniaLoadingService.cs
Normal file
17
VisionBuilder.UI.Avalonia/Services/AvaloniaLoadingService.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Serilog;
|
||||
using VisionBuilder.UI.Common.Processing;
|
||||
|
||||
namespace VisionBuilder.UI.Avalonia.Services;
|
||||
|
||||
public class AvaloniaLoadingService : ILoadingService
|
||||
{
|
||||
public void StartLoading(string title)
|
||||
{
|
||||
Log.Information("Loading: {Title}", title);
|
||||
}
|
||||
|
||||
public void StopLoading(string title)
|
||||
{
|
||||
Log.Information("Loaded: {Title}", title);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using VisionBuilder.UI.Common.Services;
|
||||
using VisionBuilder.UI.Avalonia.Views;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
namespace VisionBuilder.UI.Avalonia.Services;
|
||||
|
||||
public class AvaloniaPasswordInputService : IPasswordInputService
|
||||
{
|
||||
public async Task<string?> GetPasswordAsync()
|
||||
{
|
||||
var dialog = new PasswordDialog();
|
||||
var parent = GetMainWindow();
|
||||
if (parent != null)
|
||||
return await dialog.ShowDialog<string?>(parent);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Window? GetMainWindow()
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
return desktop.MainWindow;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using VisionBuilder.UI.Common.ViewModel;
|
||||
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;
|
||||
using VisionBuilder.UI.Avalonia.Views;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
|
||||
namespace VisionBuilder.UI.Avalonia.Services;
|
||||
|
||||
public class AvaloniaRecipeSelectionDialogService : IRecipeSelectionDialogService
|
||||
{
|
||||
private readonly IRecipeCreationTool _recipeCreationTool;
|
||||
|
||||
public AvaloniaRecipeSelectionDialogService(IRecipeCreationTool recipeCreationTool)
|
||||
{
|
||||
_recipeCreationTool = recipeCreationTool;
|
||||
}
|
||||
|
||||
public async Task<bool> SelectRecipeAsync(RecipeSelectionVM recipeSelectionVm)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
var dialog = new RecipeSelectionDialog(recipeSelectionVm, _recipeCreationTool, tcs);
|
||||
var parent = GetMainWindow();
|
||||
if (parent != null)
|
||||
{
|
||||
await dialog.ShowDialog(parent);
|
||||
return tcs.Task.IsCompleted && tcs.Task.Result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Window? GetMainWindow()
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
return desktop.MainWindow;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;
|
||||
|
||||
namespace VisionBuilder.UI.Avalonia.Services;
|
||||
|
||||
public class AvaloniaSettingsService : ISettingsService
|
||||
{
|
||||
public Task ShowSettingsDialogAsync()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
13
VisionBuilder.UI.Avalonia/Services/ImageConverter.cs
Normal file
13
VisionBuilder.UI.Avalonia/Services/ImageConverter.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace VisionBuilder.UI.Avalonia.Services;
|
||||
|
||||
public static class ImageConverter
|
||||
{
|
||||
public static global::Avalonia.Media.Imaging.Bitmap MatToAvaloniaBitmap(Mat mat)
|
||||
{
|
||||
var encoded = mat.ImEncode(".bmp");
|
||||
using var ms = new MemoryStream(encoded);
|
||||
return new global::Avalonia.Media.Imaging.Bitmap(ms);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user