Files
Better-Seewo/Better-EN5/UI/ExportInkMenuItem.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

119 lines
4.0 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.
/*
* ExportInkMenuItem.cs
* "导出墨迹" 菜单项
* 所属项目Better-Seewo
* 作者:雾启工作室
*
* 说明:
* 实现白板编辑菜单中的"导出墨迹"功能。
* 点击后将当前白板的墨迹数据导出为 .ink.json 格式的 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 ExportInkMenuItem : IMenuPluginItem
{
/// <summary>
/// 菜单项唯一标识符
/// </summary>
public Guid Id { get; } = new Guid("A1B2C3D4-E5F6-7890-ABCD-EF1234567890");
/// <summary>
/// 菜单项显示标题
/// 根据当前语言环境显示"导出墨迹"或"Export Ink"
/// </summary>
public string Title { get; }
/// <summary>
/// 菜单项排序提示值
/// 值越大越靠前998 表示在菜单中靠前的位置
/// </summary>
public int SortHint { get; } = 998;
/// <summary>
/// 语言资源源,用于获取多语言文本
/// </summary>
private readonly DictionaryLanguageSource _languageSource;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="languageSource">中英文双语资源字典</param>
public ExportInkMenuItem(DictionaryLanguageSource languageSource)
{
_languageSource = languageSource;
// 从语言资源中获取菜单项标题,默认中文
Title = _languageSource.GetString("ExportInk.Title") ?? "导出墨迹";
}
/// <summary>
/// 获取菜单项图标
/// 返回菜单项在工具栏中显示的图标资源路径
/// </summary>
/// <returns>图标资源路径字符串</returns>
public string GetMenuIcon()
{
// 返回导出图标路径
return "pack://application:,,,/Better-EN5;component/Resources/export_icon.png";
}
/// <summary>
/// 菜单项点击事件处理
/// 打开文件保存对话框,将当前白板墨迹导出为 .ink.json 文件
/// </summary>
public async Task OnClickAsync()
{
await Task.Run(() =>
{
// 从白板获取当前墨迹数据
var inkData = InkDataHelper.ExportInkData();
if (inkData == null)
{
MessageBox.Show("当前白板没有可导出的墨迹数据。", "提示",
MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// 创建文件保存对话框
var saveFileDialog = new Microsoft.Win32.SaveFileDialog
{
// 默认文件名
FileName = "课件墨迹.ink.json",
// 文件过滤器
Filter = "墨迹 JSON 文件 (*.ink.json)|*.ink.json|所有文件 (*.*)|*.*",
// 默认扩展名
DefaultExt = ".ink.json",
// 对话框标题
Title = "导出墨迹",
};
// 显示保存对话框
if (saveFileDialog.ShowDialog() == true)
{
// 使用 Newtonsoft.Json 将墨迹数据序列化为格式化的 JSON 字符串
string json = JsonConvert.SerializeObject(inkData, Formatting.Indented);
// 写入文件
File.WriteAllText(saveFileDialog.FileName, json);
}
});
}
}
}