2026-05-29 01:29:36 +01:00
|
|
|
using System;
|
2026-08-23 21:28:26 +01:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2026-05-29 01:29:36 +01:00
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Controls.Templates;
|
2026-06-11 00:14:51 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2026-05-29 01:29:36 +01:00
|
|
|
using PostIt.ViewModels;
|
2026-09-04 13:19:31 +01:00
|
|
|
using PostIt.ViewModels.Commands;
|
2026-06-11 00:14:51 +01:00
|
|
|
using PostIt.Views;
|
2026-09-07 14:39:53 +01:00
|
|
|
using PostIt.Views.Blogs;
|
2026-09-04 13:19:31 +01:00
|
|
|
using PostIt.Views.Commands;
|
2026-05-29 01:29:36 +01:00
|
|
|
|
|
|
|
|
namespace PostIt;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Given a view model, returns the corresponding view if possible.
|
|
|
|
|
/// </summary>
|
2026-08-23 21:28:26 +01:00
|
|
|
[RequiresUnreferencedCode(
|
|
|
|
|
"Default implementation of ViewLocator involves reflection which may be trimmed away.",
|
|
|
|
|
Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")]
|
2026-05-29 01:29:36 +01:00
|
|
|
public class ViewLocator : IDataTemplate
|
|
|
|
|
{
|
|
|
|
|
|
2026-09-06 20:24:19 +01:00
|
|
|
public Control Build(object? data)
|
2026-08-19 17:32:51 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return BuildCore(data);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return new TextBlock { Text = $"ViewLocator threw: {ex}" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-23 21:28:26 +01:00
|
|
|
|
2026-08-19 17:32:51 +01:00
|
|
|
private Control BuildCore(object? data)
|
2026-05-29 01:29:36 +01:00
|
|
|
{
|
2026-08-24 00:03:14 +01:00
|
|
|
var app = App.Current as App;
|
|
|
|
|
var services = app!.ServiceProvider!;
|
2026-06-11 00:14:51 +01:00
|
|
|
return data switch
|
|
|
|
|
{
|
2026-09-07 14:39:53 +01:00
|
|
|
BlogsViewModel => services.GetRequiredService<BlogsPage>(),
|
2026-08-24 00:03:14 +01:00
|
|
|
Settings => services.GetRequiredService<SettingsPage>(),
|
|
|
|
|
HomePageViewModel => services.GetRequiredService<HomePage>(),
|
2026-08-30 23:55:09 +01:00
|
|
|
ActivitiesPageViewModel => services.GetRequiredService<ActivitiesPage>(),
|
2026-08-31 03:37:09 +01:00
|
|
|
CommandFormsPageViewModel => services.GetRequiredService<CommandFormsPage>(),
|
2026-09-04 14:53:00 +01:00
|
|
|
BrushViewModel => services.GetRequiredService<BrushPage>(),
|
2026-09-04 13:19:31 +01:00
|
|
|
RdvViewModel => services.GetRequiredService<RdvPage>(),
|
2026-08-24 00:03:14 +01:00
|
|
|
SignaturePageViewModel => services.GetRequiredService<SignaturePage>(),
|
|
|
|
|
AddCircleMemberDialogViewModel => services.GetRequiredService<AddCircleMemberDialog>(),
|
|
|
|
|
CirclesPageViewModel => services.GetRequiredService<CirclesPage>(),
|
|
|
|
|
PostAclDialogViewModel => services.GetRequiredService<PostAclDialog>(),
|
2026-09-06 20:24:19 +01:00
|
|
|
BillingQueriesPageViewModel => services.GetRequiredService<BillingQueriesPage>(),
|
|
|
|
|
BillingQueryDetailsPageViewModel => services.GetRequiredService<BillingQueryDetailsPage>(),
|
2026-09-12 13:29:49 +01:00
|
|
|
ProviderOngoingRequestsPageViewModel => services.GetRequiredService<ProviderOngoingRequestsPage>(),
|
2026-09-13 18:54:27 +01:00
|
|
|
EstimateEditionPageViewModel => services.GetRequiredService<EstimateEditionPage>(),
|
2026-09-15 00:19:23 +01:00
|
|
|
EstimateListPageViewModel => services.GetRequiredService<EstimateListPage>(),
|
2026-07-07 20:59:26 +01:00
|
|
|
null => new TextBlock { Text = "No view for <null>" },
|
2026-08-19 17:32:51 +01:00
|
|
|
_ => new TextBlock { Text = $"No view for {data.GetType().Name}" }
|
2026-06-11 00:14:51 +01:00
|
|
|
};
|
2026-05-29 01:29:36 +01:00
|
|
|
}
|
2026-06-11 00:14:51 +01:00
|
|
|
|
2026-09-06 20:24:19 +01:00
|
|
|
public bool Match(object? data) => data is ViewModelBase;
|
2026-06-26 01:45:21 +01:00
|
|
|
}
|