2024-12-18 12:37:00 +03:00
|
|
|
using System;
|
2024-12-21 15:15:04 +03:00
|
|
|
using System.Reflection;
|
2024-12-18 12:37:00 +03:00
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Controls.Templates;
|
|
|
|
|
using Nebula.Launcher.ViewModels;
|
2025-02-02 10:57:29 +03:00
|
|
|
using Nebula.Launcher.Views;
|
2025-07-02 21:32:51 +03:00
|
|
|
using Nebula.Shared.ViewHelper;
|
2024-12-18 12:37:00 +03:00
|
|
|
|
|
|
|
|
namespace Nebula.Launcher;
|
|
|
|
|
|
|
|
|
|
public class ViewLocator : IDataTemplate
|
|
|
|
|
{
|
|
|
|
|
public Control? Build(object? param)
|
|
|
|
|
{
|
|
|
|
|
if (param is null)
|
|
|
|
|
return null;
|
2025-02-02 10:57:29 +03:00
|
|
|
|
|
|
|
|
if (param is Exception e)
|
|
|
|
|
{
|
|
|
|
|
return new ExceptionView(e);
|
|
|
|
|
}
|
2025-01-14 22:10:16 +03:00
|
|
|
|
2025-01-05 17:05:23 +03:00
|
|
|
var type = param.GetType().GetCustomAttribute<ViewModelRegisterAttribute>()?.Type;
|
2024-12-18 12:37:00 +03:00
|
|
|
|
2025-01-14 22:10:16 +03:00
|
|
|
if (type != null) return (Control)Activator.CreateInstance(type)!;
|
2024-12-18 12:37:00 +03:00
|
|
|
|
2025-01-14 22:10:16 +03:00
|
|
|
return new TextBlock { Text = "Not Found: " + param.GetType() };
|
2024-12-18 12:37:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Match(object? data)
|
|
|
|
|
{
|
2025-02-02 10:57:29 +03:00
|
|
|
return data is ViewModelBase || data is Exception;
|
2024-12-18 12:37:00 +03:00
|
|
|
}
|
|
|
|
|
}
|