From 3a03a09a76fe7b248ccfb5a75c5aa8afe81b4867 Mon Sep 17 00:00:00 2001 From: routersys Date: Thu, 10 Sep 2026 12:39:16 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E3=81=A8=E3=83=90=E3=83=83?= =?UTF-8?q?=E3=83=81=E5=87=BA=E5=8A=9B=E3=81=AE=E5=89=8D=E3=81=AB=E3=82=82?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E6=9D=90=E3=81=B8=E6=88=BB=E3=81=99=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ExportGuard.cpp | 40 ++++++++++++++++++++++++++++++++++------ src/ScanController.cpp | 2 +- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/ExportGuard.cpp b/src/ExportGuard.cpp index ef2f153..1f7a622 100644 --- a/src/ExportGuard.cpp +++ b/src/ExportGuard.cpp @@ -19,7 +19,8 @@ const UINT_PTR kSubclassId = 0x50450003; HWND g_host = nullptr; bool g_hooked = false; UINT g_ready_message = 0; -std::set g_output_commands; +std::set g_guarded; +std::set g_final; bool g_collected = false; std::atomic g_waiting{0}; std::atomic g_passthrough{0}; @@ -73,12 +74,39 @@ bool FindOutputMenu(HMENU menu, const std::wstring& wanted, std::set& into) return false; } -void CollectOutputCommands() { +int FindCommand(HMENU menu, const std::wstring& wanted) { + const int count = GetMenuItemCount(menu); + for (int index = 0; index < count; index++) { + HMENU sub = GetSubMenu(menu, index); + if (sub) { + const int found = FindCommand(sub, wanted); + if (found > 0) return found; + continue; + } + if (LabelAt(menu, index) != wanted) continue; + const int id = GetMenuItemID(menu, index); + if (id > 0) return id; + } + return 0; +} + +void Guard(HMENU menu, const wchar_t* key, bool leaves_edit) { + const int id = FindCommand(menu, MenuName(key)); + if (id <= 0) return; + g_guarded.insert(id); + if (leaves_edit) g_final.insert(id); +} + +void CollectCommands() { if (g_collected) return; HMENU menu = GetMenu(g_host); if (!menu) return; g_collected = true; - FindOutputMenu(menu, MenuName(L"ファイル出力"), g_output_commands); + FindOutputMenu(menu, MenuName(L"ファイル出力"), g_guarded); + Guard(menu, L"バッチ出力", false); + Guard(menu, L"プロジェクトを保存", false); + Guard(menu, L"プロジェクトを別名で保存", false); + Guard(menu, L"プロジェクトを保存して終了", true); } LRESULT CALLBACK GuardProc(HWND window, UINT message, WPARAM first, LPARAM second, UINT_PTR, @@ -92,13 +120,13 @@ LRESULT CALLBACK GuardProc(HWND window, UINT message, WPARAM first, LPARAM secon return 0; } if (message == WM_COMMAND && second == 0 && HIWORD(first) <= 1) { - CollectOutputCommands(); + CollectCommands(); const int id = (int)LOWORD(first); - if (g_output_commands.count(id) > 0) { + if (g_guarded.count(id) > 0) { if (g_passthrough.load() == id) { g_passthrough.store(0); LRESULT result = DefSubclassProc(window, message, first, second); - if (EditState() == EDIT_HANDLE::EDIT_STATE_EDIT) { + if (g_final.count(id) == 0 && EditState() == EDIT_HANDLE::EDIT_STATE_EDIT) { SuspendAutomaticScan(false); if (g_restored.exchange(false)) RequestApply(); } diff --git a/src/ScanController.cpp b/src/ScanController.cpp index 91b2905..01e4d17 100644 --- a/src/ScanController.cpp +++ b/src/ScanController.cpp @@ -310,7 +310,7 @@ void ScanWorker() { if (taken & kRequestExportRestore) { ScanResult result = RestoreOriginals(); if (result.restored > 0) { - Say(L"出力のため元素材へ戻しました: %d 件", result.restored); + Say(L"一時的に元素材へ戻しました: %d 件", result.restored); } PublishStateChange(); ExportRestoreFinished(result.restored > 0);