Add Drive backup history and make Settings editors resize

Refs #84
This commit is contained in:
agrynco committed 2026-11-24 22:42:30 +02:00
1 parent 5fae129ec0
commit 696f48209d
9 files changed
+466 -113

No files matched your search

+122 -26
View File
@@ -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<int> editors, bool stacked)
{
if (extra <= 0) return;
int remaining = extra, count = static_cast<int>(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<SettingsView *>(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<int>(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<int>(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<LPARAM>(name.c_str()));
if (selected >= 0 && !view.draft.excluded.empty())
SendMessageW(list, LB_SETCURSEL, std::min(selected, static_cast<int>(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<int>(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<std::wstring> 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<HWND>(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<const DRAWITEMSTRUCT *>(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<size_t>(row) < v->draft.excluded.size())
{
v->draft.excluded.erase(v->draft.excluded.begin() + row);
fillClipboardApps(*v, static_cast<int>(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<LPARAM>(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};