forked from Misaki/GhostEngine
Refactor application structure and add unit tests
Added: - New `ProgressService` class for managing progress indicators. - New `AssetDatabase`, `AssetOpenHandlerAttribute`, and `AsyncAssetOpenHandlerAttribute` classes for asset handling. - `Ghost.UnitTest` project for unit testing with associated files and configurations. Changed: - `ActivationHandler` class to ensure correct handling of `LaunchActivatedEventArgs`. - `App.xaml.cs` to register `INotificationService` and `IProgressService`, replacing `StackedNotificationService`. - `OnLaunched` method in `App.xaml.cs` to correctly call `ActivationHandler.Handle(args)` and start the host. - `INavigationAware` interface from internal to public for broader access. - `EditorState.cs` to activate `EditorApplication` with the current service provider. - Property names in `AssetItem` and `ExplorerItem` structs to `Name` and `FullName`. - `NotificationService` class to implement `INotificationService` and refactor notification handling. - `AssetPathToGlyphConverter` to handle file extensions consistently. - Bindings in `ProjectPage.xaml` and `ProjectPage.xaml.cs` to use `FullName` instead of `Path`. - `EngineEditorWindow` and `LandingWindow` classes to utilize new notification and progress services. - `Logger` class to include a new method for logging errors with exceptions. Updated: - Manifest files and project files to reflect new structure and dependencies. - Solution file `GhostEngine.sln` to include the new unit test project. - Added several new test classes and methods in `UnitTests.cs`.
This commit is contained in:
52
Ghost.App/Services/NotificationService.cs
Normal file
52
Ghost.App/Services/NotificationService.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using CommunityToolkit.WinUI.Behaviors;
|
||||
using Ghost.Editor.Models;
|
||||
using Ghost.Editor.Services.Contracts;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using System;
|
||||
|
||||
namespace Ghost.App.Services;
|
||||
|
||||
public class NotificationService : INotificationService
|
||||
{
|
||||
private InfoBar? _infoBar;
|
||||
private StackedNotificationsBehavior? _notificationQueue;
|
||||
|
||||
internal void SetReference(InfoBar infoBar, StackedNotificationsBehavior notificationQueue)
|
||||
{
|
||||
_infoBar = infoBar;
|
||||
_notificationQueue = notificationQueue;
|
||||
}
|
||||
|
||||
public void ShowNotification(string? message, MessageType type, int duration = 5, string? title = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var notification = new Notification
|
||||
{
|
||||
Message = message,
|
||||
Severity = (InfoBarSeverity)type,
|
||||
Duration = TimeSpan.FromSeconds(duration),
|
||||
Title = title
|
||||
};
|
||||
|
||||
ShowNotification(notification);
|
||||
}
|
||||
|
||||
public void ShowNotification(Notification notification)
|
||||
{
|
||||
_notificationQueue?.Show(notification);
|
||||
}
|
||||
|
||||
internal void ClearReference()
|
||||
{
|
||||
if (_infoBar != null)
|
||||
{
|
||||
_infoBar.IsOpen = false;
|
||||
}
|
||||
_infoBar = null;
|
||||
_notificationQueue = null;
|
||||
}
|
||||
}
|
||||
75
Ghost.App/Services/ProgressService.cs
Normal file
75
Ghost.App/Services/ProgressService.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using CommunityToolkit.WinUI;
|
||||
using Ghost.Editor.Services.Contracts;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ghost.App.Services;
|
||||
|
||||
public class ProgressService : IProgressService
|
||||
{
|
||||
private Grid? _progressBarContainer;
|
||||
private TextBlock? _progressMessage;
|
||||
private ProgressBar? _progressBar;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool IsInitialized()
|
||||
{
|
||||
return _progressBarContainer != null && _progressMessage != null && _progressBar != null;
|
||||
}
|
||||
|
||||
internal void SetReference(Grid progressBarContainer)
|
||||
{
|
||||
_progressBarContainer = progressBarContainer;
|
||||
_progressMessage = _progressBarContainer.FindChild<TextBlock>();
|
||||
_progressBar = _progressBarContainer.FindChild<ProgressBar>();
|
||||
}
|
||||
|
||||
public void ShowProgress(string message, double progress = 0.0)
|
||||
{
|
||||
if (!IsInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_progressBarContainer!.Visibility = Visibility.Visible;
|
||||
_progressMessage!.Text = message;
|
||||
_progressBar!.Value = progress;
|
||||
}
|
||||
|
||||
public void ShowIndeterminateProgress(string message)
|
||||
{
|
||||
if (!IsInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_progressBarContainer!.Visibility = Visibility.Visible;
|
||||
_progressMessage!.Text = message;
|
||||
_progressBar!.IsIndeterminate = true;
|
||||
}
|
||||
|
||||
public void SetProgress(double progress)
|
||||
{
|
||||
_progressBar!.Value = progress;
|
||||
}
|
||||
|
||||
public void HideProgress()
|
||||
{
|
||||
if (!IsInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_progressBarContainer!.Visibility = Visibility.Collapsed;
|
||||
_progressMessage!.Text = string.Empty;
|
||||
_progressBar!.Value = 0.0;
|
||||
}
|
||||
|
||||
internal void ClearReference()
|
||||
{
|
||||
_progressBarContainer = null;
|
||||
_progressMessage = null;
|
||||
_progressBar = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user