Skip to content

Commit

Permalink
Add plugins dialog view
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Feb 21, 2024
1 parent 58905f0 commit c8c83bc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/NxEditor.Core/Components/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace NxEditor.Core.Components;
public static class PluginManager
{
private static readonly string _path = Path.Combine(GlobalConfig.Shared.StorageFolder, "plugins");
private static readonly List<IServiceExtension> _extensions = [];
private static readonly Dictionary<Type, IConfigModule> _modules = [];

public static List<IServiceExtension> Extensions { get; } = [];
public static Dictionary<Type, IConfigModule> Modules { get; } = [];

public static void Load()
{
Expand All @@ -25,7 +26,7 @@ public static void Load()
public static bool ValidateModules()
{
bool result = true;
foreach ((_, var module) in _modules) {
foreach ((_, var module) in Modules) {
result = result && module.Shared.Validate(out _);
}

Expand All @@ -35,7 +36,7 @@ public static bool ValidateModules()
public static bool RegisterModules(ConfigPageModel configPage)
{
bool result = true;
foreach ((var type, var module) in _modules) {
foreach ((var type, var module) in Modules) {
try {
configPage.Append(module.Shared);
configPage.ConfigModules.Add(type.Name, module.Shared);
Expand All @@ -51,7 +52,7 @@ public static bool RegisterModules(ConfigPageModel configPage)

public static void RegisterExtensions()
{
foreach (var extension in _extensions) {
foreach (var extension in Extensions) {
try {
extension.RegisterExtension(ServiceLoader.Shared);
}
Expand Down Expand Up @@ -96,7 +97,7 @@ private static void LoadPlugin(PluginInfo info)

foreach (var type in types.Where(x => x.GetInterface("IConfigModule") == typeof(IConfigModule))) {
try {
_modules.Add(type, (IConfigModule)Activator.CreateInstance(type)!);
Modules.Add(type, (IConfigModule)Activator.CreateInstance(type)!);
}
catch (Exception ex) {
Logger.Write(new Exception($"Failed to load ConfigModule: {info.Name}", ex));
Expand All @@ -105,7 +106,7 @@ private static void LoadPlugin(PluginInfo info)

foreach (var type in types.Where(x => x.GetInterface("IServiceExtension") == typeof(IServiceExtension))) {
try {
_extensions.Add((IServiceExtension)Activator.CreateInstance(type)!);
Extensions.Add((IServiceExtension)Activator.CreateInstance(type)!);
}
catch (Exception ex) {
Logger.Write(new Exception($"Failed to load ServiceExtension: {info.Name}", ex));
Expand Down
4 changes: 2 additions & 2 deletions src/NxEditor.Core/NxEditor.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="NxEditor.PluginBase" Version="1.3.1" />
<PackageReference Include="Octokit" Version="9.1.1" />
<PackageReference Include="NxEditor.PluginBase" Version="1.4.0" />
<PackageReference Include="Octokit" Version="9.1.2" />
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions src/NxEditor/Models/Menus/ShellViewMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NxEditor.PluginBase.Attributes;
using NxEditor.PluginBase.Common;
using NxEditor.PluginBase.Models;
using NxEditor.Views.Dialogs;
using System.Collections.ObjectModel;
using System.Text;

Expand Down Expand Up @@ -220,6 +221,16 @@ you can just message me on Discord or GitHub.
}.ShowAsync();
}

[Menu("Plugins", "About", "Alt + F1", "fa-solid fa-list-ul")]
public static async Task Plugins()
{
await new DialogBox {
Title = "Plugins",
IsSecondaryButtonVisible = false,
Content = new AboutDialogView()
}.ShowAsync();
}

[Menu("About", "About", "Ctrl + F12", "fa-solid fa-circle-info")]
public static async Task About()
{
Expand Down
23 changes: 23 additions & 0 deletions src/NxEditor/Views/Dialogs/AboutDialogView.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<UserControl x:Class="NxEditor.Views.Dialogs.AboutDialogView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:comp="using:NxEditor.Core.Components"
xmlns:models="using:NxEditor.PluginBase"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<StackPanel>
<ItemsControl ItemsSource="{x:Static comp:PluginManager.Extensions}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type models:IServiceExtension}">
<TextBlock Margin="0,2">
<Run Text="{Binding Name, StringFormat='- {0}'}" />
<Run Text="{Binding Version}" />
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</UserControl>
10 changes: 10 additions & 0 deletions src/NxEditor/Views/Dialogs/AboutDialogView.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Avalonia.Controls;

namespace NxEditor.Views.Dialogs;
public partial class AboutDialogView : UserControl
{
public AboutDialogView()
{
InitializeComponent();
}
}

0 comments on commit c8c83bc

Please sign in to comment.