diff --git a/CMakeLists.txt b/CMakeLists.txt index 61fc320..e30a7bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.24) -project(KSwitcher VERSION 0.6.71 LANGUAGES CXX RC) +project(KSwitcher VERSION 0.6.72 LANGUAGES CXX RC) if(NOT WIN32) message(FATAL_ERROR "KSwitcher uses native Windows APIs") endif() diff --git a/LAN-PREVIEW.md b/LAN-PREVIEW.md index bc7b0f8..aa767ed 100644 --- a/LAN-PREVIEW.md +++ b/LAN-PREVIEW.md @@ -11,7 +11,7 @@ is not implemented by clipboard synchronization. ## Set up multiple computers 1. Install the v0.6.58 or newer on every participating PC. Input protocol v2 requires all participants to update; earlier one-pair builds cannot connect. Preserve local data; do not copy pairing identities between PCs. -2. Open Settings → Tools → KSwitcher computers and enable discovery on both PCs. +2. Open **Settings → Computers → Manage computers…** and enable discovery on both PCs. Only running LAN-enabled KSwitcher instances appear, not generic network devices. 3. Match the computer name and instance-ID prefix displayed on the other PC. Select each other, generate one code, enter that same code on both, then click diff --git a/README.md b/README.md index 43bb63c..9ee63e5 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,15 @@ The original [Typlo](https://github.com/bitcodepro/Typlo) project and its data r **[User guide / Wiki](https://gitea.hrynco.com/hrynco/hrynco-kswitcher/wiki)** — setup, features, shortcuts, dictionaries, screenshots and troubleshooting in **English** and **[Українська](https://gitea.hrynco.com/hrynco/hrynco-kswitcher/wiki/Home-uk)**. Each wiki page links to its translation. +From v0.6.72, use **Settings → Snippets** to edit snippets in place and +**Save snippets** to save them independently. **Clipboard** contains OCR +options. **Sync**, **Computers**, and **Diagnostics** have their own tabs. + +**Українською.** З v0.6.72 сніпети редагуються у **Settings → Snippets** +і зберігаються окремою кнопкою **Save snippets**. OCR розміщено у +**Clipboard**, а для синхронізації, ПК та журналу є окремі вкладки +**Sync**, **Computers** і **Diagnostics**. + [![Support KSwitcher development — buy the developer a coffee](resources/support/donate-en.png)](https://send.monobank.ua/jar/88h2TddKfS) [Donate via Monobank](https://send.monobank.ua/jar/88h2TddKfS) · Thank you for supporting KSwitcher. @@ -477,13 +486,13 @@ ChatGPT and Codex desktop editors use paced selection for snippet triggers. If o ### Application-specific snippets — v0.6.51 -In **Tools → Snippets**, select a snippet and enable **Only in these applications**. Enter executable names separated by commas, or select a currently open application's process and choose **Add app**. For example: `ms-teams.exe, outlook.exe`. Uncheck the option for a global snippet. A checked but empty restriction cannot be saved. Save applies the changes; Cancel discards them. +In **Settings → Snippets**, select a snippet and enable **Only in these applications**. Enter executable names separated by commas, or select a currently open application's process and choose **Add app**. For example: `ms-teams.exe, outlook.exe`. Uncheck the option for a global snippet. A checked but empty restriction cannot be saved. Use **Save snippets** to apply the changes. A matching application-specific snippet takes precedence over a global snippet with the same trigger. The same trigger can be used for different applications; overlapping scopes for the same trigger are rejected. Existing snippets without a scope remain global. Matching is case-insensitive by process name, with or without `.exe`, and is checked before insertion. No OCR or timer is involved. Chrome scope means the entire browser, not one website. Scopes are saved with snippets and included in manual import/export and synchronization; merge conflicts consider the application scopes. Use v0.6.51 or newer on every synchronizing PC before sharing scoped snippets: older versions do not understand the restriction and may treat the snippet as global. -**Українською.** У **Tools → Snippets** вибери сніпет, увімкни **Only in these applications** та задай назви процесів через кому або вибери відкриту програму зі списку й натисни **Add app**. Наприклад: `ms-teams.exe, outlook.exe`. Вимкнений прапорець означає всі програми. Увімкнений прапорець із порожнім списком не можна зберегти. **Save** зберігає, **Cancel** відкидає зміни. +**Українською.** У **Settings → Snippets** вибери сніпет, увімкни **Only in these applications** та задай назви процесів через кому або вибери відкриту програму зі списку й натисни **Add app**. Наприклад: `ms-teams.exe, outlook.exe`. Вимкнений прапорець означає всі програми. Увімкнений прапорець із порожнім списком не можна зберегти. Натисни **Save snippets**, щоб застосувати зміни. Сніпет конкретної програми має пріоритет над глобальним із тим самим тригером. Для різних програм однакові тригери дозволені, для перетинних областей — ні. Старі сніпети залишаються глобальними. Зіставлення за назвою процесу не залежить від регістру та суфікса `.exe`; OCR і таймерів немає. Для Chrome це весь браузер, а не окремий сайт. Обмеження входять до експорту/імпорту та синхронізації. Перед синхронізацією онови всі ПК до v0.6.51 або новішої: старі версії не розуміють обмеження та можуть застосувати сніпет глобально. ### Existing features diff --git a/Release/KSwitcher-win-x64.zip b/Release/KSwitcher-win-x64.zip index f723518..5eca507 100644 Binary files a/Release/KSwitcher-win-x64.zip and b/Release/KSwitcher-win-x64.zip differ diff --git a/Release/README.md b/Release/README.md index ffacd6d..42279a7 100644 --- a/Release/README.md +++ b/Release/README.md @@ -1,5 +1,17 @@ # Latest Windows release +## v0.6.72 — 2026-11-12 + +Edit snippets directly in **Settings → Snippets**. **Save snippets** applies +snippet edits independently of the settings draft. Find OCR options in +**Clipboard** and open backup and synchronization, paired computers, and +logging from **Sync**, **Computers**, and **Diagnostics**, respectively. + +**Українською.** Редагуйте сніпети безпосередньо у **Settings → Snippets**. +Кнопка **Save snippets** зберігає їх окремо від чернетки налаштувань. +Параметри OCR тепер у **Clipboard**. Для синхронізації, спарених ПК та +журналу є вкладки **Sync**, **Computers** і **Diagnostics**. + ## v0.6.71 — 2026-11-12 After navigating snippet suggestions with **↑ / ↓**, press **Enter** to diff --git a/Release/SHA256SUMS.txt b/Release/SHA256SUMS.txt index 10d91c4..31b70f7 100644 --- a/Release/SHA256SUMS.txt +++ b/Release/SHA256SUMS.txt @@ -1 +1 @@ -42390860144e0b3a2b32874500ab9de8de60b76715cc583d306f761a749a83e9 KSwitcher-win-x64.zip +4b694cdc1d32da0623bb3372b0c04d438f70c427baac1ef831b94c8f492df8d0 KSwitcher-win-x64.zip diff --git a/Release/release-files.json b/Release/release-files.json index effa17d..53d1242 100644 --- a/Release/release-files.json +++ b/Release/release-files.json @@ -1,86 +1,86 @@ { - "version": "0.6.71", + "schema": 1, + "version": "0.6.72", "files": [ { "size": 2202624, - "path": "KSwitcher.exe", - "sha256": "fc85390dcc0a46c8cd10daad77482de4f374f9f61b4b4adee1a9ca022d17e4f8" + "sha256": "59b7072ac1cb0e7e138fc89b5cf3776a5affee47cb374c1f825411a71742f6fe", + "path": "KSwitcher.exe" }, { - "size": 2129408, - "path": "KSwitcher.Config.exe", - "sha256": "371c9bf2673049e52f432457a929173f5e5a2a91d1e9dc3e96ef8a2c4699e628" + "size": 2130432, + "sha256": "1cab608710db9de62ef7726a7cca30e1284377871fce9674a4815399bb2f0211", + "path": "KSwitcher.Config.exe" }, { "size": 3210240, - "path": "KSwitcher.Screenshot.exe", - "sha256": "bbcfed4d697c9053ff6ad828289805cd6d5f20b4c3d29027b4d26317b973f725" + "sha256": "235afacecc4282baf3388aaecd2a217ae7fbf1aa5800e5193c6552461df30c1f", + "path": "KSwitcher.Screenshot.exe" }, { "size": 4401, - "path": "LICENSE", - "sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c" + "sha256": "d3c81140cce01c26bf6cbf52aa40e0825e1fa35b9a91d1387170a65d2597082c", + "path": "LICENSE" }, { "size": 1075, - "path": "json-LICENSE.txt", - "sha256": "c0d068392ea65358b798b8c165103560f06e9e3b38c4ab4e2d8810a7b931af86" + "sha256": "c0d068392ea65358b798b8c165103560f06e9e3b38c4ab4e2d8810a7b931af86", + "path": "json-LICENSE.txt" }, { - "size": 92710, - "path": "README.md", - "sha256": "3d475635e3190c80dbf499bb06cb0c082c16c8977d735e21e8f658cc8fc2bc51" + "size": 93316, + "sha256": "7475381edfe686f03f08d197d54db34ac12a51bd477cd3b65a57fda32c7852e0", + "path": "README.md" }, { - "size": 9900, - "path": "LAN-PREVIEW.md", - "sha256": "6dcb0efabec6898965bbbd31ba68e06276fd0f098ac9a8649bc1f7d7de21d63e" + "size": 9908, + "sha256": "4a673e44dc42fff45ba8b944413b5b5adddca7100c7eccd1c5010dccc5762e41", + "path": "LAN-PREVIEW.md" }, { "size": 682867, - "path": "dictionaries/en.txt", - "sha256": "5f267c141c3d6837870e1c098f86b89a113ba300343119432644ead88f720c21" + "sha256": "5f267c141c3d6837870e1c098f86b89a113ba300343119432644ead88f720c21", + "path": "dictionaries/en.txt" }, { "size": 20138, - "path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt", - "sha256": "28a9529c7d0bb4dc51f4bf5c116a3d16ef247a052f7591466768ddf563fd1cf5" + "sha256": "28a9529c7d0bb4dc51f4bf5c116a3d16ef247a052f7591466768ddf563fd1cf5", + "path": "dictionaries/LICENSE-CC-BY-SA-4.0.txt" }, { "size": 2230, - "path": "dictionaries/README.md", - "sha256": "2df17fe4e17d527c67ab57269b07dce59a49c1fb128c429a1408decbb47109ec" + "sha256": "2df17fe4e17d527c67ab57269b07dce59a49c1fb128c429a1408decbb47109ec", + "path": "dictionaries/README.md" }, { "size": 1060364, - "path": "dictionaries/ru.txt", - "sha256": "9ef922c7699569304a428f6aba0fd13a21341c0d0cb9561f37ef83c41577a28b" + "sha256": "9ef922c7699569304a428f6aba0fd13a21341c0d0cb9561f37ef83c41577a28b", + "path": "dictionaries/ru.txt" }, { "size": 1279, - "path": "dictionaries/sources.json", - "sha256": "d6e11a3aaba22a8a7eaba19f778d8a5bd66653ff306810e85a1b0e7fff3a6b86" + "sha256": "d6e11a3aaba22a8a7eaba19f778d8a5bd66653ff306810e85a1b0e7fff3a6b86", + "path": "dictionaries/sources.json" }, { "size": 898248, - "path": "dictionaries/uk.txt", - "sha256": "caeb097749d4afc84b68ad96b3d7dfb6a6569561cd32ccce0bee94a13b43ba86" + "sha256": "caeb097749d4afc84b68ad96b3d7dfb6a6569561cd32ccce0bee94a13b43ba86", + "path": "dictionaries/uk.txt" }, { "size": 993, - "path": "tools/README.txt", - "sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a" + "sha256": "a34b5161a8315af037e1ec71d816bfc688f7c364141d4ee2347cf0515ef0c82a", + "path": "tools/README.txt" }, { "size": 134656, - "path": "tools/StayHere.exe", - "sha256": "6ef5cf64708d62b7fc63c3c793cc99188a513433ff4774cae01dc014f6664376" + "sha256": "6ef5cf64708d62b7fc63c3c793cc99188a513433ff4774cae01dc014f6664376", + "path": "tools/StayHere.exe" }, { "size": 2796, - "path": "tools/StayHere-README.md", - "sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413" + "sha256": "ba214e2aca7405e698b3ab21ceb1f41ce088edd996b3e30e4a9d58ff496f9413", + "path": "tools/StayHere-README.md" } - ], - "schema": 1 + ] } diff --git a/resources/app.rc b/resources/app.rc index cb844e8..e963dcd 100644 --- a/resources/app.rc +++ b/resources/app.rc @@ -9,8 +9,8 @@ IDC_SCREENSHOT_PENCIL CURSOR "icons/lucide/pencil.cur" 1 RT_MANIFEST "app.manifest" 201 RCDATA "update.ps1" 1 VERSIONINFO - FILEVERSION 0,6,71,0 - PRODUCTVERSION 0,6,71,0 + FILEVERSION 0,6,72,0 + PRODUCTVERSION 0,6,72,0 FILEOS VOS_NT_WINDOWS32 FILETYPE VFT_APP BEGIN @@ -20,7 +20,7 @@ BEGIN BEGIN VALUE "FileDescription", "KSwitcher — native keyboard and clipboard utility" VALUE "ProductName", "KSwitcher" - VALUE "FileVersion", "0.6.71" + VALUE "FileVersion", "0.6.72" END END BLOCK "VarFileInfo" diff --git a/src/ui.cpp b/src/ui.cpp index 37057c9..d50b5bd 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1087,6 +1087,13 @@ LRESULT CALLBACK historyProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) #endif #ifndef KS_RESIDENT_APP +constexpr int SnippetsPage = 4, SaveSnippets = 318; +struct SnippetView +{ + App *app{}; + std::vector snippets, saved; + int selection = -1; +}; struct SettingsView { App *app{}; @@ -1099,7 +1106,11 @@ struct SettingsView std::vector mouseProfiles; unsigned mouseEvents{}, rawMouseEvents{}; bool rawMouseRegistered{}; + SnippetView snippets; }; +bool snippetCommand(HWND, SnippetView *, WPARAM, bool embedded); +bool confirmSnippetClose(HWND, SnippetView *); +void refreshSnippetDraft(HWND, SnippetView *); void updateSettingsState(HWND w, SettingsView *v); void selectSettingsPage(HWND w, SettingsView *v) { @@ -1701,8 +1712,8 @@ void updateSettingsState(HWND w, SettingsView *v) v->refreshing = true; bool changed = settingsChanged(w, v); EnableWindow(GetDlgItem(w, IDOK), changed); - const wchar_t *text = changed ? L"Unsaved changes — click Save to apply." : - v->visitedLan ? L"No unsaved settings. Network changes save automatically in the Computers window." : L"No unsaved changes."; + const wchar_t *text = changed ? L"Unsaved settings — click Save to apply." : + v->visitedLan ? L"No unsaved settings. Network changes save automatically in the Computers window." : L"No unsaved settings."; if (value(w, 261) != text) value(w, 261, text); v->refreshing = false; } @@ -1742,7 +1753,8 @@ void closeSettings(HWND w, SettingsView *v) } } } - DestroyWindow(w); + if (confirmSnippetClose(w, &v->snippets)) + DestroyWindow(w); } LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) { @@ -1778,6 +1790,7 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) case ConfigSettingsDownloaded: v->draft = v->app->settings; fillSettings(w, v); + refreshSnippetDraft(w, &v->snippets); return 0; case WM_ENABLE: if (wp) updateSettingsState(w, v); @@ -1814,6 +1827,8 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) { SettingsStateRefresh refresh{w}; int id = LOWORD(wp); + if (id >= 301 && id <= SaveSnippets && snippetCommand(w, &v->snippets, wp, true)) + return 0; if (id == 220 && HIWORD(wp) == LBN_SELCHANGE && !v->filling) { collectLayout(w, v); @@ -1852,6 +1867,7 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) if (id == IDOK) { if (!settingsChanged(w, v)) return 0; + if (!confirmSnippetClose(w, &v->snippets)) return 0; if (v->app->busy) throw std::runtime_error("Wait for the current text operation to finish"); v->app->applySettings(collectSettings(w, v)); @@ -1886,11 +1902,6 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) showAutoOptions(w, v); return 0; } - if (id == 252) - { - showSnippets(*v->app); - return 0; - } if (id == 253) { if (v->app->busy) @@ -1927,12 +1938,6 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) } return DefWindowProcW(w, msg, wp, lp); } -struct SnippetView -{ - App *app; - std::vector snippets; - int selection = -1; -}; void updateSnippetEditor(HWND w, SnippetView *v) { bool selected = v->selection >= 0 && v->selection < (int)v->snippets.size(); @@ -1985,6 +1990,168 @@ void collectSnippet(HWND w, SnippetView *v) } } } +bool sameSnippets(const std::vector &left, const std::vector &right) +{ + return std::equal(left.begin(), left.end(), right.begin(), right.end(), [](const Snippet &a, const Snippet &b) { + return a.id == b.id && a.trigger == b.trigger && a.text == b.text && a.apps == b.apps; + }); +} +void refreshSnippetDraft(HWND w, SnippetView *v) +{ + collectSnippet(w, v); + if (!sameSnippets(v->snippets, v->saved) || sameSnippets(v->saved, v->app->settings.snippets)) + return; + v->snippets = v->saved = v->app->settings.snippets; + v->selection = -1; + fillSnippets(w, v); + value(w, 319, L""); +} +void saveSnippetDraft(HWND w, SnippetView *v) +{ + collectSnippet(w, v); + if (sameSnippets(v->snippets, v->saved)) return; + auto settings = v->app->settings; + if (v->app->busy) + throw std::runtime_error("Wait for the current operation"); + if (!sameSnippets(settings.snippets, v->saved) && !sameSnippets(settings.snippets, v->snippets)) + throw std::runtime_error("Snippets changed elsewhere. Reopen Settings to load the current snippets."); + settings.snippets = v->snippets; + v->app->applySettings(settings); + v->snippets = v->saved = v->app->settings.snippets; + if (v->selection >= (int)v->snippets.size()) v->selection = -1; + if (auto parent = v->app->settingsWindow) + { + auto *view = reinterpret_cast(GetWindowLongPtrW(parent, GWLP_USERDATA)); + view->draft.snippets = v->saved; + view->draft.snippetTombstones = v->app->settings.snippetTombstones; + updateSettingsState(parent, view); + } +} +bool confirmSnippetClose(HWND w, SnippetView *v) +{ + collectSnippet(w, v); + if (sameSnippets(v->snippets, v->saved)) return true; + const int choice = MessageBoxW(w, L"Save your snippet changes before closing?", + L"KSwitcher — Unsaved snippets", MB_YESNOCANCEL | MB_ICONWARNING | MB_DEFBUTTON3); + if (choice == IDYES) saveSnippetDraft(w, v); + return choice == IDYES || choice == IDNO; +} +bool snippetCommand(HWND w, SnippetView *v, WPARAM wp, bool embedded) +{ + const int id = LOWORD(wp); + if (embedded && ((HIWORD(wp) == EN_CHANGE && (id == 302 || id == 303 || id == 315)) || + id == 310 || id == 311 || id == 314)) + value(w, 319, L""); + if (id == 314) + { + bool restricted = IsDlgButtonChecked(w, 314) == BST_CHECKED; + for (int field : {315, 316, 317}) EnableWindow(GetDlgItem(w, field), restricted); + return true; + } + if (id == 317) + { + auto app = value(w, 316); + if (!app.empty()) + { + auto current = value(w, 315); + std::wistringstream input(current); std::wstring entry; + while (std::getline(input, entry, L',')) if (snippetAppName(entry) == snippetAppName(app)) return true; + value(w, 315, current.empty() ? app : current + L", " + app); + } + return true; + } + if (id == 301 && HIWORD(wp) == LBN_SELCHANGE) + { + collectSnippet(w, v); + v->selection = (int)SendDlgItemMessageW(w, 301, LB_GETCURSEL, 0, 0); + updateSnippetEditor(w, v); + return true; + } + if (id == 310) + { + collectSnippet(w, v); + v->snippets.push_back({L";new", L"", newSnippetId()}); + v->selection = (int)v->snippets.size() - 1; + fillSnippets(w, v); + SetFocus(GetDlgItem(w, 302)); + return true; + } + if (id == 311) + { + if (v->selection >= 0) + { + v->snippets.erase(v->snippets.begin() + v->selection); + v->selection = -1; + fillSnippets(w, v); + SetFocus(GetDlgItem(w, 301)); + } + return true; + } + if (id == 312 || id == 313) + { + if (v->selection < 0 || v->selection >= (int)v->snippets.size()) return true; + SendDlgItemMessageW(w, 303, EM_REPLACESEL, TRUE, (LPARAM)(id == 312 ? L"{cursor}" : L"{enter}")); + return true; + } + if (id == (embedded ? SaveSnippets : IDOK)) + { + saveSnippetDraft(w, v); + if (embedded) + { + fillSnippets(w, v); + value(w, 319, L"Snippets saved."); + } + else DestroyWindow(w); + return true; + } + if (!embedded && id == IDCANCEL) + { + DestroyWindow(w); + return true; + } + return false; +} +void createSnippetEditor(HWND w, SnippetView *view, bool embedded) +{ + const int top = embedded ? 60 : 16; + const int textHeight = embedded ? 106 : 240; + const int actions = top + 201 + textHeight; + label(w, L"Triggers", 24, top, 186); + control(w, L"LISTBOX", L"", WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_BORDER, + 301, 24, top + 24, 186, 170 + textHeight); + button(w, L"&Add", 310, 24, actions, 86); + button(w, L"&Delete", 311, 120, actions, 90); + label(w, L"&Trigger (for example ;addr)", 232, top, 452); + edit(w, 302, 232, top + 24, 452); + checkbox(w, L"Only in these &applications (unchecked: everywhere)", 314, 232, top + 55, 452); + edit(w, 315, 232, top + 83, 452); + control(w, L"COMBOBOX", L"", WS_TABSTOP | CBS_DROPDOWNLIST | WS_VSCROLL, 316, 232, top + 113, 330, 200); + button(w, L"Add a&pp", 317, 572, top + 110, 112); + label(w, L"Process names, comma-separated (for example chrome.exe)", 232, top + 144, 452); + label(w, L"&Replacement text", 232, top + 170, 452); + edit(w, 303, 232, top + 194, 452, textHeight, ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL | WS_VSCROLL); + button(w, L"Insert cursor &marker", 312, 232, actions, 190); + button(w, L"Insert &Enter marker", 313, 432, actions, 190); + if (embedded) + { + control(w, L"STATIC", L"", 0, 319, 232, actions + 35, 286, 24); + button(w, L"Sa&ve snippets", SaveSnippets, 530, actions + 30, 154); + } + else + { + control(w, L"STATIC", L"Use {{cursor}} / {{enter}} for literal markers.", 0, 0, 232, actions + 35, 452, 22); + button(w, L"&Save", IDOK, 474, actions + 65, 100); + button(w, L"&Cancel", IDCANCEL, 584, actions + 65, 100); + } + std::set apps; + EnumWindows([](HWND candidate, LPARAM context)->BOOL { + if (IsWindowVisible(candidate)) { auto name = processName(candidate); if (!name.empty()) ((std::set*)context)->insert(lower(name) + L".exe"); } + return TRUE; + }, (LPARAM)&apps); + for (const auto &name : apps) SendDlgItemMessageW(w, 316, CB_ADDSTRING, 0, (LPARAM)name.c_str()); + SendDlgItemMessageW(w, 316, CB_SETCURSEL, 0, 0); + fillSnippets(w, view); +} LRESULT CALLBACK snippetProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) { if (msg == WM_DPICHANGED) @@ -1996,102 +2163,24 @@ LRESULT CALLBACK snippetProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) if (msg == WM_NCCREATE) { auto *app = (App *)((CREATESTRUCTW *)lp)->lpCreateParams; - v = new SnippetView{app, app->settings.snippets}; + v = new SnippetView{app, app->settings.snippets, app->settings.snippets}; SetWindowLongPtrW(w, GWLP_USERDATA, (LONG_PTR)v); return TRUE; } - if (!v) - return DefWindowProcW(w, msg, wp, lp); + if (!v) return DefWindowProcW(w, msg, wp, lp); try { - switch (msg) + if (msg == WM_COMMAND && snippetCommand(w, v, wp, false)) return 0; + if (msg == WM_CLOSE) { - case WM_COMMAND: - { - int id = LOWORD(wp); - if (id == 314) - { - bool restricted = IsDlgButtonChecked(w, 314) == BST_CHECKED; - for (int field : {315, 316, 317}) EnableWindow(GetDlgItem(w, field), restricted); - return 0; - } - if (id == 317) - { - auto app = value(w, 316); - if (!app.empty()) - { - auto current = value(w, 315); - std::wistringstream input(current); std::wstring entry; - while (std::getline(input, entry, L',')) if (snippetAppName(entry) == snippetAppName(app)) return 0; - value(w, 315, current.empty() ? app : current + L", " + app); - } - return 0; - } - if (id == 301 && HIWORD(wp) == LBN_SELCHANGE) - { - collectSnippet(w, v); - v->selection = (int)SendDlgItemMessageW(w, 301, LB_GETCURSEL, 0, 0); - updateSnippetEditor(w, v); - return 0; - } - if (id == 310) - { - collectSnippet(w, v); - v->snippets.push_back({L";new", L"", newSnippetId()}); - v->selection = (int)v->snippets.size() - 1; - fillSnippets(w, v); - SetFocus(GetDlgItem(w, 302)); - return 0; - } - if (id == 311) - { - if (v->selection >= 0) - { - v->snippets.erase(v->snippets.begin() + v->selection); - v->selection = -1; - fillSnippets(w, v); - SetFocus(GetDlgItem(w, 301)); - } - return 0; - } - if (id == 312 || id == 313) - { - if (v->selection < 0 || v->selection >= (int)v->snippets.size()) return 0; - SendDlgItemMessageW(w, 303, EM_REPLACESEL, TRUE, (LPARAM)(id == 312 ? L"{cursor}" : L"{enter}")); - return 0; - } - if (id == IDOK) - { - collectSnippet(w, v); - auto s = v->app->settings; - s.snippets = v->snippets; - if (v->app->busy) - throw std::runtime_error("Wait for the current operation"); - v->app->applySettings(s); - if (v->app->settingsWindow) - { - auto *parent = (SettingsView *)GetWindowLongPtrW(v->app->settingsWindow, GWLP_USERDATA); - parent->draft.snippets = s.snippets; - updateSettingsState(v->app->settingsWindow, parent); - } - DestroyWindow(w); - return 0; - } - if (id == IDCANCEL) - { - DestroyWindow(w); - return 0; - } - break; - } - case WM_CLOSE: DestroyWindow(w); return 0; - case WM_NCDESTROY: + } + if (msg == WM_NCDESTROY) + { disposeFont(w); v->app->snippetsWindow = nullptr; delete v; - return DefWindowProcW(w, msg, wp, lp); } } catch (const std::exception &e) @@ -2227,7 +2316,8 @@ void showSettings(App &app, bool visible) INITCOMMONCONTROLSEX tabsInit{sizeof(tabsInit), ICC_TAB_CLASSES}; InitCommonControlsEx(&tabsInit); HWND tabs = control(w, WC_TABCONTROLW, L"", WS_TABSTOP, 260, 18, 16, 684, 32); - const wchar_t *tabNames[] = {L"General", L"Languages", L"Shortcuts", L"Clipboard", L"Tools", L"Mouse"}; + const wchar_t *tabNames[] = {L"General", L"Languages", L"Shortcuts", L"Clipboard", L"Snippets", L"Mouse", + L"Sync", L"Computers", L"Diagnostics"}; for (int i = 0; i < (int)std::size(tabNames); ++i) { TCITEMW item{}; item.mask = TCIF_TEXT; item.pszText = const_cast(tabNames[i]); @@ -2288,26 +2378,29 @@ void showSettings(App &app, bool visible) button(w, L"Clear &history...", 254, 24, 258, 200); label(w, L"Exclude applications (process names, comma-separated)", 24, 330, 660); edit(w, 243, 24, 362, 660); + button(w, L"OCR op&tions...", 257, 24, 394, 200); page(); - label(w, L"Additional tools and preferences", 24, 76, 660); - button(w, L"S&nippets...", 252, 24, 116, 210); - label(w, L"Manage reusable text and expansion triggers.", 254, 120, 430); - button(w, L"OCR op&tions...", 257, 24, 170, 210); - label(w, L"Configure text recognition from images.", 254, 174, 430); - button(w, L"S&ync...", 258, 24, 224, 210); - label(w, L"Synchronize preferences between computers.", 254, 228, 430); - button(w, L"KSwitcher &computers...", 262, 24, 278, 210); - label(w, L"Share mouse and keyboard with paired computers.", 254, 282, 430); - button(w, L"View l&og...", 256, 24, 332, 210); - label(w, L"Inspect recent operations and diagnostics.", 254, 336, 430); - checkbox(w, L"Write lo&g", 208, 24, 378, 210); + v->snippets = {&app, app.settings.snippets, app.settings.snippets}; + createSnippetEditor(w, &v->snippets, true); page(); createMousePage(w, *v); page(); - control(w, L"STATIC", L"No unsaved changes.", 0, 261, 18, 430, 684, 24); + label(w, L"Back up and synchronize settings through OpenBao.", 24, 76, 660); + button(w, L"S&ync settings...", 258, 24, 110, 210); + page(); + + label(w, L"Share mouse and keyboard with paired computers.", 24, 76, 660); + button(w, L"Manage &computers...", 262, 24, 110, 210); + page(); + + checkbox(w, L"Write lo&g", 208, 24, 76, 210); + button(w, L"View l&og...", 256, 24, 110, 210); + page(); + + control(w, L"STATIC", L"No unsaved settings.", 0, 261, 18, 430, 684, 24); button(w, L"Impo&rt...", 250, 18, 466, 125); button(w, L"&Export...", 251, 155, 466, 125); button(w, L"&Save", IDOK, 490, 466, 100); @@ -2325,40 +2418,22 @@ void showSettings(App &app, bool visible) } void showSnippets(App &app) { + if (app.settingsWindow) + { + HWND w = app.settingsWindow; + TabCtrl_SetCurSel(GetDlgItem(w, 260), SnippetsPage); + selectSettingsPage(w, reinterpret_cast(GetWindowLongPtrW(w, GWLP_USERDATA))); + activateWindow(w); + return; + } if (app.snippetsWindow) { SetForegroundWindow(app.snippetsWindow); return; } - HWND w = makeWindow(app, L"KSwitcher.Snippets", L"Text snippets", snippetProc, 740, 620); + HWND w = makeWindow(app, L"KSwitcher.Snippets", L"Text snippets", snippetProc, 720, 565); app.snippetsWindow = w; - label(w, L"Triggers", 16, 16); - control(w, L"LISTBOX", L"", WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | WS_BORDER, 301, - 16, 44, 200, 480); - button(w, L"&Add", 310, 16, 538, 90); - button(w, L"&Delete", 311, 116, 538, 100); - label(w, L"&Trigger (for example ;addr)", 236, 16, 470); - edit(w, 302, 236, 44, 488); - control(w, L"BUTTON", L"Only in these &applications (unchecked: everywhere)", WS_TABSTOP | BS_AUTOCHECKBOX, 314, 236, 82, 488, 24); - edit(w, 315, 236, 112, 488); - control(w, L"COMBOBOX", L"", WS_TABSTOP | CBS_DROPDOWNLIST | WS_VSCROLL, 316, 236, 148, 364, 200); - button(w, L"Add a&pp", 317, 612, 145, 112); - std::set apps; - EnumWindows([](HWND candidate, LPARAM context)->BOOL { - if (IsWindowVisible(candidate)) { auto name = processName(candidate); if (!name.empty()) ((std::set*)context)->insert(lower(name) + L".exe"); } - return TRUE; - }, (LPARAM)&apps); - for (const auto &name : apps) SendDlgItemMessageW(w, 316, CB_ADDSTRING, 0, (LPARAM)name.c_str()); - SendDlgItemMessageW(w, 316, CB_SETCURSEL, 0, 0); - label(w, L"Process names, comma-separated; e.g. chrome.exe, ms-teams.exe", 236, 182, 488); - label(w, L"&Replacement text", 236, 212, 480); - edit(w, 303, 236, 240, 488, 240, ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL | WS_VSCROLL); - control(w, L"STATIC", L"{cursor}: caret; {enter}: press Enter after insertion.\nUse {{cursor}} / {{enter}} for literal markers.", 0, 0, 236, 492, 488, 36); - button(w, L"Insert cursor &marker", 312, 236, 530, 190); - button(w, L"Insert &Enter marker", 313, 436, 530, 190); - button(w, L"&Save", IDOK, 510, 578, 100); - button(w, L"&Cancel", IDCANCEL, 624, 578, 100); - fillSnippets(w, (SnippetView *)GetWindowLongPtrW(w, GWLP_USERDATA)); + createSnippetEditor(w, reinterpret_cast(GetWindowLongPtrW(w, GWLP_USERDATA)), false); showRequestedWindow(w); SetForegroundWindow(w); } diff --git a/src/update.h b/src/update.h index c15a5a9..4c3034b 100644 --- a/src/update.h +++ b/src/update.h @@ -2,7 +2,7 @@ #include "platform.h" namespace ks { -inline constexpr wchar_t AppVersion[] = L"0.6.71"; +inline constexpr wchar_t AppVersion[] = L"0.6.72"; inline constexpr UINT UpdateMessage = WM_APP + 7; inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000; inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000; diff --git a/tests/chat_profiles.cpp b/tests/chat_profiles.cpp index 1ac6d7b..e3d5378 100644 --- a/tests/chat_profiles.cpp +++ b/tests/chat_profiles.cpp @@ -134,13 +134,13 @@ int main() HWND parent = app.settingsWindow; auto saveEnabled=[&] { return IsWindowEnabled(GetDlgItem(parent,IDOK))!=FALSE; }; auto status=[&] { wchar_t text[256]{}; GetDlgItemTextW(parent,261,text,256); return std::wstring(text); }; - require(!saveEnabled() && status()==L"No unsaved changes.","new Settings shows clean state with Save disabled"); + require(!saveEnabled() && status()==L"No unsaved settings.","new Settings shows clean state with Save disabled"); SendMessageW(parent,WM_COMMAND,IDOK,0); require(IsWindow(parent),"Save command with no changes does not apply or close Settings"); bool originalLog=IsDlgButtonChecked(parent,208)==BST_CHECKED; CheckDlgButton(parent,208,originalLog?BST_UNCHECKED:BST_CHECKED); SendMessageW(parent,WM_COMMAND,MAKEWPARAM(208,BN_CLICKED),0); - require(saveEnabled() && status().find(L"Unsaved changes") == 0,"checkbox edit immediately marks Settings dirty"); + require(saveEnabled() && status().find(L"Unsaved settings") == 0,"checkbox edit immediately marks Settings dirty"); CheckDlgButton(parent,208,originalLog?BST_CHECKED:BST_UNCHECKED); SendMessageW(parent,WM_COMMAND,MAKEWPARAM(208,BN_CLICKED),0); require(!saveEnabled(),"reverting checkbox disables Save again"); @@ -179,7 +179,7 @@ int main() SendMessageW(automatic,WM_COMMAND,IDOK,0); require(!saveEnabled(),"reverting auto-correction draft disables Save"); HWND tabs = GetDlgItem(parent, 260); - require(tabs && TabCtrl_GetItemCount(tabs) == 6, "six settings categories"); + require(tabs && TabCtrl_GetItemCount(tabs) == 9, "nine settings categories"); for (int page = 0; page < TabCtrl_GetItemCount(tabs); ++page) { TabCtrl_SetCurSel(tabs, page); @@ -254,7 +254,7 @@ int main() SendMessageW(dialog, WM_COMMAND, 713, 0); require(IsWindow(dialog), "chat reset keeps dialog open"); SendMessageW(dialog, WM_COMMAND, IDOK, 0); - require(saveEnabled() && status().find(L"Unsaved changes")==0,"removing child profile immediately marks parent dirty"); + require(saveEnabled() && status().find(L"Unsaved settings")==0,"removing child profile immediately marks parent dirty"); RedrawWindow(parent,nullptr,nullptr,RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN); GetClientRect(parent,&rect); dc=GetDC(parent); clip=ks::screenshotClip(dc,rect.right,rect.bottom,{}); ReleaseDC(parent,dc); @@ -357,7 +357,9 @@ int main() ks::showSettings(app); parent=app.settingsWindow; require(!saveEnabled(),"Settings starts clean before separately saved snippet edit"); ks::showSnippets(app); - HWND snippets = app.snippetsWindow; + HWND snippets = parent; + require(!app.snippetsWindow && IsWindowVisible(GetDlgItem(snippets, 301)), + "opening Snippets from Settings selects its inline editor"); SendDlgItemMessageW(snippets,301,LB_SETCURSEL,0,0); SendMessageW(snippets,WM_COMMAND,MAKEWPARAM(301,LBN_SELCHANGE),0); require(IsDlgButtonChecked(snippets,314)==BST_UNCHECKED, "old snippet shows everywhere"); @@ -371,20 +373,20 @@ int main() wchar_t appList[128]{}; GetDlgItemTextW(snippets,315,appList,128); require(std::wstring(appList)==L"Notepad.exe, MS-Teams.EXE", "Add app appends a second application without duplicates"); - SendMessageW(snippets,WM_COMMAND,IDOK,0); - require(!app.snippetsWindow && app.settings.snippets[0].apps==std::vector{L"notepad",L"ms-teams"}, "snippet editor saves selected applications"); - require(!saveEnabled() && status()==L"No unsaved changes.","separately saved snippet edit leaves Settings clean"); - SendMessageW(parent,WM_COMMAND,IDCANCEL,0); - ks::showSnippets(app);snippets=app.snippetsWindow; - SendDlgItemMessageW(snippets,301,LB_SETCURSEL,0,0); - SendMessageW(snippets,WM_COMMAND,MAKEWPARAM(301,LBN_SELCHANGE),0); - require(IsDlgButtonChecked(snippets,314)==BST_CHECKED, "scope restored when reopening editor"); + SendMessageW(snippets,WM_COMMAND,318,0); + require(IsWindow(snippets) && app.settings.snippets[0].apps==std::vector{L"notepad",L"ms-teams"}, "inline snippet editor saves selected applications"); + require(!saveEnabled() && status()==L"No unsaved settings.","separately saved snippet edit leaves Settings clean"); RedrawWindow(snippets,nullptr,nullptr,RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN); RECT snippetRect{};GetClientRect(snippets,&snippetRect); HDC snippetDc=GetDC(snippets); auto snippetImage=ks::screenshotClip(snippetDc,snippetRect.right,snippetRect.bottom,{}); ReleaseDC(snippets,snippetDc); ks::atomicWrite(std::filesystem::path(ks::executable()).parent_path()/L"snippet-scopes.png",ks::encodePng(ks::decodeImage(snippetImage))); + SendMessageW(parent,WM_COMMAND,IDCANCEL,0); + ks::showSnippets(app);snippets=app.snippetsWindow; + SendDlgItemMessageW(snippets,301,LB_SETCURSEL,0,0); + SendMessageW(snippets,WM_COMMAND,MAKEWPARAM(301,LBN_SELCHANGE),0); + require(IsDlgButtonChecked(snippets,314)==BST_CHECKED, "scope restored when reopening editor"); SetDlgItemTextW(snippets,315,L"chrome.exe"); SendMessageW(snippets,WM_COMMAND,IDCANCEL,0); require(app.settings.snippets[0].apps==std::vector{L"notepad",L"ms-teams"}, "cancel preserves existing scope"); diff --git a/tests/input.cpp b/tests/input.cpp index cb6f9ce..3897a51 100644 --- a/tests/input.cpp +++ b/tests/input.cpp @@ -800,12 +800,52 @@ int main(int argc, char **argv) { require(fitted.left==0&&fitted.top==0&&fitted.right==1200&&fitted.bottom==800,"oversized disconnected-monitor window fits work area"); fitted=ks::fitWindowRect({2000,2000,2600,2400},{-1920,0,0,1080}); require(fitted.left==-600&&fitted.top==680&&fitted.right==0,"negative-coordinate monitor supported"); + // The fixture has a message-only window and no keyboard hook. + app.settings.toggle = app.settings.casing = app.settings.translit = + app.settings.undo = app.settings.clipboard = app.settings.screenshot = L""; + std::fill(app.settings.direct.begin(), app.settings.direct.end(), L""); ks::showSettings(app,false); { auto settings = app.settingsWindow; auto tabs = GetDlgItem(settings, 260); auto capture = GetDlgItem(settings, 737); auto events = GetDlgItem(settings, 733); + auto visible = [&](int id) { return (GetWindowLongPtrW(GetDlgItem(settings, id), GWL_STYLE) & WS_VISIBLE) != 0; }; + auto selectPage = [&](int index) { + TabCtrl_SetCurSel(tabs, index); + NMHDR changed{tabs, 260, TCN_SELCHANGE}; + SendMessageW(settings, WM_NOTIFY, 260, reinterpret_cast(&changed)); + }; + RECT lastTab{}, tabClient{}; + GetClientRect(tabs, &tabClient); + require(TabCtrl_GetItemCount(tabs) == 9 && TabCtrl_GetItemRect(tabs, 8, &lastTab) && + lastTab.right <= tabClient.right, "all Settings tabs fit in one row"); + selectPage(3); + require(visible(257) && !visible(301), "OCR options are in Clipboard"); + selectPage(6); + require(visible(258) && !visible(262), "Sync has its own tab"); + selectPage(7); + require(visible(262) && !visible(258), "Computers has its own tab"); + selectPage(8); + require(visible(208) && visible(256), "logging controls are in Diagnostics"); + selectPage(4); + require(visible(301) && visible(303) && visible(318), "Snippets has an inline editor and its own Save button"); + const bool awake = app.settings.awake; + SendDlgItemMessageW(settings, 205, BM_SETCHECK, awake ? BST_UNCHECKED : BST_CHECKED, 0); + SendMessageW(settings, WM_COMMAND, 310, 0); + SetDlgItemTextW(settings, 302, L";inline-fixture"); + SetDlgItemTextW(settings, 303, L"inline snippet"); + selectPage(0); + selectPage(4); + SendMessageW(settings, WM_COMMAND, 318, 0); + require(app.settings.awake == awake && IsWindowEnabled(GetDlgItem(settings, IDOK)) && + std::any_of(app.settings.snippets.begin(), app.settings.snippets.end(), [](const ks::Snippet &snippet) { + return snippet.trigger == L";inline-fixture" && snippet.text == L"inline snippet"; + }), "saving inline snippets preserves the unsaved settings draft across tab changes"); + SendDlgItemMessageW(settings, 205, BM_SETCHECK, awake ? BST_CHECKED : BST_UNCHECKED, 0); + SendMessageW(settings, WM_COMMAND, 311, 0); + SendMessageW(settings, WM_COMMAND, 318, 0); + selectPage(0); require(!(GetWindowLongPtrW(capture, GWL_STYLE) & WS_VISIBLE), "mouse detection is hidden on General"); TabCtrl_SetCurSel(tabs, 5);