add:插件
屎山
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<ui:Page
|
||||
x:Class="Ink_Canvas.Windows.SettingsViews.Pages.PluginPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
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:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||
Title="插件"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Margin="24">
|
||||
<TextBlock Text="🎨 插件管理" Style="{DynamicResource TitleTextBlockStyle}" Margin="0,0,0,16" />
|
||||
|
||||
<Border x:Name="StatusBorder" Background="{DynamicResource InfoAcrylicFillColorDefaultBrush}" Padding="12" CornerRadius="8" Margin="0,0,0,20">
|
||||
<TextBlock x:Name="PluginCountText" Text="正在加载插件..." Foreground="{DynamicResource InfoTextFillColorPrimaryBrush}" />
|
||||
</Border>
|
||||
|
||||
<StackPanel x:Name="PluginContainer" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</ui:Page>
|
||||
@@ -0,0 +1,120 @@
|
||||
using Ink_Canvas.Plugins;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Windows.SettingsViews.Pages
|
||||
{
|
||||
public partial class PluginPage : iNKORE.UI.WPF.Modern.Controls.Page
|
||||
{
|
||||
public PluginPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += PluginPage_Loaded;
|
||||
}
|
||||
|
||||
private void PluginPage_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
LoadPlugins();
|
||||
}
|
||||
|
||||
public void LoadPlugins()
|
||||
{
|
||||
try
|
||||
{
|
||||
var pluginManager = PluginManager.Instance;
|
||||
var plugins = pluginManager.Plugins;
|
||||
|
||||
PluginCountText.Text = string.Format("已加载 {0} 个插件", plugins.Count);
|
||||
|
||||
if (plugins.Count == 0)
|
||||
{
|
||||
PluginContainer.Children.Clear();
|
||||
var noPluginText = new TextBlock
|
||||
{
|
||||
Text = "没有找到插件,请将插件文件放置在 Plugins 目录中",
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
Foreground = Brushes.Gray,
|
||||
Margin = new Thickness(0, 10, 0, 0)
|
||||
};
|
||||
PluginContainer.Children.Add(noPluginText);
|
||||
return;
|
||||
}
|
||||
|
||||
PluginContainer.Children.Clear();
|
||||
|
||||
foreach (var pluginInfo in plugins)
|
||||
{
|
||||
var pluginCard = CreatePluginCard(pluginInfo);
|
||||
PluginContainer.Children.Add(pluginCard);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginCountText.Text = string.Format("加载插件时出错:{0}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private Border CreatePluginCard(PluginInfo pluginInfo)
|
||||
{
|
||||
var card = new Border
|
||||
{
|
||||
Background = Brushes.White,
|
||||
BorderBrush = Brushes.LightGray,
|
||||
BorderThickness = new Thickness(1),
|
||||
CornerRadius = new CornerRadius(8),
|
||||
Margin = new Thickness(0, 0, 0, 10),
|
||||
Padding = new Thickness(15)
|
||||
};
|
||||
|
||||
var stackPanel = new StackPanel();
|
||||
|
||||
var titlePanel = new DockPanel { LastChildFill = true };
|
||||
|
||||
var nameText = new TextBlock
|
||||
{
|
||||
Text = pluginInfo.Name,
|
||||
FontSize = 16,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Foreground = Brushes.Black,
|
||||
Margin = new Thickness(0, 0, 10, 0)
|
||||
};
|
||||
DockPanel.SetDock(nameText, Dock.Left);
|
||||
|
||||
var versionText = new TextBlock
|
||||
{
|
||||
Text = string.Format("v{0}", pluginInfo.Version),
|
||||
FontSize = 12,
|
||||
Foreground = Brushes.Gray,
|
||||
VerticalAlignment = VerticalAlignment.Center
|
||||
};
|
||||
|
||||
titlePanel.Children.Add(nameText);
|
||||
titlePanel.Children.Add(versionText);
|
||||
|
||||
var descriptionText = new TextBlock
|
||||
{
|
||||
Text = pluginInfo.Description,
|
||||
FontSize = 12,
|
||||
Foreground = Brushes.DarkGray,
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
Margin = new Thickness(0, 5, 0, 5)
|
||||
};
|
||||
|
||||
var authorText = new TextBlock
|
||||
{
|
||||
Text = string.Format("作者:{0}", pluginInfo.Author),
|
||||
FontSize = 11,
|
||||
Foreground = Brushes.Gray
|
||||
};
|
||||
|
||||
stackPanel.Children.Add(titlePanel);
|
||||
stackPanel.Children.Add(descriptionText);
|
||||
stackPanel.Children.Add(authorText);
|
||||
|
||||
card.Child = stackPanel;
|
||||
return card;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<ui:Page
|
||||
x:Class="Ink_Canvas.Windows.SettingsViews.Pages.PluginSettingsPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
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:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||
Title="插件设置"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<ContentControl x:Name="PluginSettingsContent" Margin="24" />
|
||||
</Grid>
|
||||
</ui:Page>
|
||||
@@ -0,0 +1,71 @@
|
||||
using Ink_Canvas.Plugins;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Ink_Canvas.Windows.SettingsViews.Pages
|
||||
{
|
||||
public partial class PluginSettingsPage : iNKORE.UI.WPF.Modern.Controls.Page
|
||||
{
|
||||
private static PluginInfo _currentPlugin;
|
||||
|
||||
public static PluginInfo CurrentPlugin
|
||||
{
|
||||
get { return _currentPlugin; }
|
||||
set
|
||||
{
|
||||
_currentPlugin = value;
|
||||
}
|
||||
}
|
||||
|
||||
public PluginSettingsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
Loaded += PluginSettingsPage_Loaded;
|
||||
}
|
||||
|
||||
private void PluginSettingsPage_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
LoadPluginSettings();
|
||||
}
|
||||
|
||||
public void LoadPluginSettings()
|
||||
{
|
||||
if (_currentPlugin == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var settingsView = _currentPlugin.Instance.GetSettingsView();
|
||||
if (settingsView != null && settingsView is UIElement uiElement)
|
||||
{
|
||||
var parent = VisualTreeHelper.GetParent(uiElement);
|
||||
if (parent != null)
|
||||
{
|
||||
if (parent is Decorator decorator)
|
||||
{
|
||||
decorator.Child = null;
|
||||
}
|
||||
else if (parent is ContentControl contentControl)
|
||||
{
|
||||
contentControl.Content = null;
|
||||
}
|
||||
else if (parent is Panel panel)
|
||||
{
|
||||
panel.Children.Remove(uiElement);
|
||||
}
|
||||
}
|
||||
|
||||
PluginSettingsContent.Content = uiElement;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("加载插件设置时出错: {0}", ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,15 @@
|
||||
</ui:NavigationViewItem.MenuItems>
|
||||
</ui:NavigationViewItem>
|
||||
<ui:NavigationViewItemHeader Content="插件设置"/>
|
||||
<ui:NavigationViewItem
|
||||
x:Name="PluginItem"
|
||||
Content="插件"
|
||||
Tag="PluginPage"
|
||||
ToolTipService.ToolTip="插件管理">
|
||||
<ui:NavigationViewItem.Icon>
|
||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Puzzle}"/>
|
||||
</ui:NavigationViewItem.Icon>
|
||||
</ui:NavigationViewItem>
|
||||
</ui:NavigationView.MenuItems>
|
||||
|
||||
<ui:NavigationView.FooterMenuItems>
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Media;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
using Screen = System.Windows.Forms.Screen;
|
||||
|
||||
@@ -15,6 +16,7 @@ namespace Ink_Canvas.Windows.SettingsViews
|
||||
{
|
||||
private readonly Dictionary<string, Type> _pageTypes;
|
||||
private readonly Dictionary<string, object> _pages = new Dictionary<string, object>();
|
||||
private readonly Dictionary<string, Ink_Canvas.Plugins.PluginInfo> _pluginPages = new Dictionary<string, Ink_Canvas.Plugins.PluginInfo>();
|
||||
|
||||
// 保存窗口原始位置和大小
|
||||
private double _originalLeft;
|
||||
@@ -44,7 +46,9 @@ namespace Ink_Canvas.Windows.SettingsViews
|
||||
{ "FontsPage", typeof(FontsPage) },
|
||||
{ "StartupPage", typeof(StartupPage) },
|
||||
{ "AboutPage", typeof(AboutPage) },
|
||||
{ "Settings", typeof(SettingsPage) }
|
||||
{ "Settings", typeof(SettingsPage) },
|
||||
{ "PluginPage", typeof(PluginPage) },
|
||||
{ "PluginSettingsPage", typeof(PluginSettingsPage) }
|
||||
};
|
||||
|
||||
// 默认选中首页
|
||||
@@ -65,6 +69,7 @@ namespace Ink_Canvas.Windows.SettingsViews
|
||||
{
|
||||
SetMaxSizeAndCenter();
|
||||
RegisterDpiChangedListener();
|
||||
LoadPluginSettingsPages();
|
||||
};
|
||||
|
||||
// 窗口关闭时释放资源
|
||||
@@ -258,6 +263,12 @@ namespace Ink_Canvas.Windows.SettingsViews
|
||||
string tag = selectedItem.Tag as string;
|
||||
if (!string.IsNullOrEmpty(tag) && _pageTypes.ContainsKey(tag))
|
||||
{
|
||||
// 如果是插件设置页面,设置当前插件
|
||||
if (_pluginPages.TryGetValue(tag, out var plugin))
|
||||
{
|
||||
PluginSettingsPage.CurrentPlugin = plugin;
|
||||
}
|
||||
|
||||
// 避免重复导航到当前页面
|
||||
if (rootFrame.SourcePageType != _pageTypes[tag])
|
||||
{
|
||||
@@ -458,6 +469,44 @@ namespace Ink_Canvas.Windows.SettingsViews
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private void LoadPluginSettingsPages()
|
||||
{
|
||||
try
|
||||
{
|
||||
var pluginManager = Ink_Canvas.Plugins.PluginManager.Instance;
|
||||
var plugins = pluginManager.Plugins;
|
||||
|
||||
foreach (var plugin in plugins)
|
||||
{
|
||||
var settingsView = plugin.Instance.GetSettingsView();
|
||||
if (settingsView != null)
|
||||
{
|
||||
var pageTag = string.Format("PluginSettings_{0}", plugin.Id);
|
||||
|
||||
_pageTypes[pageTag] = typeof(PluginSettingsPage);
|
||||
_pluginPages[pageTag] = plugin;
|
||||
|
||||
var navItem = new NavigationViewItem
|
||||
{
|
||||
Content = string.Format("{0} 设置", plugin.Name),
|
||||
Tag = pageTag
|
||||
};
|
||||
|
||||
navItem.Icon = new FontIcon
|
||||
{
|
||||
Glyph = "\uE713"
|
||||
};
|
||||
|
||||
NavigationViewControl.MenuItems.Add(navItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(string.Format("加载插件设置页面时出错: {0}", ex.Message));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user