From 696f48209ddb63150e2fbffadd6f686af3b340ac Mon Sep 17 00:00:00 2001 From: Anatolii Hrynchuk Date: Tue, 24 Nov 2026 22:42:30 +0200 Subject: [PATCH] Add Drive backup history and make Settings editors resize Refs #84 --- README.md | 7 +- src/app.cpp | 3 +- src/google_drive.cpp | 86 +++++++++++++------ src/google_drive.h | 17 ++-- src/ui.cpp | 148 ++++++++++++++++++++++++++------ src/ui_app_languages.inl | 2 +- src/ui_google_drive.inl | 179 +++++++++++++++++++++++++++++++-------- src/ui_mouse_buttons.inl | 2 +- tests/chat_profiles.cpp | 135 ++++++++++++++++++++++++----- 9 files changed, 466 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index 80dc7d0..53bbe97 100644 --- a/README.md +++ b/README.md @@ -727,9 +727,10 @@ sync. Manual Google Drive backups remain available with either provider. Turn off Google Drive sync and apply the change before switching Google accounts or disconnecting. -**Back up saved settings** uploads your last applied -settings and displays the backup time. **Restore latest backup** asks for -confirmation and loads the settings into the current draft. Review the result +**Back up saved settings** adds a copy of your last applied settings to the +backup list. The list shows the backup date, source and size, newest first. +Use **Load older backups** to see more when available. Select a row and choose +**Restore selected backup** to load that copy into the draft after confirmation. Review the result and choose **Apply** or **Save**. **Disconnect** removes the refresh token from Windows Credential Manager and leaves existing backups in Google Drive. The automatic sync profile is separate from manual backup history. Applying diff --git a/src/app.cpp b/src/app.cpp index b066779..0106084 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -3056,8 +3056,9 @@ void App::captureHistory() return; auto owner = GetClipboardOwner(); auto app = processName(owner ? owner : GetForegroundWindow()); + const auto appKey = lower(app); for (auto &name : config.excluded) - if (lower(name) == lower(app)) + if (snippetAppName(name) == appKey) return; if(!config.history){ auto clip=readClipboard(window,(size_t)config.maxImageMiB*1024*1024,ClipboardRead::All,sequence); diff --git a/src/google_drive.cpp b/src/google_drive.cpp index 72eadd9..e64ec39 100644 --- a/src/google_drive.cpp +++ b/src/google_drive.cpp @@ -14,6 +14,7 @@ #include "google_drive_oauth_config.h" #endif #include +#include #include #include @@ -26,6 +27,7 @@ constexpr std::string_view Scope = "https://www.googleapis.com/auth/drive.appdat constexpr auto TokenHost = L"oauth2.googleapis.com"; constexpr auto DriveHost = L"www.googleapis.com"; constexpr auto NativeName = "kswitcher-win32-settings.json"; +constexpr auto PreviewName = "kswitcher-settings.json"; constexpr auto SyncName = "kswitcher-win32-sync-v1.json"; constexpr auto Reconnect = "Google Drive needs authorization again. Reconnect your Google account."; constexpr auto Network = "Could not reach Google Drive. Check your connection and try again."; @@ -375,6 +377,7 @@ void checkDrive(DWORD status) { if (status == 401) throw std::runtime_error(Reconnect); if (status == 403) throw std::runtime_error("Google Drive denied access. Reconnect or check your account's access."); + if (status == 404) throw std::runtime_error("The requested file is no longer available on Google Drive."); if (status == 412) throw std::runtime_error("The Google Drive profile changed on another PC. Sync again."); if (status < 200 || status >= 300) throw std::runtime_error("Google Drive could not complete the request. Try again."); } @@ -407,6 +410,20 @@ DriveFile driveFile(const Json &file) return result; } +Json driveFilePage(const std::string &access, const std::string &filter, size_t count, + std::string_view page, std::string_view fields) +{ + const auto query = form({{"spaces", "appDataFolder"}, {"pageSize", std::to_string(count)}, + {"orderBy", "createdTime desc"}, {"q", filter}, {"fields", fields}}); + const auto response = driveRequest(L"GET", "/drive/v3/files?" + query + + (page.empty() ? "" : "&pageToken=" + urlEncode(page)), access); + auto data = Json::parse(response.body, nullptr, false); + if (!data.is_object() || !data.contains("files") || !data.at("files").is_array() || + data.value("incompleteSearch", false)) + throw std::runtime_error("Google Drive returned an unreadable file list."); + return data; +} + std::vector matchingFiles(const std::string &access, const std::string &filter, size_t count) { std::vector matches; @@ -414,14 +431,9 @@ std::vector matchingFiles(const std::string &access, const std::strin // Drive can return an empty page with a continuation token. for (int i = 0; i < 20; ++i) { - const auto query = form({{"spaces", "appDataFolder"}, {"pageSize", std::to_string(count)}, {"orderBy", "createdTime desc"}, - {"q", filter}, {"fields", "nextPageToken,incompleteSearch,files(id,createdTime)"}}); - const auto response = driveRequest(L"GET", "/drive/v3/files?" + query + - (page.empty() ? "" : "&pageToken=" + urlEncode(page)), access); + const auto data = driveFilePage(access, filter, count, page, "nextPageToken,incompleteSearch,files(id,createdTime)"); try { - const auto data = Json::parse(response.body, nullptr, false); - if (data.value("incompleteSearch", false)) throw std::runtime_error("Incomplete Drive search."); const auto &files = data.at("files").get_ref(); for (const auto &file : files) { @@ -439,13 +451,6 @@ std::vector matchingFiles(const std::string &access, const std::strin throw std::runtime_error("Google Drive did not finish listing backups. Try again."); } -std::optional latestFile(const std::string &access) -{ - auto files = matchingFiles(access, "name = 'kswitcher-settings.json' or name = 'kswitcher-win32-settings.json'", 1); - if (files.empty()) return {}; - return std::move(files.front()); -} - DriveFile createDriveFile(const std::string &access, const std::string &name, const std::string &settings) { if (settings.size() > GoogleDriveBackupLimit) throw std::runtime_error("Settings exceed the 2 MiB Drive limit."); @@ -613,29 +618,62 @@ void disconnectGoogleDrive() throw std::runtime_error("Could not remove the Google Drive connection from Windows Credential Manager."); } -std::wstring latestGoogleDriveBackup() +GoogleDriveBackupPage listGoogleDriveBackups(std::string_view page) { auto access = accessToken(); ClearString clear{access}; - auto file = latestFile(access); - return file ? file->created : std::wstring{}; + const auto filter = std::string("name = '") + PreviewName + "' or name = '" + NativeName + "'"; + std::string token(page); + // An empty page with a continuation token can occur before the end. + for (int attempt = 0; attempt < 20; ++attempt) + { + const auto data = driveFilePage(access, filter, 50, token, + "nextPageToken,incompleteSearch,files(id,createdTime,name,size)"); + GoogleDriveBackupPage result; + try + { + result.nextPage = data.value("nextPageToken", ""); + for (const auto &file : data.at("files")) + { + auto info = driveFile(file); + const auto name = file.at("name").get(); + if (name != NativeName && name != PreviewName) continue; + std::optional size; + if (file.contains("size")) + { + const auto value = file.at("size").get(); + uint64_t parsed{}; + const auto [end, error] = std::from_chars(value.data(), value.data() + value.size(), parsed); + if (error == std::errc{} && end == value.data() + value.size()) size = parsed; + } + result.backups.push_back({std::move(info.id), std::move(info.created), size, name == PreviewName}); + } + } + catch (const std::exception &) + { + throw std::runtime_error("Google Drive returned an unreadable backup list."); + } + if (!result.backups.empty() || result.nextPage.empty()) return result; + token = std::move(result.nextPage); + } + throw std::runtime_error("Google Drive did not finish listing backups. Try again."); } -std::wstring uploadGoogleDriveBackup(const Bytes &settings) +GoogleDriveBackupInfo uploadGoogleDriveBackup(const Bytes &settings) { auto access = accessToken(); ClearString clear{access}; - return createDriveFile(access, NativeName, {settings.begin(), settings.end()}).created; + auto file = createDriveFile(access, NativeName, {settings.begin(), settings.end()}); + return {std::move(file.id), std::move(file.created), settings.size(), false}; } -GoogleDriveBackup fetchGoogleDriveBackup() +Bytes fetchGoogleDriveBackup(std::string_view id) { + if (id.empty()) throw std::runtime_error("Select a Google Drive backup to restore."); auto access = accessToken(); ClearString clear{access}; - const auto file = latestFile(access); - if (!file) return {}; - auto response = driveRequest(L"GET", "/drive/v3/files/" + urlEncode(file->id) + "?alt=media", access, - {}, {}, GoogleDriveBackupLimit); - return {file->created, std::move(response.body)}; + auto response = driveRequest(L"GET", "/drive/v3/files/" + urlEncode(id) + "?alt=media", + access, {}, {}, GoogleDriveBackupLimit); + return std::move(response.body); } } diff --git a/src/google_drive.h b/src/google_drive.h index 92b57c5..9348b21 100644 --- a/src/google_drive.h +++ b/src/google_drive.h @@ -19,12 +19,19 @@ bool googleDriveConfigured(); bool googleDriveConnected(); void connectGoogleDrive(std::stop_token); void disconnectGoogleDrive(); -std::wstring latestGoogleDriveBackup(); -std::wstring uploadGoogleDriveBackup(const Bytes &); -struct GoogleDriveBackup +struct GoogleDriveBackupInfo { + std::string id; std::wstring created; - Bytes settings; + std::optional size; + bool preview{}; }; -GoogleDriveBackup fetchGoogleDriveBackup(); +struct GoogleDriveBackupPage +{ + std::vector backups; + std::string nextPage; +}; +GoogleDriveBackupPage listGoogleDriveBackups(std::string_view page = {}); +GoogleDriveBackupInfo uploadGoogleDriveBackup(const Bytes &); +Bytes fetchGoogleDriveBackup(std::string_view id); } diff --git a/src/ui.cpp b/src/ui.cpp index b55b2f6..7da50f1 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1131,6 +1131,9 @@ LRESULT CALLBACK historyProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) #ifndef KS_RESIDENT_APP constexpr int LanguagesPage = 1, ShortcutsPage = 2, ClipboardPage = 3, SnippetsPage = 4, MousePage = 5; constexpr int ExceptionsPage = 13, PersonalDictionariesPage = 14, WordBoundariesPage = 15, SnippetMacros = 320; +constexpr int CustomReplacementsPage = 16; +constexpr int ClipboardExcludedApps = 243, ClipboardAppName = 244, ClipboardAddApp = 245, + ClipboardRemoveApp = 246, ClipboardAppPicker = 247; constexpr UINT AppWindowPicked = WM_APP + 78; constexpr int SettingsNavigation = 260, SettingsStatus = 261, SettingsViewport = 264, SettingsApply = 272; constexpr int SettingsBrand = 265, SettingsHeading = 266, SettingsDescription = 267, SettingsGroup = 268; @@ -1309,6 +1312,7 @@ struct SettingsView unsigned mouseEvents{}, rawMouseEvents{}; bool rawMouseRegistered{}; SnippetView snippets; + HWND clipboardPickerOutline{}; }; void saveSettingsWindowState(HWND w, const SettingsView &v) { @@ -1760,6 +1764,33 @@ int fitSettingsColumns(WindowLayout &layout, size_t first, size_t end, int width int fitLanSettings(HWND panel, int width); int fitSyncSettings(HWND panel, int width); int fitDriveSettings(HWND panel, int width, int height); +void stretchSettingsEditors(WindowLayout &layout, size_t first, size_t end, int extra, + std::initializer_list editors, bool stacked) +{ + if (extra <= 0) return; + int remaining = extra, count = static_cast(editors.size()); + for (int id : editors) + { + const int growth = stacked ? remaining / count : extra; + remaining -= growth; + --count; + for (size_t i = first; i < end; ++i) + { + auto &[child, bounds] = layout.controls[i]; + if (GetDlgCtrlID(child) != id) continue; + const auto editor = bounds; + bounds.bottom += growth; + for (size_t j = first; j < end; ++j) + { + auto &below = layout.controls[j].second; + if (below.top >= editor.bottom && (stacked || (below.left >= editor.left && below.left < editor.right))) + OffsetRect(&below, 0, growth); + } + break; + } + } + layout.height += extra; +} void reflowSettingsPage(HWND pane, WindowLayout &layout, int width, int height) { const auto &v = *reinterpret_cast(GetWindowLongPtrW(GetParent(pane), GWLP_USERDATA)); @@ -1788,6 +1819,13 @@ void reflowSettingsPage(HWND pane, WindowLayout &layout, int width, int height) case WordBoundariesPage: grid = {24, 684, 362, 346, 90, 500}; break; } layout.height = fitSettingsColumns(layout, page.first, page.end, available, grid); + const int extra = height * 96 / static_cast(dpi) - layout.height; + if (v.selectedPage == SnippetsPage) + stretchSettingsEditors(layout, page.first, page.end, extra, {301, 303}, available < grid.wrapAt); + if (v.selectedPage == MousePage) + stretchSettingsEditors(layout, page.first, page.end, extra, {731, 733}, available < grid.wrapAt); + if (v.selectedPage == CustomReplacementsPage) + stretchSettingsEditors(layout, page.first, page.end, extra, {416}, false); }; fit(width); if (scale(pane, layout.height) > height) @@ -1859,10 +1897,17 @@ void reflowClipboard(HWND pane, WindowLayout &layout, int width, int height) const int captionHeight = settingsCaptionHeight(layout.controls[first + 9].first, contentWidth); layout.controls[first + 9].second = {left, y, right, y + captionHeight}; y += captionHeight + 4; - layout.controls[first + 10].second = {left, y, right, y + 25}; - y += 35; - layout.controls[first + 11].second = {left, y, actionRight, y + 28}; - layout.height = y + 48; + const int listHeight = std::max(100, height * 96 / static_cast(dpi) - y - 100); + layout.controls[first + 10].second = {left, y, right, y + listHeight}; + y += listHeight + 8; + const int pickerLeft = right - 32, removeLeft = pickerLeft - 84, addLeft = removeLeft - 68; + layout.controls[first + 11].second = {left, y + 1, addLeft - 6, y + 26}; + layout.controls[first + 12].second = {addLeft, y, removeLeft - 6, y + 28}; + layout.controls[first + 13].second = {removeLeft, y, pickerLeft - 6, y + 28}; + layout.controls[first + 14].second = {pickerLeft, y, right, y + 28}; + y += 36; + layout.controls[first + 15].second = {left, y, actionRight, y + 28}; + layout.height = y + 56; }; fit(width); if (scale(pane, layout.height) > height) @@ -2489,6 +2534,36 @@ void fillLayouts(SettingsView *v) } void fillCorrectionOptions(HWND w, const Settings &draft); void collectCorrectionOptions(HWND w, Settings &draft); +void updateClipboardAppButtons(HWND pane) +{ + EnableWindow(GetDlgItem(pane, ClipboardAddApp), !snippetAppName(value(pane, ClipboardAppName)).empty()); + EnableWindow(GetDlgItem(pane, ClipboardRemoveApp), + SendDlgItemMessageW(pane, ClipboardExcludedApps, LB_GETCURSEL, 0, 0) != LB_ERR); +} +void fillClipboardApps(SettingsView &view, int selected = -1) +{ + const auto list = GetDlgItem(view.viewport, ClipboardExcludedApps); + SendMessageW(list, LB_RESETCONTENT, 0, 0); + for (const auto &name : view.draft.excluded) + SendMessageW(list, LB_ADDSTRING, 0, reinterpret_cast(name.c_str())); + if (selected >= 0 && !view.draft.excluded.empty()) + SendMessageW(list, LB_SETCURSEL, std::min(selected, static_cast(view.draft.excluded.size()) - 1), 0); + updateClipboardAppButtons(view.viewport); +} +void addClipboardApp(SettingsView &view, std::wstring name) +{ + name = snippetAppName(std::move(name)); + if (name.empty()) return; + if (name.size() > 260 || name.find_first_of(L"\\/:*?\"<>|,\r\n") != name.npos) + throw std::runtime_error("Enter one process name, such as chrome.exe."); + auto &apps = view.draft.excluded; + const auto existing = std::find_if(apps.begin(), apps.end(), + [&](const auto &app) { return snippetAppName(app) == name; }); + const auto row = static_cast(existing - apps.begin()); + if (existing == apps.end()) apps.push_back(std::move(name)); + value(view.viewport, ClipboardAppName, L""); + fillClipboardApps(view, row); +} void fillSettings(HWND root, SettingsView *v) { HWND w = v->viewport; @@ -2513,14 +2588,8 @@ void fillSettings(HWND root, SettingsView *v) value(w, 240, std::to_wstring(s.maxItems)); value(w, 241, std::to_wstring(s.maxMiB)); value(w, 242, std::to_wstring(s.maxImageMiB)); - std::wstring excluded; - for (auto &name : s.excluded) - { - if (!excluded.empty()) - excluded += L", "; - excluded += name; - } - value(w, 243, excluded); + value(w, ClipboardAppName, L""); + fillClipboardApps(*v); v->order.clear(); for (auto &id : s.cycle) for (int i = 0; i < (int)v->app->layouts.size(); ++i) @@ -2571,15 +2640,6 @@ Settings collectSettings(SettingsView *v) s.maxItems = integer(w, 240); s.maxMiB = integer(w, 241); s.maxImageMiB = integer(w, 242); - s.excluded.clear(); - std::wistringstream input(value(w, 243)); - std::wstring item; - while (std::getline(input, item, L',')) - { - auto first = item.find_first_not_of(L" \t"), last = item.find_last_not_of(L" \t"); - if (first != item.npos) - s.excluded.push_back(item.substr(first, last - first + 1)); - } std::vector cycle; for (int i : v->order) { @@ -2948,10 +3008,19 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) paintSettings(w, *v); return 0; case AppWindowPicked: - snippetWindowPicked(v->viewport, wp, lp); + if (v->selectedPage == ClipboardPage) + { + if (lp == 1 && wp) + { + addClipboardApp(*v, processName(reinterpret_cast(wp))); + updateSettingsState(w, v); + } + } + else if (v->selectedPage == SnippetsPage) snippetWindowPicked(v->viewport, wp, lp); return 0; case WM_DRAWITEM: - if (wp == AppWindowPickerIcon || wp == AddMouseProfile || wp == RenameMouseProfile || wp == DeleteMouseProfile || wp == AddMouseEvent) + if (wp == AppWindowPickerIcon || wp == ClipboardAppPicker || wp == AddMouseProfile || + wp == RenameMouseProfile || wp == DeleteMouseProfile || wp == AddMouseEvent) { drawActionApplicationIcon(w, *reinterpret_cast(lp)); return TRUE; @@ -3067,6 +3136,27 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp) } SettingsStateRefresh refresh{w}; HWND pane = v->viewport; + if ((id == ClipboardAppName && HIWORD(wp) == EN_CHANGE) || + (id == ClipboardExcludedApps && HIWORD(wp) == LBN_SELCHANGE)) + { + updateClipboardAppButtons(pane); + return 0; + } + if (id == ClipboardAddApp && HIWORD(wp) == BN_CLICKED) + { + addClipboardApp(*v, value(pane, ClipboardAppName)); + return 0; + } + if (id == ClipboardRemoveApp && HIWORD(wp) == BN_CLICKED) + { + const auto row = SendDlgItemMessageW(pane, ClipboardExcludedApps, LB_GETCURSEL, 0, 0); + if (row != LB_ERR && static_cast(row) < v->draft.excluded.size()) + { + v->draft.excluded.erase(v->draft.excluded.begin() + row); + fillClipboardApps(*v, static_cast(row)); + } + return 0; + } if (id == 282 && HIWORD(wp) == BN_CLICKED) { writeClipboard(w, textClip(value(pane, 281))); @@ -3899,9 +3989,15 @@ void showSettings(App &app, bool visible) label(pane, L"Per item MiB", 484, 176, 180); edit(pane, 242, 484, 204, 200); button(pane, L"Clear &history...", 254, 24, 258, 200); - label(pane, L"Exclude applications (process names, comma-separated)", 24, 330, 660); - edit(pane, 243, 24, 362, 660); - button(pane, L"OCR op&tions...", 257, 24, 394, 200); + label(pane, L"Exclude applications from clipboard history", 24, 330, 660); + control(pane, L"LISTBOX", L"Excluded applications", WS_TABSTOP | WS_BORDER | WS_VSCROLL | + LBS_NOTIFY | LBS_NOINTEGRALHEIGHT, ClipboardExcludedApps, 24, 362, 660, 100); + const auto clipboardApp = edit(pane, ClipboardAppName, 24, 472, 460); + SendMessageW(clipboardApp, EM_SETCUEBANNER, TRUE, reinterpret_cast(L"Process name, for example chrome.exe")); + button(pane, L"&Add", ClipboardAddApp, 490, 471, 62); + button(pane, L"&Remove", ClipboardRemoveApp, 558, 471, 78); + createAppWindowPicker(pane, ClipboardAppPicker, 652, 471, 32, v->clipboardPickerOutline, createButtonTooltips(pane)); + button(pane, L"OCR op&tions...", 257, 24, 507, 200); page(); v->snippets = {&app, app.settings.snippets, app.settings.snippets}; diff --git a/src/ui_app_languages.inl b/src/ui_app_languages.inl index f76ccc7..ff22fc5 100644 --- a/src/ui_app_languages.inl +++ b/src/ui_app_languages.inl @@ -192,7 +192,7 @@ void addButtonTooltip(HWND tips, HWND owner, int id, const wchar_t *text) constexpr int AppWindowPickerIcon = 753; void createAppWindowPicker(HWND w, int id, int x, int y, int width, HWND &outline, HWND tips = nullptr) { - const bool icon = id == AppWindowPickerIcon; + const bool icon = id == AppWindowPickerIcon || id == ClipboardAppPicker; HWND picker = control(w, L"BUTTON", icon ? L"Drag to application window" : L" ⊕ Drag to window", WS_TABSTOP | (icon ? BS_OWNERDRAW : BS_PUSHBUTTON | BS_LEFT), id, x, y, width, 28); SetWindowSubclass(picker, appWindowPickerProc, 1, reinterpret_cast(&outline)); diff --git a/src/ui_google_drive.inl b/src/ui_google_drive.inl index 23596c5..f7026c4 100644 --- a/src/ui_google_drive.inl +++ b/src/ui_google_drive.inl @@ -1,19 +1,21 @@ constexpr int DriveConnect = 620, DriveBackup = 621, DriveRestore = 622, DriveDisconnect = 623, DriveStatus = 624; constexpr int DriveSyncNow = 626, DriveSyncUpload = 627, DriveSyncDownload = 628, DriveSyncConflicts = 629, - DriveSyncStatus = 630; -constexpr int DriveSettingsWidth = 660, DriveSettingsHeight = 390; + DriveSyncStatus = 630, DriveList = 631, DriveOlder = 632; +constexpr int DriveSettingsWidth = 660, DriveSettingsHeight = 507; constexpr int DriveMargin = 16, DriveButtonWidth = 276, DriveButtonGap = 16; constexpr int DriveLeftButton = (DriveSettingsWidth - 2 * DriveButtonWidth - DriveButtonGap) / 2; constexpr int DriveRightButton = DriveLeftButton + DriveButtonWidth + DriveButtonGap; -constexpr int DriveBackupActionsTop = 124; -constexpr int DriveSyncTop = 193; -enum class DriveAction { Status, Connect, Backup, Restore, Disconnect }; +constexpr int DriveOlderTop = 208, DriveBackupActionsTop = 240; +constexpr int DriveSyncTop = 310; +enum class DriveAction { Status, Connect, Backup, Restore, Disconnect, Older }; struct DriveResult { std::optional connected; - std::optional latest; + std::optional page; + std::optional uploaded; std::wstring notice; std::optional backup; + std::wstring restoreDate; }; struct DriveTask { @@ -28,7 +30,9 @@ struct DriveView bool configured = googleDriveConfigured(), connected{}; DriveAction action = DriveAction::Status; std::shared_ptr task; - std::wstring latest, notice; + std::vector backups; + std::string nextPage; + std::wstring notice; }; std::wstring driveBackupTime(const std::wstring &value) @@ -43,6 +47,55 @@ std::wstring driveBackupTime(const std::wstring &value) return std::wstring(date) + L" " + time; } +const GoogleDriveBackupInfo *selectedDriveBackup(HWND w, const DriveView &view) +{ + const auto index = ListView_GetNextItem(GetDlgItem(w, DriveList), -1, LVNI_SELECTED); + return index >= 0 && static_cast(index) < view.backups.size() ? &view.backups[index] : nullptr; +} + +void fitDriveBackupColumns(HWND list) +{ + if (!list) return; + RECT client{}; + GetClientRect(list, &client); + const int width = client.right; + const int source = std::max(1, width * 34 / 100); + const int size = std::min(scale(list, 105), std::max(1, width / 4)); + ListView_SetColumnWidth(list, 0, std::max(1, width - source - size)); + ListView_SetColumnWidth(list, 1, source); + ListView_SetColumnWidth(list, 2, size); +} + +void fillDriveBackupList(HWND w, const DriveView &view, const std::string &selected) +{ + const auto list = GetDlgItem(w, DriveList); + SendMessageW(list, WM_SETREDRAW, FALSE, 0); + ListView_DeleteAllItems(list); + int selection = 0; + for (const auto &backup : view.backups) + { + auto date = driveBackupTime(backup.created); + LVITEMW row{LVIF_TEXT, ListView_GetItemCount(list)}; + row.pszText = date.data(); + const int index = ListView_InsertItem(list, &row); + if (index < 0) break; + if (backup.id == selected) selection = index; + std::wstring source = backup.preview ? L"KSwitcher-New" : L"KSwitcher Win32"; + auto size = !backup.size ? L"—" : *backup.size < 1024 ? std::to_wstring(*backup.size) + L" B" : + std::to_wstring(*backup.size / 1024 + (*backup.size % 1024 != 0)) + L" KiB"; + ListView_SetItemText(list, index, 1, source.data()); + ListView_SetItemText(list, index, 2, size.data()); + } + if (ListView_GetItemCount(list)) + { + ListView_SetItemState(list, selection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); + ListView_EnsureVisible(list, selection, FALSE); + } + fitDriveBackupColumns(list); + SendMessageW(list, WM_SETREDRAW, TRUE, 0); + InvalidateRect(list, nullptr, TRUE); +} + void updateDriveControls(HWND w, const DriveView &view) { const auto *editor = syncEditor(view.settings->sync); @@ -52,14 +105,14 @@ void updateDriveControls(HWND w, const DriveView &view) const bool available = view.configured && !busy; EnableWindow(GetDlgItem(w, DriveConnect), (available && !active) || (signingIn && !view.task->stop.stop_requested())); EnableWindow(GetDlgItem(w, DriveBackup), available && view.connected); - EnableWindow(GetDlgItem(w, DriveRestore), available && view.connected); + EnableWindow(GetDlgItem(w, DriveRestore), available && view.connected && selectedDriveBackup(w, view)); + EnableWindow(GetDlgItem(w, DriveOlder), available && view.connected && !view.nextPage.empty()); EnableWindow(GetDlgItem(w, DriveDisconnect), available && view.connected && !active); value(w, DriveConnect, signingIn ? L"Cancel &sign-in" : view.connected ? L"&Reconnect" : L"&Connect"); const bool checking = busy && view.action == DriveAction::Status && !view.connected; std::wstring status = checking ? view.notice : !view.configured ? L"Google Drive is unavailable in this build." : view.connected ? L"Google Drive is connected." : L"Google Drive is disconnected."; - if (view.connected && !view.latest.empty()) status += L"\r\nLatest backup: " + driveBackupTime(view.latest); if (!checking && !view.notice.empty()) status += L"\r\n" + view.notice; if (value(w, DriveStatus) != status) value(w, DriveStatus, status); } @@ -86,10 +139,13 @@ void startDriveTask(HWND w, DriveView &view, DriveAction action) task->signingIn = action == DriveAction::Connect; const auto path = view.settings->app->data / L"settings.json"; const auto layouts = view.settings->app->layouts; + const auto *selection = selectedDriveBackup(w, view); + const auto backup = action == DriveAction::Restore && selection ? *selection : GoogleDriveBackupInfo{}; + const auto page = action == DriveAction::Older ? view.nextPage : std::string{}; if (!SetTimer(w, 1, 100, nullptr)) throw std::runtime_error("Could not start the Google Drive action."); try { - std::thread([task, action, path, layouts] + std::thread([task, action, path, layouts, backup, page] { DriveResult result; try @@ -106,8 +162,8 @@ void startDriveTask(HWND w, DriveView &view, DriveAction action) result.connected = googleDriveConnected(); if (*result.connected) { - result.latest = latestGoogleDriveBackup(); - if (result.latest->empty()) result.notice = L"No Google Drive backup yet."; + result.page = listGoogleDriveBackups(); + if (result.page->backups.empty()) result.notice = L"No Google Drive backups yet."; } break; case DriveAction::Backup: @@ -115,18 +171,17 @@ void startDriveTask(HWND w, DriveView &view, DriveAction action) Settings saved; try { saved = loadSettings(path, layouts); } catch (const std::exception &) { throw std::runtime_error("Could not read the saved KSwitcher settings."); } - result.latest = uploadGoogleDriveBackup(encodeDriveBackup(saved)); + result.uploaded = uploadGoogleDriveBackup(encodeDriveBackup(saved)); result.notice = L"Saved settings backed up to Google Drive."; break; } case DriveAction::Restore: - { - auto backup = fetchGoogleDriveBackup(); - result.latest = std::move(backup.created); - if (result.latest->empty()) result.notice = L"No backup is available for this Google account."; - else result.backup = std::move(backup.settings); + result.backup = fetchGoogleDriveBackup(backup.id); + result.restoreDate = driveBackupTime(backup.created); + break; + case DriveAction::Older: + result.page = listGoogleDriveBackups(page); break; - } case DriveAction::Disconnect: disconnectGoogleDrive(); result.connected = false; @@ -152,8 +207,9 @@ void startDriveTask(HWND w, DriveView &view, DriveAction action) case DriveAction::Status: view.notice = L"Checking the Google Drive connection…"; break; case DriveAction::Connect: view.notice = L"Complete Google sign-in in your browser."; break; case DriveAction::Backup: view.notice = L"Backing up saved settings…"; break; - case DriveAction::Restore: view.notice = L"Downloading the latest backup…"; break; + case DriveAction::Restore: view.notice = L"Downloading the selected backup…"; break; case DriveAction::Disconnect: view.notice = L"Disconnecting from Google Drive…"; break; + case DriveAction::Older: view.notice = L"Loading older backups…"; break; } updateDriveControls(w, view); updateDriveSyncControls(w, view); @@ -192,8 +248,7 @@ void finishDriveTask(HWND w, DriveView &view) if (view.action == DriveAction::Connect && !task->signingIn) { view.connected = true; - view.latest.clear(); - view.notice = L"Checking for the latest backup…"; + view.notice = L"Loading Google Drive backups…"; updateDriveControls(w, view); } return; @@ -203,16 +258,45 @@ void finishDriveTask(HWND w, DriveView &view) } KillTimer(w, 1); view.task.reset(); + const auto *previous = selectedDriveBackup(w, view); + auto selection = previous ? previous->id : std::string{}; + bool listChanged = false; if (result.connected) { view.connected = *result.connected; - view.latest.clear(); + if (!view.connected || view.action == DriveAction::Connect) + { + view.backups.clear(); + view.nextPage.clear(); + selection.clear(); + listChanged = true; + } } - if (result.latest) view.latest = std::move(*result.latest); + if (result.page) + { + view.nextPage = std::move(result.page->nextPage); + if (view.action == DriveAction::Older) + { + for (auto &backup : result.page->backups) + if (std::none_of(view.backups.begin(), view.backups.end(), + [&](const auto &known) { return known.id == backup.id; })) + view.backups.push_back(std::move(backup)); + } + else view.backups = std::move(result.page->backups); + listChanged = true; + } + if (result.uploaded) + { + selection = result.uploaded->id; + view.backups.insert(view.backups.begin(), std::move(*result.uploaded)); + listChanged = true; + } + if (listChanged) fillDriveBackupList(w, view, selection); view.notice = std::move(result.notice); if (result.backup) { - std::wstring prompt = L"Load the latest backup into Settings? It will replace unapplied edits to the settings included in the backup. Use Apply or Save to make the restored settings active."; + std::wstring prompt = L"Load the Google Drive backup from " + result.restoreDate + + L" into Settings? It will replace unapplied edits to the settings included in the backup. Use Apply or Save to make the restored settings active."; const auto *editor = syncEditor(view.settings->sync); if (editor && automaticSyncEnabled(syncFields(view.settings->sync))) prompt += L"\n\nAutomatic synchronization can send applied settings to the active provider and other PCs."; @@ -232,7 +316,11 @@ void finishDriveTask(HWND w, DriveView &view) LRESULT CALLBACK driveSettingsProc(HWND w, UINT message, WPARAM wp, LPARAM lp) { - if (message == WM_SIZE) arrangeWindow(w); + if (message == WM_SIZE) + { + arrangeWindow(w); + fitDriveBackupColumns(GetDlgItem(w, DriveList)); + } auto *view = reinterpret_cast(GetWindowLongPtrW(w, GWLP_USERDATA)); if (!view) return DefWindowProcW(w, message, wp, lp); try @@ -261,6 +349,13 @@ LRESULT CALLBACK driveSettingsProc(HWND w, UINT message, WPARAM wp, LPARAM lp) updateDriveSyncControls(w, *view); } return 0; + case WM_NOTIFY: + { + const auto ¬ice = *reinterpret_cast(lp); + if (notice.idFrom == DriveList && notice.code == LVN_ITEMCHANGED) + updateDriveControls(w, *view); + break; + } case WM_COMMAND: { const auto id = LOWORD(wp); @@ -292,7 +387,7 @@ LRESULT CALLBACK driveSettingsProc(HWND w, UINT message, WPARAM wp, LPARAM lp) } return 0; } - if (id < DriveConnect || id > DriveDisconnect || HIWORD(wp) != BN_CLICKED || + if (((id < DriveConnect || id > DriveDisconnect) && id != DriveOlder) || HIWORD(wp) != BN_CLICKED || !IsWindowEnabled(GetDlgItem(w, id))) break; if (view->task) { @@ -302,7 +397,7 @@ LRESULT CALLBACK driveSettingsProc(HWND w, UINT message, WPARAM wp, LPARAM lp) updateDriveControls(w, *view); return 0; } - const auto action = id == DriveConnect ? DriveAction::Connect : id == DriveBackup ? DriveAction::Backup : + const auto action = id == DriveOlder ? DriveAction::Older : id == DriveConnect ? DriveAction::Connect : id == DriveBackup ? DriveAction::Backup : id == DriveRestore ? DriveAction::Restore : DriveAction::Disconnect; startDriveTask(w, *view, action); return 0; @@ -349,10 +444,23 @@ HWND createDriveSettings(HWND pane, SettingsView &settings) constexpr int left = DriveMargin, width = DriveSettingsWidth - 2 * left; settingsGroupLabel(w, L"Backup and restore", left, 14, width); label(w, L"Apply or Save your edits before backing them up.", left, 40, width); - edit(w, DriveStatus, left, 63, width, 54, ES_MULTILINE | ES_READONLY | WS_VSCROLL); + edit(w, DriveStatus, left, 63, width, 42, ES_MULTILINE | ES_READONLY | WS_VSCROLL); + const auto list = control(w, WC_LISTVIEWW, L"Google Drive backups", WS_TABSTOP | WS_BORDER | LVS_REPORT | + LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER, DriveList, left, 112, width, 90); + ListView_SetExtendedListViewStyle(list, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | LVS_EX_LABELTIP); + int columnIndex = 0; + for (const auto *title : {L"Backup date", L"Source", L"Size"}) + { + LVCOLUMNW column{LVCF_TEXT | LVCF_FMT}; + column.pszText = const_cast(title); + column.fmt = columnIndex == 2 ? LVCFMT_RIGHT : LVCFMT_LEFT; + ListView_InsertColumn(list, columnIndex++, &column); + } + fitDriveBackupColumns(list); + button(w, L"Load &older backups", DriveOlder, DriveLeftButton, DriveOlderTop, DriveButtonWidth); button(w, L"&Connect", DriveConnect, DriveLeftButton, DriveBackupActionsTop, DriveButtonWidth); button(w, L"Back &up saved settings", DriveBackup, DriveLeftButton, DriveBackupActionsTop + 31, DriveButtonWidth); - button(w, L"&Restore latest backup", DriveRestore, DriveRightButton, DriveBackupActionsTop, DriveButtonWidth); + button(w, L"&Restore selected backup", DriveRestore, DriveRightButton, DriveBackupActionsTop, DriveButtonWidth); button(w, L"&Disconnect", DriveDisconnect, DriveRightButton, DriveBackupActionsTop + 31, DriveButtonWidth); settingsGroupLabel(w, L"Automatic synchronization", left, DriveSyncTop, width); checkbox(w, L"&Use Google Drive for automatic synchronization", DriveAutomatic, left, DriveSyncTop + 27, width); @@ -383,9 +491,14 @@ int fitDriveSettings(HWND panel, int width, int height) auto &[child, bounds] = layout.controls[i]; const auto &original = layout.originalControls[i].bounds; const int id = GetDlgCtrlID(child); - if (original.top >= DriveBackupActionsTop) OffsetRect(&bounds, 0, extra); - if (id == DriveStatus) bounds.bottom += extra; - if (id == DriveStatus || id == DriveSyncStatus) bounds.right = width - DriveMargin; + if (original.top >= DriveOlderTop) OffsetRect(&bounds, 0, extra); + if (id == DriveList) bounds.bottom += extra; + if (id == DriveStatus || id == DriveSyncStatus || id == DriveList) bounds.right = width - DriveMargin; + if (id == DriveOlder) + { + bounds.left = (width - buttonWidth) / 2; + bounds.right = bounds.left + buttonWidth; + } if ((id >= DriveConnect && id <= DriveDisconnect) || (id >= DriveSyncNow && id <= DriveSyncConflicts)) { bounds.left = firstButton + (original.left == DriveRightButton ? buttonWidth + DriveButtonGap : 0); diff --git a/src/ui_mouse_buttons.inl b/src/ui_mouse_buttons.inl index 68167ff..3e2543e 100644 --- a/src/ui_mouse_buttons.inl +++ b/src/ui_mouse_buttons.inl @@ -378,7 +378,7 @@ void drawActionApplicationIcon(HWND editor, const DRAWITEMSTRUCT &item) FrameRect(item.hDC, &folder, ink); FillRect(item.hDC, &tab, ink); } - else if (item.CtlID == AppWindowPickerIcon) + else if (item.CtlID == AppWindowPickerIcon || item.CtlID == ClipboardAppPicker) { RECT target{x - half, y - half, x + half + 1, y + half + 1}; RECT horizontal{x - half - weight, y, x + half + weight + 1, y + 1}; diff --git a/tests/chat_profiles.cpp b/tests/chat_profiles.cpp index dff37bb..258f32f 100644 --- a/tests/chat_profiles.cpp +++ b/tests/chat_profiles.cpp @@ -26,6 +26,17 @@ void require(bool ok, const char *message) if (!ok) throw std::runtime_error(message); ++passed; } +void captureSettingsFixture(HWND window, const wchar_t *filename) +{ + RedrawWindow(window, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); + RECT area{}; + GetClientRect(window, &area); + const auto dc = GetDC(window); + const auto capture = ks::screenshotClip(dc, area.right, area.bottom, {}); + ReleaseDC(window, dc); + ks::atomicWrite(std::filesystem::path(ks::executable()).parent_path() / filename, + ks::encodePng(ks::decodeImage(capture))); +} void googleDriveWindowChecks(const std::filesystem::path &root) { ks::App app(GetModuleHandleW(nullptr), true, root); @@ -44,7 +55,7 @@ void googleDriveWindowChecks(const std::filesystem::path &root) "Google Drive opens inside Settings and hides OpenBao"); RECT panelBounds{}; GetWindowRect(drive, &panelBounds); - for (int id : {620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630}) + for (int id : {620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632}) { const auto control = GetDlgItem(drive, id); RECT bounds{}; @@ -75,23 +86,41 @@ void googleDriveWindowChecks(const std::filesystem::path &root) }; const auto backupStatus = GetDlgItem(drive, 624); const auto syncStatus = GetDlgItem(drive, 630); + const auto backupList = GetDlgItem(drive, 631); + require((GetWindowLongPtrW(backupList, GWL_STYLE) & LVS_TYPEMASK) == LVS_REPORT && + Header_GetItemCount(ListView_GetHeader(backupList)) == 3, + "backup history is a native report list with three columns"); + int columnIndex = 0; + for (const auto *expected : {L"Backup date", L"Source", L"Size"}) + { + wchar_t caption[48]{}; + LVCOLUMNW column{LVCF_TEXT}; + column.pszText = caption; + column.cchTextMax = std::size(caption); + require(ListView_GetColumn(backupList, columnIndex++, &column) && std::wstring_view(caption) == expected, + "the backup history columns identify the date, source and size"); + } const auto lastButton = GetDlgItem(drive, 629); resize(980, 650); const auto originalStatus = boundsOf(backupStatus); const auto originalSyncStatus = boundsOf(syncStatus); - resize(1100, 750); + const auto originalList = boundsOf(backupList); + resize(1100, 850); const auto expandedStatus = boundsOf(backupStatus); const auto expandedSyncStatus = boundsOf(syncStatus); - require((expandedStatus.bottom - expandedStatus.top) - (originalStatus.bottom - originalStatus.top) >= dips(80) && - expandedSyncStatus.bottom - expandedSyncStatus.top == originalSyncStatus.bottom - originalSyncStatus.top, - "raising the window grows the top status without stretching the lower status"); + const auto expandedList = boundsOf(backupList); + require((expandedList.bottom - expandedList.top) - (originalList.bottom - originalList.top) >= dips(40) && + std::abs((expandedStatus.bottom - expandedStatus.top) - (originalStatus.bottom - originalStatus.top)) <= dips(1) && + std::abs((expandedSyncStatus.bottom - expandedSyncStatus.top) - + (originalSyncStatus.bottom - originalSyncStatus.top)) <= dips(1), + "raising the window grows the backup list while keeping status fields compact"); const auto expandedPanel = boundsOf(drive); const auto bottom = boundsOf(lastButton).bottom; require(expandedPanel.bottom - bottom >= dips(18) && expandedPanel.bottom - bottom <= dips(22) && boundsOf(pane).bottom - bottom <= dips(35), "the action block stays against the viewport bottom"); - for (const auto &status : {expandedStatus, expandedSyncStatus}) + for (const auto &status : {expandedStatus, expandedList, expandedSyncStatus}) require(std::abs((expandedPanel.right - status.right) - (status.left - expandedPanel.left)) <= dips(2), - "both status fields stretch to the right margin"); + "the status fields and backup list stretch to the right margin"); for (const auto &[first, second] : {std::pair{620, 622}, {621, 623}, {626, 628}, {627, 629}}) { const auto left = boundsOf(GetDlgItem(drive, first)), right = boundsOf(GetDlgItem(drive, second)); @@ -99,20 +128,13 @@ void googleDriveWindowChecks(const std::filesystem::path &root) left.right < right.left, "each action row is horizontally centered"); } resize(640, 460); - const auto compactStatus = boundsOf(backupStatus); - require(compactStatus.bottom - compactStatus.top >= dips(53) && - (GetWindowLongPtrW(pane, GWL_STYLE) & WS_VSCROLL), "short windows keep a usable status field and scroll"); + const auto compactList = boundsOf(backupList); + require(compactList.bottom - compactList.top >= dips(89) && + (GetWindowLongPtrW(pane, GWL_STYLE) & WS_VSCROLL), "short windows keep a usable backup list and scroll"); SendMessageW(pane, WM_VSCROLL, SB_BOTTOM, 0); require(boundsOf(lastButton).bottom <= boundsOf(pane).bottom, "bottom actions remain reachable by scrolling"); - resize(1100, 750); - RedrawWindow(settings, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); - RECT area{}; - GetClientRect(settings, &area); - const auto dc = GetDC(settings); - const auto capture = ks::screenshotClip(dc, area.right, area.bottom, {}); - ReleaseDC(settings, dc); - ks::atomicWrite(std::filesystem::path(ks::executable()).parent_path() / L"settings-google-drive.png", - ks::encodePng(ks::decodeImage(capture))); + resize(1100, 850); + captureSettingsFixture(settings, L"settings-google-drive.png"); selectSettingsPage(settings, 17); const auto openBao = GetDlgItem(pane, 271); require(!IsWindowVisible(drive) && IsWindowVisible(openBao), "OpenBao is still accessible"); @@ -134,6 +156,7 @@ void googleDriveWindowChecks(const std::filesystem::path &root) SendMessageW(openBaoToggle, BM_CLICK, 0, 0); require(IsDlgButtonChecked(openBao, 601) == BST_CHECKED && IsDlgButtonChecked(drive, 625) == BST_UNCHECKED && !ks::syncVisible(root), "switching back clears Drive and leaves the saved provider intact until Apply"); + DestroyWindow(settings); } void settingsWindowStateChecks(const std::filesystem::path &root) { @@ -231,6 +254,79 @@ std::wstring pickTestApplication(HWND picker, bool cancel = false) DestroyWindow(target); return pickedApp; } +void settingsEditorResizeChecks(const std::filesystem::path &root) +{ + ks::App app(GetModuleHandleW(nullptr), true, root); + app.settings.toggle = app.settings.casing = app.settings.translit = app.settings.undo = L""; + app.settings.clipboard = app.settings.screenshot = L""; + app.settings.filesHotkey = L""; + app.settings.direct.assign(app.layouts.size(), L""); + ks::showSettings(app); + const auto settings = app.settingsWindow; + const auto pane = settingsViewport(settings); + const auto dips = [dpi = GetDpiForWindow(settings)](int n) { return MulDiv(n, dpi, 96); }; + const auto resize = [&](int height, int width = 1000) + { + SetWindowPos(settings, nullptr, 0, 0, dips(width), dips(height), SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER); + }; + const auto bounds = [](HWND window) + { + RECT result{}; + GetWindowRect(window, &result); + return result; + }; + const auto field = [&](int id) { return bounds(GetDlgItem(pane, id)); }; + const auto grows = [&](int page, int first, int second, int action) + { + selectSettingsPage(settings, page); + resize(610); + const auto before = field(first), otherBefore = field(second); + resize(760); + const auto after = field(first), otherAfter = field(second); + require(after.bottom - after.top - (before.bottom - before.top) >= dips(125), + "primary editor grows with the window"); + if (second) + require(otherAfter.bottom - otherAfter.top - (otherBefore.bottom - otherBefore.top) >= dips(125), + "second editor grows with the window"); + const auto bottom = action ? field(action).bottom : after.bottom; + require(bounds(pane).bottom - bottom <= dips(30) && bottom <= bounds(pane).bottom, + "the last editor or action row stays near the bottom"); + }; + grows(16, 416, 0, 0); + captureSettingsFixture(settings, L"settings-custom-replacements.png"); + grows(4, 301, 303, 320); + require(std::abs(field(310).top - field(320).top) <= dips(2), "snippet actions share the bottom row"); + captureSettingsFixture(settings, L"settings-snippets-responsive.png"); + grows(5, 731, 733, 739); + require(field(737).top >= field(731).bottom && field(740).top >= field(733).bottom, + "mouse test controls stay below the stretched lists"); + captureSettingsFixture(settings, L"settings-mouse-responsive.png"); + resize(760, 635); + require(field(731).bottom <= field(733).top, "narrow Mouse layout still stacks without overlap"); + resize(760); + + selectSettingsPage(settings, 3); + const HWND list = GetDlgItem(pane, 243); + const auto count = [&] { return SendMessageW(list, LB_GETCOUNT, 0, 0); }; + const auto initial = count(); + SetDlgItemTextW(pane, 244, L"Clipboard-Fixture.exe"); + SendDlgItemMessageW(pane, 245, BM_CLICK, 0, 0); + require(count() == initial + 1 && IsWindowEnabled(GetDlgItem(settings, SettingsApply)), + "manual clipboard exclusions update the Settings draft"); + SetDlgItemTextW(pane, 244, L"clipboard-fixture"); + SendDlgItemMessageW(pane, 245, BM_CLICK, 0, 0); + require(count() == initial + 1, "process names with and without .exe are deduplicated"); + SendDlgItemMessageW(pane, 246, BM_CLICK, 0, 0); + require(count() == initial, "remove deletes the selected exclusion"); + const auto picked = ks::snippetAppName(pickTestApplication(GetDlgItem(pane, 247))); + require(count() == initial + 1 && app.settings.excluded.size() == static_cast(initial), + "the shared crosshair adds a draft exclusion"); + SendMessageW(settings, WM_COMMAND, SettingsApply, 0); + require(app.settings.excluded.back() == picked && ks::loadSettings(root / L"settings.json", app.layouts).excluded == app.settings.excluded, + "applying persists the picked exclusion through normal Settings"); + captureSettingsFixture(settings, L"settings-clipboard-exclusions.png"); + DestroyWindow(settings); +} void lanWindowLayoutChecks(const std::filesystem::path &root) { const std::string peer(32,'b'); @@ -614,6 +710,7 @@ int main(int argc,char **argv) } contextChecks(); settingsWindowStateChecks(root / L"window-state"); + settingsEditorResizeChecks(root / L"responsive-editors"); { ks::App app(GetModuleHandleW(nullptr), true, root); require(!app.layouts.empty(), "installed layouts available");