Files
Better-Seewo/Better-EN5/UI/ImportInkMenuItem.cs
miao-moe 8dd1eed519 feat: Better-Seewo v2.0.0 - 希沃白板功能增强插件
- Fluent Design 风格 UI,深色/浅色主题切换
- 平滑过渡动画(页面切换、按钮交互、状态变化)
- 五大核心功能:安装管理、墨迹管理、格式转换、触摸设置、激活管理
- 基于 dotnetCampus.EasiPlugin.Sdk v2.1.1-alpha.3 插件框架
- WPF 安装向导(欢迎页 -> 安装页 -> 完成页)
2026-06-28 06:51:35 +00:00

128 lines
4.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* ImportInkMenuItem.cs
* "导入墨迹" 菜单项
* 所属项目Better-Seewo
* 作者:雾启工作室
*
* 说明:
* 实现白板编辑菜单中的"导入墨迹"功能。
* 点击后打开文件选择对话框,选择 .ink.json 文件导入到当前白板。
* 默认文件名为"课件墨迹.ink.json"。
*/
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using dotnetCampus.EasiPlugin;
using Newtonsoft.Json;
namespace Better_Seewo.Better_EN5.UI
{
/// <summary>
/// 导入墨迹菜单项
/// 实现 IMenuPluginItem 接口,在白板编辑菜单中显示"导入墨迹"按钮
/// 点击后打开文件选择对话框,读取 JSON 文件并将墨迹数据应用到白板
/// </summary>
public class ImportInkMenuItem : IMenuPluginItem
{
/// <summary>
/// 菜单项唯一标识符
/// </summary>
public Guid Id { get; } = new Guid("B2C3D4E5-F6A7-8901-BCDE-F12345678901");
/// <summary>
/// 菜单项显示标题
/// 根据当前语言环境显示"导入墨迹"或"Import Ink"
/// </summary>
public string Title { get; }
/// <summary>
/// 菜单项排序提示值
/// 值越大越靠前997 表示在菜单中位于"导出墨迹"之后
/// </summary>
public int SortHint { get; } = 997;
/// <summary>
/// 语言资源源,用于获取多语言文本
/// </summary>
private readonly DictionaryLanguageSource _languageSource;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="languageSource">中英文双语资源字典</param>
public ImportInkMenuItem(DictionaryLanguageSource languageSource)
{
_languageSource = languageSource;
// 从语言资源中获取菜单项标题,默认中文
Title = _languageSource.GetString("ImportInk.Title") ?? "导入墨迹";
}
/// <summary>
/// 获取菜单项图标
/// 返回菜单项在工具栏中显示的图标资源路径
/// </summary>
/// <returns>图标资源路径字符串</returns>
public string GetMenuIcon()
{
// 返回导入图标路径
return "pack://application:,,,/Better-EN5;component/Resources/import_icon.png";
}
/// <summary>
/// 菜单项点击事件处理
/// 打开文件选择对话框,读取 .ink.json 文件并将墨迹数据导入到当前白板
/// </summary>
public async Task OnClickAsync()
{
await Task.Run(() =>
{
// 创建文件选择对话框
var openFileDialog = new Microsoft.Win32.OpenFileDialog
{
// 默认文件名
FileName = "课件墨迹.ink.json",
// 文件过滤器
Filter = "墨迹 JSON 文件 (*.ink.json)|*.ink.json|所有文件 (*.*)|*.*",
// 默认扩展名
DefaultExt = ".ink.json",
// 对话框标题
Title = "导入墨迹",
};
// 显示打开对话框
if (openFileDialog.ShowDialog() == true)
{
try
{
// 读取 JSON 文件内容
string json = File.ReadAllText(openFileDialog.FileName);
// 使用 Newtonsoft.Json 反序列化墨迹数据
var inkData = JsonConvert.DeserializeObject<InkStrokeCollection>(json);
if (inkData == null)
{
MessageBox.Show("无法解析所选文件的墨迹数据。", "导入失败",
MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
// 将墨迹数据应用到白板
InkDataHelper.ImportInkData(inkData);
}
catch (Exception ex)
{
// 捕获并提示导入过程中的异常
MessageBox.Show($"导入墨迹时发生错误:\n{ex.Message}", "导入失败",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
});
}
}
}