Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #748
插件此前无法向宿主工具栏「打开」按钮的文件对话框注册自己的可打开格式,插件想打开自有格式只能另弹自己的对话框(issue 里说的「劫持对话框」),多个插件之间还会互相冲突。
根因
SymbolIconOpenStrokes_MouseUp(Ink Canvas/MainWindow_cs/MW_Save&OpenStrokes.cs:1362)的筛选器直接取写死的资源字符串Main_Strokes_OpenFileDialogFilter(仅.icstk/.xml/.zip/.uink),没有任何插件扩展点;打开后又只按扩展名分派宿主内置格式,其余一律落到OpenSingleStrokeFile。同时未设置FilterIndex,而「所有支持的文件」排在最后一项,默认筛选项是*.icstk,与「默认显示全部支持格式」的预期也不一致。改动说明
IOpenFileFormatService(InkCanvas.PluginSdk/IOpenFileFormatService.cs):RegisterFormat(string groupName, IEnumerable<string> extensions, Func<string, bool> handler),一个插件可多次调用注册多组格式;须在Initialize阶段调用(与现有RegisterService{T}约束一致,用_currentLoadingPlugin识别调用方)。HostApiRequirement.CurrentApiVersion1.13.0 → 1.14.0,插件载入时按版本校验。Ink Canvas/Plugins/PluginManager.cs:注册表 +GetOpenFormats()+RegisterOpenFormat()+TryOpenWithPluginFormat();注册通过TrackUndo挂到插件的UnloadPlugin上,卸载时自动注销;handler 抛异常或返回false时写日志并提示打开失败。Ink Canvas/Plugins/Services/OpenFileFormatService.cs:宿主服务,仅转发到PluginManager;App.xaml.cs里 DI 注册。MW_Save&OpenStrokes.cs:新增BuildOpenStrokesFilter()动态拼接筛选器(第一项「所有支持的文件」= 宿主 + 全部插件扩展名,其后为宿主各组、再后为插件各组),并设FilterIndex = 1;打开时宿主内置扩展名(HostOpenExtensions)优先走原分支,其余扩展名先尝试插件派发,无人认领时才回落到原OpenSingleStrokeFile。.icstk/.xml/.zip/.uink)不允许插件覆盖;多个插件注册同一扩展名时先注册者生效,后者的该扩展名被忽略并写 WARN;扩展名非法或全部被拒绝时注册返回false并写 WARN。MainWindowStrings三套语言资源(resx/zh-ME/en-US)新增「所有支持的文件」与「墨迹打开失败」两条,Designer.cs同步。rules/plugin_sdk.md补充IOpenFileFormatService用法与冲突规则。测试
构建(worktree 内,Debug x64):
结果:还原与构建均成功,退出码 0,无编译错误(工作树干净,无未提交改动)。
运行验证(Debug 产物直接运行,测试插件
com.jsrbot.testopenformat+ 另外两个测试插件 A/B 提供.docx/.pdf、.enb/.enbx、.failx、.abc):测试文档 (*.docx;*.pdf)、测试课件 (*.enb;*.enbx)、失败测试 (*.failx)、测试格式B (*.abc);.icstk未被插件重复列出.docx/.enb打开doc/course.abc(另一插件)false(.failx)refusing,宿主日志 WARN「插件 … 未能打开文件」,界面顶部 toast「墨迹打开失败」.icstkRegisterFormat返回false并写 WARN 拒绝.enb/.enbx/.pdf回归检查(宿主原生格式路径):
.icstk打开(批注模式).icstk保存.icstk打开(白板模式).xml/.zip/.uinkHostOpenExtensions时完全跳过插件派发,后续分支未修改;未单独准备样例手动打开OpenSingleStrokeFile,行为不变截图
筛选器(默认「所有支持的文件」+ 插件分组):
.abc派发到插件自己的窗口:handler 返回 false 时的提示:
回归:原生
.icstk在批注模式打开:回归:原生
.icstk在白板模式打开:需要确认的两点
TryBlockFrozenPageMutation冻结页检查与inkCanvas可见性切换(由插件自行决定界面状态)。如果希望宿主统一处理,请告知期望行为。🤖 本 PR 由 SuperDevBot(AI)生成,已按 CONTRIBUTING 完成构建与运行测试。