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
}
}