Release v0.6.33: warn about unsaved settings and expose menu access keys
This commit is contained in:
@@ -1654,6 +1654,7 @@ void App::trayMenu()
|
||||
GetCursorPos(&pt);
|
||||
pasteTarget = GetForegroundWindow();
|
||||
SetForegroundWindow(window);
|
||||
showMenuAccessKeys(menu);
|
||||
int cmd = TrackPopupMenu(menu, TPM_RETURNCMD | TPM_RIGHTBUTTON, pt.x, pt.y, 0, window, nullptr);
|
||||
DestroyMenu(menu);
|
||||
PostMessageW(window, WM_NULL, 0, 0);
|
||||
|
||||
@@ -159,6 +159,31 @@ void showRequestedWindow(HWND window)
|
||||
if (!IsWindowVisible(window))
|
||||
ShowWindow(window, SW_SHOW);
|
||||
}
|
||||
void showMenuAccessKeys(HMENU menu)
|
||||
{
|
||||
// Mouse-opened popups ignore the owner's keyboard-cue state.
|
||||
// Preserve the mnemonic and expose it in the right-hand hint column.
|
||||
for (int i = 0; i < GetMenuItemCount(menu); ++i)
|
||||
{
|
||||
if (auto child = GetSubMenu(menu, i)) showMenuAccessKeys(child);
|
||||
int length = GetMenuStringW(menu, i, nullptr, 0, MF_BYPOSITION);
|
||||
std::wstring text(length + 1, L'\0');
|
||||
GetMenuStringW(menu, i, text.data(), (int)text.size(), MF_BYPOSITION);
|
||||
text.resize(length);
|
||||
if (text.find(L'\t') != text.npos) continue;
|
||||
for (size_t p = 0; p + 1 < text.size(); ++p)
|
||||
{
|
||||
if (text[p] != L'&') continue;
|
||||
if (text[p + 1] == L'&') { ++p; continue; }
|
||||
text += L"\t" + upper(text.substr(p + 1, 1));
|
||||
MENUITEMINFOW item{sizeof(item)};
|
||||
item.fMask = MIIM_STRING;
|
||||
item.dwTypeData = text.data();
|
||||
SetMenuItemInfoW(menu, i, TRUE, &item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool activateWindow(HWND window)
|
||||
{
|
||||
if (!IsWindow(window))
|
||||
|
||||
@@ -38,6 +38,7 @@ HKL windowLayout(HWND);
|
||||
bool switchWindowLayout(HWND, HKL, const std::function<bool()> &valid);
|
||||
bool activateWindow(HWND);
|
||||
void showRequestedWindow(HWND);
|
||||
void showMenuAccessKeys(HMENU);
|
||||
bool ownsClipboard(HWND);
|
||||
bool webViewDescendant(DWORD owner, DWORD host,
|
||||
const std::function<std::optional<std::pair<DWORD, std::wstring>>(DWORD)> &read);
|
||||
|
||||
+43
-2
@@ -867,6 +867,7 @@ LRESULT CALLBACK historyProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
AppendMenuW(menu, MF_STRING, 113, L"&Delete");
|
||||
AppendMenuW(menu, MF_STRING, 114, selectedImage(w,v)?L"&Edit image in screenshot editor":L"&Open full item");
|
||||
AppendMenuW(menu, MF_STRING, 115, L"&Copy text from image (OCR)");
|
||||
showMenuAccessKeys(menu);
|
||||
int cmd = TrackPopupMenu(menu, TPM_RETURNCMD, p.x, p.y, 0, w, nullptr);
|
||||
DestroyMenu(menu);
|
||||
if (cmd)
|
||||
@@ -1338,6 +1339,46 @@ void showOcrOptions(HWND parent, SettingsView *v)
|
||||
showRequestedWindow(w); SetForegroundWindow(w);
|
||||
}
|
||||
#include "ui_sync.inl"
|
||||
bool settingsChanged(HWND w, SettingsView *v)
|
||||
{
|
||||
try
|
||||
{
|
||||
return encodeSettings(collectSettings(w, v)) != encodeSettings(v->app->settings);
|
||||
}
|
||||
catch (const std::exception &)
|
||||
{
|
||||
// Invalid edits are unsaved changes too. Allow discarding them without
|
||||
// requiring the user to repair the fields first.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
void closeSettings(HWND w, SettingsView *v)
|
||||
{
|
||||
if (settingsChanged(w, v))
|
||||
{
|
||||
int choice = MessageBoxW(w,
|
||||
L"You have unsaved settings changes. Save them before closing?\n\n"
|
||||
L"Yes: save and close.\nNo: discard changes.\nCancel: keep editing.",
|
||||
L"KSwitcher — Unsaved settings", MB_YESNOCANCEL | MB_ICONWARNING | MB_DEFBUTTON3);
|
||||
if (choice != IDYES && choice != IDNO)
|
||||
return;
|
||||
if (choice == IDYES)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (v->app->busy)
|
||||
throw std::runtime_error("Wait for the current text operation to finish");
|
||||
v->app->applySettings(collectSettings(w, v));
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
error(w, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
DestroyWindow(w);
|
||||
}
|
||||
LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
if (msg == WM_DPICHANGED)
|
||||
@@ -1403,7 +1444,7 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
}
|
||||
if (id == IDCANCEL)
|
||||
{
|
||||
DestroyWindow(w);
|
||||
closeSettings(w, v);
|
||||
return 0;
|
||||
}
|
||||
if (id == 250)
|
||||
@@ -1454,7 +1495,7 @@ LRESULT CALLBACK settingsProc(HWND w, UINT msg, WPARAM wp, LPARAM lp)
|
||||
break;
|
||||
}
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(w);
|
||||
closeSettings(w, v);
|
||||
return 0;
|
||||
case WM_NCDESTROY:
|
||||
disposeFont(w);
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
#include "platform.h"
|
||||
namespace ks
|
||||
{
|
||||
inline constexpr wchar_t AppVersion[] = L"0.6.32";
|
||||
inline constexpr wchar_t AppVersion[] = L"0.6.33";
|
||||
inline constexpr UINT UpdateMessage = WM_APP + 7;
|
||||
inline constexpr UINT UpdateCheckIntervalMs = 6 * 60 * 60 * 1000;
|
||||
inline constexpr UINT UpdateNotificationRetryMs = 5 * 60 * 1000;
|
||||
|
||||
Reference in New Issue
Block a user