From 8bc9f98b1b7d180da84d51cf6a81ba9b6ac8dc24 Mon Sep 17 00:00:00 2001 From: Huoxing-Rusty <220455872+Huoxing-Rusty@users.noreply.github.com> Date: Tue, 17 Nov 2026 00:12:34 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A2=A8=E8=BF=B9?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=89=93=E5=BC=80=E4=BD=8D=E7=BD=AE=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E4=B8=8E=E5=8F=AF=E6=92=A4=E9=94=80=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/Helpers/FileAssociationManager.cs | 5 +- Ink Canvas/MainWindow.xaml.cs | 3 +- Ink Canvas/MainWindow_cs/MW_StrokeFileOpen.cs | 92 ++++++++ Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs | 4 +- .../Properties/MainWindowStrings.Designer.cs | 24 ++ .../Properties/MainWindowStrings.en-US.resx | 36 +++ Ink Canvas/Properties/MainWindowStrings.resx | 36 +++ .../Properties/MainWindowStrings.zh-ME.resx | 36 +++ Ink Canvas/Windows/StrokeFileOpenWindow.xaml | 74 ++++++ .../Windows/StrokeFileOpenWindow.xaml.cs | 27 +++ InkCanvas.Calibration.Tests/Program.cs | 5 +- .../StrokeFileOpenTests.cs | 212 ++++++++++++++++++ 12 files changed, 545 insertions(+), 9 deletions(-) create mode 100644 Ink Canvas/MainWindow_cs/MW_StrokeFileOpen.cs create mode 100644 Ink Canvas/Windows/StrokeFileOpenWindow.xaml create mode 100644 Ink Canvas/Windows/StrokeFileOpenWindow.xaml.cs create mode 100644 InkCanvas.Calibration.Tests/StrokeFileOpenTests.cs diff --git a/Ink Canvas/Helpers/FileAssociationManager.cs b/Ink Canvas/Helpers/FileAssociationManager.cs index 0af321501..223f8bb6f 100644 --- a/Ink Canvas/Helpers/FileAssociationManager.cs +++ b/Ink Canvas/Helpers/FileAssociationManager.cs @@ -872,8 +872,7 @@ private static void ProcessIpcFiles() // 获取主窗口并打开文件 if (Application.Current.MainWindow is MainWindow mainWindow) { - mainWindow.OpenSingleStrokeFile(filePath); - mainWindow.ShowNotification(string.Format(AutomationStrings.FileAssoc_LoadedStrokesFile, Path.GetFileName(filePath))); + mainWindow.OpenStrokeFileFromShell(filePath); } } catch (Exception ex) @@ -1111,4 +1110,4 @@ private static void ProcessIpcFiles() //[DllImport("shell32.dll")] //private static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2); } -} \ No newline at end of file +} diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index 97d7886bd..6447fc876 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -3561,8 +3561,7 @@ private void HandleCommandLineFileOpen() try { // 打开文件 - OpenSingleStrokeFile(icstkFile); - ShowNotification(string.Format(Properties.MainWindowStrings.Main_StrokesFileLoaded, Path.GetFileName(icstkFile))); + OpenStrokeFileFromShell(icstkFile); } catch (Exception ex) { diff --git a/Ink Canvas/MainWindow_cs/MW_StrokeFileOpen.cs b/Ink Canvas/MainWindow_cs/MW_StrokeFileOpen.cs new file mode 100644 index 000000000..ebd07a37e --- /dev/null +++ b/Ink Canvas/MainWindow_cs/MW_StrokeFileOpen.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Windows; +using System.Windows.Ink; +using System.Windows.Media; +using Ink_Canvas.Helpers; +using Ink_Canvas.Properties; +using Ink_Canvas.Windows; + +namespace Ink_Canvas +{ + public partial class MainWindow + { + private readonly Queue pendingStrokeFiles = new Queue(); + private bool isOpeningStrokeFile; + + // 冷启动与 IPC 共用此入口;模态窗口的消息循环仍会收到 IPC,按顺序处理,避免叠放弹窗。 + public void OpenStrokeFileFromShell(string filePath) + { + pendingStrokeFiles.Enqueue(filePath); + if (isOpeningStrokeFile) return; + isOpeningStrokeFile = true; + try + { + while (pendingStrokeFiles.Count > 0) + { + var path = pendingStrokeFiles.Dequeue(); + try + { + var dialog = new StrokeFileOpenWindow(path) { Owner = MessageBoxHelper.GetDefaultOwner(this) }; + if (dialog.Owner == null) dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; + if (dialog.ShowDialog() == true && ImportStrokeFile(path, dialog.SelectedTarget)) + ShowNotification(string.Format(MainWindowStrings.Main_StrokesFileLoaded, Path.GetFileName(path))); + } + catch (Exception ex) + { + LogHelper.WriteLogToFile($"打开外部墨迹文件失败: {ex}", LogHelper.LogType.Error); + ShowNotification(ex is InvalidDataException || ex is InvalidOperationException + ? ex.Message : MainWindowStrings.Main_StrokesFileOpenFailed); + } + } + } + finally + { + isOpeningStrokeFile = false; + } + } + + internal bool ImportStrokeFile(string filePath, StrokeFileOpenTarget? target) + { + if (!target.HasValue) return false; + + // 在切换模式之前读完并校验,损坏、空文件不会改变当前画布。 + StrokeCollection strokes; + using (var stream = File.OpenRead(filePath)) strokes = new StrokeCollection(stream); + if (strokes.Count == 0) throw new InvalidDataException(MainWindowStrings.Main_OpenInk_Empty); + int targetMode = target == StrokeFileOpenTarget.Screen ? 0 : 1; + if (IsPageFrozen(targetMode == 0 ? 0 : CurrentWhiteboardIndex)) + throw new InvalidOperationException(MainWindowStrings.Main_Freeze_FrozenNoEdit); + if (isDisplayingOrHidingBlackboard) + throw new InvalidOperationException(MainWindowStrings.Main_OpenInk_ModeBusy); + + if (target == StrokeFileOpenTarget.Booth) + { + // 已在照片页时不重新进入展台,保留当前照片及其变换。 + if (!_isVideoPresenterSpecialMode) ToggleVideoBooth(); + } + else + { + if (_isVideoPresenterSpecialMode) + { + // 先保存展台状态并恢复白板,再向目标页面追加文件。 + ExitVideoPresenterSpecialMode(); + CloseVideoPresenterSidebarAndReleaseResources(); + GridBackgroundCover.Visibility = Visibility.Visible; + } + if (currentMode != targetMode) ImageBlackboard_MouseUp(null, null); + if (target == StrokeFileOpenTarget.Screen && GridTransparencyFakeBackground.Background == Brushes.Transparent) + BtnHideInkCanvas_Click(null, null); + } + + if (currentMode != targetMode || (target == StrokeFileOpenTarget.Booth && !_isVideoPresenterSpecialMode)) + throw new InvalidOperationException(MainWindowStrings.Main_OpenInk_ModeBusy); + + // 复用批量插入:保留已有元素和历史,即使当前是点橡皮也只生成一条撤销记录。 + if (!TryAddPluginStrokes(strokes, null)) return false; + MarkCurrentPageInkChanged(); + return true; + } + } +} diff --git a/Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs b/Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs index c2010cd68..a39faea02 100644 --- a/Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs +++ b/Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs @@ -733,6 +733,8 @@ private void EnterVideoPresenterSpecialMode() private void ExitVideoPresenterSpecialMode() { if (!_isVideoPresenterSpecialMode) return; + // 保存方法依赖展台模式标志,必须在退出模式前调用。 + SaveCurrentBoothState(); _isVideoPresenterSpecialMode = false; // 退出展台后恢复双指旋转开关 SetBoothGestureRotationUiEnabled(true); @@ -740,8 +742,6 @@ private void ExitVideoPresenterSpecialMode() _boothPreviewRestartRetryCount = 0; LogHelper.WriteLogToFile("[Booth] 退出视频展台拍摄模式,保留拍摄态墨迹、缩放位置与旋转状态", LogHelper.LogType.Info); - // 退出前完整保存当前展台页面状态(墨迹、缩放、位移、旋转、最后查看页码) - SaveCurrentBoothState(); // 停止 A4 纸实时识别定时器并隐藏覆盖层 StopPaperDetectTimer(); diff --git a/Ink Canvas/Properties/MainWindowStrings.Designer.cs b/Ink Canvas/Properties/MainWindowStrings.Designer.cs index 4fa517b27..25d27040b 100644 --- a/Ink Canvas/Properties/MainWindowStrings.Designer.cs +++ b/Ink Canvas/Properties/MainWindowStrings.Designer.cs @@ -413,5 +413,29 @@ public static string GetString(string key) public static string Main_ExitVerifyWithTotp => ResourceManager.GetString(nameof(Main_ExitVerifyWithTotp), _resourceCulture); public static string Main_ExitVerifyPasswordOnly => ResourceManager.GetString(nameof(Main_ExitVerifyPasswordOnly), _resourceCulture); + public static string Main_OpenInk_Title => ResourceManager.GetString(nameof(Main_OpenInk_Title), _resourceCulture); + + public static string Main_OpenInk_ChooseDestination => ResourceManager.GetString(nameof(Main_OpenInk_ChooseDestination), _resourceCulture); + + public static string Main_OpenInk_Screen => ResourceManager.GetString(nameof(Main_OpenInk_Screen), _resourceCulture); + + public static string Main_OpenInk_ScreenDescription => ResourceManager.GetString(nameof(Main_OpenInk_ScreenDescription), _resourceCulture); + + public static string Main_OpenInk_Whiteboard => ResourceManager.GetString(nameof(Main_OpenInk_Whiteboard), _resourceCulture); + + public static string Main_OpenInk_WhiteboardDescription => ResourceManager.GetString(nameof(Main_OpenInk_WhiteboardDescription), _resourceCulture); + + public static string Main_OpenInk_Booth => ResourceManager.GetString(nameof(Main_OpenInk_Booth), _resourceCulture); + + public static string Main_OpenInk_BoothDescription => ResourceManager.GetString(nameof(Main_OpenInk_BoothDescription), _resourceCulture); + + public static string Main_OpenInk_AppendHint => ResourceManager.GetString(nameof(Main_OpenInk_AppendHint), _resourceCulture); + + public static string Main_OpenInk_Cancel => ResourceManager.GetString(nameof(Main_OpenInk_Cancel), _resourceCulture); + + public static string Main_OpenInk_Empty => ResourceManager.GetString(nameof(Main_OpenInk_Empty), _resourceCulture); + + public static string Main_OpenInk_ModeBusy => ResourceManager.GetString(nameof(Main_OpenInk_ModeBusy), _resourceCulture); + } } diff --git a/Ink Canvas/Properties/MainWindowStrings.en-US.resx b/Ink Canvas/Properties/MainWindowStrings.en-US.resx index 0865e664a..2b06dfc84 100644 --- a/Ink Canvas/Properties/MainWindowStrings.en-US.resx +++ b/Ink Canvas/Properties/MainWindowStrings.en-US.resx @@ -748,4 +748,40 @@ Please check if the update was successful. Sorry, an unexpected error occurred that may cause InkCanvasForClass to run unstably. It is recommended to save your ink and restart the application. + + Open ink file + + + Choose where to open + + + Screen annotation + + + Continue annotating on your screen + + + Whiteboard + + + Add ink to the current whiteboard page + + + Document camera + + + Overlay ink on the current photo or live view + + + Ink will be added to the current page. You can undo this. + + + Cancel + + + This file contains no ink to import. + + + A mode change is in progress. Please open the file again shortly. + \ No newline at end of file diff --git a/Ink Canvas/Properties/MainWindowStrings.resx b/Ink Canvas/Properties/MainWindowStrings.resx index 4e561f8be..775dc94d7 100644 --- a/Ink Canvas/Properties/MainWindowStrings.resx +++ b/Ink Canvas/Properties/MainWindowStrings.resx @@ -748,4 +748,40 @@ 请输入安全密码以退出软件。 + + 打开墨迹文件 + + + 选择打开位置 + + + 屏幕批注 + + + 在屏幕上继续批注 + + + 白板 + + + 添加到当前白板页面 + + + 展台 + + + 叠加到当前照片或实时画面 + + + 墨迹将添加到当前页面,可撤销。 + + + 取消 + + + 此文件不包含可导入的墨迹。 + + + 正在切换模式,请稍后重新打开文件。 + \ No newline at end of file diff --git a/Ink Canvas/Properties/MainWindowStrings.zh-ME.resx b/Ink Canvas/Properties/MainWindowStrings.zh-ME.resx index 00c97f7b1..3c128f7c6 100644 --- a/Ink Canvas/Properties/MainWindowStrings.zh-ME.resx +++ b/Ink Canvas/Properties/MainWindowStrings.zh-ME.resx @@ -745,4 +745,40 @@ 哎呀出意外了,InkCanvasForClass 可能要寄了。 建议赶紧存墨迹然后复活保平安。 + + 打开墨迹文件 + + + 选择打开位置 + + + 屏幕批注 + + + 在屏幕上继续批注 + + + 白板 + + + 添加到当前白板页面 + + + 展台 + + + 叠加到当前照片或实时画面 + + + 墨迹将添加到当前页面,可撤销。 + + + 取消 + + + 此文件不包含可导入的墨迹。 + + + 正在切换模式,请稍后重新打开文件。 + diff --git a/Ink Canvas/Windows/StrokeFileOpenWindow.xaml b/Ink Canvas/Windows/StrokeFileOpenWindow.xaml new file mode 100644 index 000000000..dcbd964bb --- /dev/null +++ b/Ink Canvas/Windows/StrokeFileOpenWindow.xaml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +