From 21932056f3169113274a4271b3ef02c932ddb13e Mon Sep 17 00:00:00 2001
From: CJKmkp <2564608840@qq.com>
Date: Sun, 31 Aug 2025 13:14:05 +0800
Subject: [PATCH] =?UTF-8?q?improve:=E6=8F=92=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Helpers/Plugins/EnhancedPluginBaseV2.cs | 241 ++++++++
Ink Canvas/Helpers/Plugins/IActionService.cs | 296 ++++++++++
Ink Canvas/Helpers/Plugins/IGetService.cs | 215 ++++++++
Ink Canvas/Helpers/Plugins/IPluginService.cs | 521 +-----------------
Ink Canvas/Helpers/Plugins/IWindowService.cs | 154 ++++++
.../Helpers/Plugins/PluginServiceManager.cs | 282 ++++++----
6 files changed, 1078 insertions(+), 631 deletions(-)
create mode 100644 Ink Canvas/Helpers/Plugins/EnhancedPluginBaseV2.cs
create mode 100644 Ink Canvas/Helpers/Plugins/IActionService.cs
create mode 100644 Ink Canvas/Helpers/Plugins/IGetService.cs
create mode 100644 Ink Canvas/Helpers/Plugins/IWindowService.cs
diff --git a/Ink Canvas/Helpers/Plugins/EnhancedPluginBaseV2.cs b/Ink Canvas/Helpers/Plugins/EnhancedPluginBaseV2.cs
new file mode 100644
index 00000000..d4f2f96f
--- /dev/null
+++ b/Ink Canvas/Helpers/Plugins/EnhancedPluginBaseV2.cs
@@ -0,0 +1,241 @@
+using System.Windows.Controls;
+
+namespace Ink_Canvas.Helpers.Plugins
+{
+ ///
+ /// 增强的插件基类 V2,提供对三个专门服务接口的访问
+ /// 插件开发者可以根据需要选择性地使用这些服务
+ ///
+ public abstract class EnhancedPluginBaseV2 : PluginBase, IEnhancedPlugin
+ {
+ ///
+ /// 获取服务实例
+ ///
+ public IGetService GetService { get; private set; }
+
+ ///
+ /// 窗口服务实例
+ ///
+ public IWindowService WindowService { get; private set; }
+
+ ///
+ /// 操作服务实例
+ ///
+ public IActionService ActionService { get; private set; }
+
+ ///
+ /// 插件服务实例(兼容性)
+ ///
+ public IPluginService PluginService { get; private set; }
+
+ ///
+ /// 构造函数
+ ///
+ protected EnhancedPluginBaseV2()
+ {
+ // 初始化所有服务实例
+ PluginService = PluginServiceManager.Instance;
+ GetService = PluginServiceManager.Instance;
+ WindowService = PluginServiceManager.Instance;
+ ActionService = PluginServiceManager.Instance;
+ }
+
+ ///
+ /// 插件启动时调用,在Initialize之后
+ ///
+ public virtual void OnStartup()
+ {
+ LogHelper.WriteLogToFile($"插件 {Name} 已启动");
+ }
+
+ ///
+ /// 插件关闭时调用,在Cleanup之前
+ ///
+ public virtual void OnShutdown()
+ {
+ LogHelper.WriteLogToFile($"插件 {Name} 正在关闭");
+ }
+
+ ///
+ /// 获取插件的菜单项
+ ///
+ /// 菜单项集合
+ public virtual MenuItem[] GetMenuItems()
+ {
+ return new MenuItem[0];
+ }
+
+ ///
+ /// 获取插件的工具栏按钮
+ ///
+ /// 工具栏按钮集合
+ public virtual Button[] GetToolbarButtons()
+ {
+ return new Button[0];
+ }
+
+ ///
+ /// 获取插件的状态栏信息
+ ///
+ /// 状态栏信息
+ public virtual string GetStatusBarInfo()
+ {
+ return $"{Name} v{Version} - {(IsEnabled ? "已启用" : "已禁用")}";
+ }
+
+ ///
+ /// 插件配置变更时调用
+ ///
+ public virtual void OnConfigurationChanged()
+ {
+ LogHelper.WriteLogToFile($"插件 {Name} 配置已变更");
+ }
+
+ #region 便捷方法
+
+ ///
+ /// 显示通知消息
+ ///
+ /// 消息内容
+ /// 消息类型
+ protected void ShowNotification(string message, NotificationType type = NotificationType.Info)
+ {
+ WindowService.ShowNotification(message, type);
+ }
+
+ ///
+ /// 显示确认对话框
+ ///
+ /// 消息内容
+ /// 标题
+ /// 用户选择结果
+ protected bool ShowConfirmDialog(string message, string title = "确认")
+ {
+ return WindowService.ShowConfirmDialog(message, title);
+ }
+
+ ///
+ /// 显示输入对话框
+ ///
+ /// 提示消息
+ /// 标题
+ /// 默认值
+ /// 用户输入内容
+ protected string ShowInputDialog(string message, string title = "输入", string defaultValue = "")
+ {
+ return WindowService.ShowInputDialog(message, title, defaultValue);
+ }
+
+ ///
+ /// 获取系统设置
+ ///
+ /// 设置类型
+ /// 设置键
+ /// 默认值
+ /// 设置值
+ protected T GetSetting(string key, T defaultValue = default(T))
+ {
+ return GetService.GetSetting(key, defaultValue);
+ }
+
+ ///
+ /// 设置系统设置
+ ///
+ /// 设置类型
+ /// 设置键
+ /// 设置值
+ protected void SetSetting(string key, T value)
+ {
+ ActionService.SetSetting(key, value);
+ }
+
+ ///
+ /// 保存设置
+ ///
+ protected void SaveSettings()
+ {
+ ActionService.SaveSettings();
+ }
+
+ ///
+ /// 清除当前画布
+ ///
+ protected void ClearCanvas()
+ {
+ ActionService.ClearCanvas();
+ }
+
+ ///
+ /// 撤销操作
+ ///
+ protected void Undo()
+ {
+ ActionService.Undo();
+ }
+
+ ///
+ /// 重做操作
+ ///
+ protected void Redo()
+ {
+ ActionService.Redo();
+ }
+
+ ///
+ /// 检查是否可以撤销
+ ///
+ protected bool CanUndo => GetService.CanUndo;
+
+ ///
+ /// 检查是否可以重做
+ ///
+ protected bool CanRedo => GetService.CanRedo;
+
+ ///
+ /// 获取当前绘制模式
+ ///
+ protected int CurrentDrawingMode => GetService.CurrentDrawingMode;
+
+ ///
+ /// 设置绘制模式
+ ///
+ /// 绘制模式
+ protected void SetDrawingMode(int mode)
+ {
+ ActionService.SetDrawingMode(mode);
+ }
+
+ ///
+ /// 注册事件处理器
+ ///
+ /// 事件名称
+ /// 事件处理器
+ protected void RegisterEventHandler(string eventName, System.EventHandler handler)
+ {
+ ActionService.RegisterEventHandler(eventName, handler);
+ }
+
+ ///
+ /// 注销事件处理器
+ ///
+ /// 事件名称
+ /// 事件处理器
+ protected void UnregisterEventHandler(string eventName, System.EventHandler handler)
+ {
+ ActionService.UnregisterEventHandler(eventName, handler);
+ }
+
+ ///
+ /// 触发事件
+ ///
+ /// 事件名称
+ /// 事件发送者
+ /// 事件参数
+ protected void TriggerEvent(string eventName, object sender, System.EventArgs args)
+ {
+ ActionService.TriggerEvent(eventName, sender, args);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Ink Canvas/Helpers/Plugins/IActionService.cs b/Ink Canvas/Helpers/Plugins/IActionService.cs
new file mode 100644
index 00000000..0101a605
--- /dev/null
+++ b/Ink Canvas/Helpers/Plugins/IActionService.cs
@@ -0,0 +1,296 @@
+using System;
+using System.Windows.Media;
+
+namespace Ink_Canvas.Helpers.Plugins
+{
+ ///
+ /// 操作服务接口,统一所有执行操作相关的方法
+ ///
+ public interface IActionService
+ {
+ #region 画布操作
+
+ ///
+ /// 清除当前画布
+ ///
+ void ClearCanvas();
+
+ ///
+ /// 清除所有画布
+ ///
+ void ClearAllCanvases();
+
+ ///
+ /// 添加新页面
+ ///
+ void AddNewPage();
+
+ ///
+ /// 删除当前页面
+ ///
+ void DeleteCurrentPage();
+
+ ///
+ /// 切换到指定页面
+ ///
+ /// 页面索引
+ void SwitchToPage(int pageIndex);
+
+ ///
+ /// 切换到下一页
+ ///
+ void NextPage();
+
+ ///
+ /// 切换到上一页
+ ///
+ void PreviousPage();
+
+ #endregion
+
+ #region 绘制操作
+
+ ///
+ /// 设置绘制模式
+ ///
+ /// 绘制模式
+ void SetDrawingMode(int mode);
+
+ ///
+ /// 设置笔触宽度
+ ///
+ /// 宽度
+ void SetInkWidth(double width);
+
+ ///
+ /// 设置笔触颜色
+ ///
+ /// 颜色
+ void SetInkColor(Color color);
+
+ ///
+ /// 设置高亮笔宽度
+ ///
+ /// 宽度
+ void SetHighlighterWidth(double width);
+
+ ///
+ /// 设置橡皮擦大小
+ ///
+ /// 大小
+ void SetEraserSize(int size);
+
+ ///
+ /// 设置橡皮擦类型
+ ///
+ /// 类型
+ void SetEraserType(int type);
+
+ ///
+ /// 设置橡皮擦形状
+ ///
+ /// 形状
+ void SetEraserShape(int shape);
+
+ ///
+ /// 设置笔触透明度
+ ///
+ /// 透明度
+ void SetInkAlpha(double alpha);
+
+ ///
+ /// 设置笔触样式
+ ///
+ /// 样式
+ void SetInkStyle(int style);
+
+ ///
+ /// 设置背景颜色
+ ///
+ /// 颜色
+ void SetBackgroundColor(string color);
+
+ #endregion
+
+ #region 文件操作
+
+ ///
+ /// 保存画布内容
+ ///
+ /// 文件路径
+ void SaveCanvas(string filePath);
+
+ ///
+ /// 加载画布内容
+ ///
+ /// 文件路径
+ void LoadCanvas(string filePath);
+
+ ///
+ /// 导出为图片
+ ///
+ /// 文件路径
+ /// 图片格式
+ void ExportAsImage(string filePath, string format);
+
+ ///
+ /// 导出为PDF
+ ///
+ /// 文件路径
+ void ExportAsPDF(string filePath);
+
+ #endregion
+
+ #region 撤销重做操作
+
+ ///
+ /// 撤销操作
+ ///
+ void Undo();
+
+ ///
+ /// 重做操作
+ ///
+ void Redo();
+
+ #endregion
+
+ #region 选择操作
+
+ ///
+ /// 全选
+ ///
+ void SelectAll();
+
+ ///
+ /// 取消选择
+ ///
+ void DeselectAll();
+
+ ///
+ /// 删除选中内容
+ ///
+ void DeleteSelected();
+
+ ///
+ /// 复制选中内容
+ ///
+ void CopySelected();
+
+ ///
+ /// 剪切选中内容
+ ///
+ void CutSelected();
+
+ ///
+ /// 粘贴内容
+ ///
+ void Paste();
+
+ #endregion
+
+ #region 系统设置操作
+
+ ///
+ /// 设置系统设置
+ ///
+ /// 设置类型
+ /// 设置键
+ /// 设置值
+ void SetSetting(string key, T value);
+
+ ///
+ /// 保存设置到文件
+ ///
+ void SaveSettings();
+
+ ///
+ /// 从文件加载设置
+ ///
+ void LoadSettings();
+
+ ///
+ /// 重置设置为默认值
+ ///
+ void ResetSettings();
+
+ #endregion
+
+ #region 插件管理操作
+
+ ///
+ /// 启用插件
+ ///
+ /// 插件名称
+ void EnablePlugin(string pluginName);
+
+ ///
+ /// 禁用插件
+ ///
+ /// 插件名称
+ void DisablePlugin(string pluginName);
+
+ ///
+ /// 卸载插件
+ ///
+ /// 插件名称
+ void UnloadPlugin(string pluginName);
+
+ #endregion
+
+ #region 事件系统操作
+
+ ///
+ /// 注册事件处理器
+ ///
+ /// 事件名称
+ /// 事件处理器
+ void RegisterEventHandler(string eventName, EventHandler handler);
+
+ ///
+ /// 注销事件处理器
+ ///
+ /// 事件名称
+ /// 事件处理器
+ void UnregisterEventHandler(string eventName, EventHandler handler);
+
+ ///
+ /// 触发事件
+ ///
+ /// 事件名称
+ /// 事件发送者
+ /// 事件参数
+ void TriggerEvent(string eventName, object sender, EventArgs args);
+
+ #endregion
+
+ #region 应用程序操作
+
+ ///
+ /// 重启应用程序
+ ///
+ void RestartApplication();
+
+ ///
+ /// 退出应用程序
+ ///
+ void ExitApplication();
+
+ ///
+ /// 检查更新
+ ///
+ void CheckForUpdates();
+
+ ///
+ /// 打开帮助文档
+ ///
+ void OpenHelpDocument();
+
+ ///
+ /// 打开关于页面
+ ///
+ void OpenAboutPage();
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Ink Canvas/Helpers/Plugins/IGetService.cs b/Ink Canvas/Helpers/Plugins/IGetService.cs
new file mode 100644
index 00000000..70ff947e
--- /dev/null
+++ b/Ink Canvas/Helpers/Plugins/IGetService.cs
@@ -0,0 +1,215 @@
+using System;
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace Ink_Canvas.Helpers.Plugins
+{
+ ///
+ /// 获取服务接口,统一所有获取类的方法
+ ///
+ public interface IGetService
+ {
+ #region 窗口和UI获取
+
+ ///
+ /// 获取主窗口引用
+ ///
+ Window MainWindow { get; }
+
+ ///
+ /// 获取当前画布
+ ///
+ InkCanvas CurrentCanvas { get; }
+
+ ///
+ /// 获取所有画布页面
+ ///
+ List