Skip to content

Commit 0faf2d2

Browse files
committed
CollectionInterface: overrideMap = get it working in the non-delayed version; NEXT = work on the write-protected delay
1 parent 34fdb2e commit 0faf2d2

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/Dialogs/CollectionInterfaceDialog.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <CommCtrl.h>
3030
#include <Shlwapi.h>
3131
#include "NppMetaClass.h"
32+
#include "OverrideMapUpdaterClass.h"
3233

3334

3435
HWND g_hwndCIDlg = nullptr, g_hwndCIHlpDlg = nullptr;
@@ -252,8 +253,10 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
252253
}
253254
case IDC_CI_BTN_DOWNLOAD:
254255
{
256+
bool doAskOverrideMap = false, doUpdateOverrideMap = false;
255257
std::wstring wsCategory = _get_tab_category_wstr(hwndDlg, IDC_CI_TABCTRL);
256258
HWND hwLBFile = GetDlgItem(hwndDlg, IDC_CI_COMBO_FILE);
259+
OverrideMapUpdater* pobjOvMapUpdater = nullptr;
257260

258261
// prepare for N selections
259262
std::vector<int> vBuf;
@@ -326,8 +329,11 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
326329
if (isEN && isCHK && pobjCI->mapFL.count(ws_id_name)) {
327330
alsoDownload[L"FL"][L"URL"] = pobjCI->mapFL[ws_id_name];
328331
alsoDownload[L"FL"][L"PATH"] = gNppMetaInfo.dir.cfgFunctionList + L"\\" + ws_id_name + L".xml";
332+
alsoDownload[L"FL"][L"DISPLAY"] = wsFilename;
329333
extraWritable[L"FL"] = pobjCI->isFunctionListDirWritable();
330334
total++;
335+
// if there are any FunctionList files, need to ask about overrideMap.xml
336+
doAskOverrideMap = true;
331337
}
332338
}
333339
else if (wsCategory == L"AutoCompletion") {
@@ -351,6 +357,9 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
351357

352358
wsPath = gNppMetaInfo.dir.cfgFunctionList + L"\\" + ws_id_name + L".xml";
353359
isWritable = pobjCI->isFunctionListDirWritable();
360+
361+
// if there are any FunctionList files, need to ask about overrideMap.xml
362+
doAskOverrideMap = true;
354363
}
355364
else if (wsCategory == L"Theme") {
356365
wsURL = L"https://raw.githubusercontent.com/notepad-plus-plus/nppThemes/main/themes/" + wsFilename;
@@ -359,19 +368,31 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
359368
isWritable = pobjCI->isThemesDirWritable();
360369
}
361370

371+
// ask about override map, but only once per **DOWNLOAD** click
372+
if (doAskOverrideMap && !doUpdateOverrideMap) {
373+
std::wstring msg = L"You are downloading one or more FunctionList files.\r\n\r\nWould you like to update your overrideMap.xml to reference the new file(s)?";
374+
int iMB_ret = ::MessageBox(hwndDlg, msg.c_str(), L"Update overrideMap?", MB_YESNO);
375+
doUpdateOverrideMap = (iMB_ret == IDYES);
376+
if (doUpdateOverrideMap)
377+
pobjOvMapUpdater = new OverrideMapUpdater;
378+
}
379+
362380
int count = 0;
363381
if (isWritable) {
364382
// download directly to the final destination
365383
didDownload |= pobjCI->downloadFileToDisk(wsURL, wsPath);
366-
std::wstring msg = L"Downloaded to " + wsPath;
367-
//::MessageBox(hwndDlg, msg.c_str(), L"Download Successful", MB_OK);
368384
count++;
385+
386+
// For FL downloads, need to add the association here if overrideMap-updating is enabled
387+
if (doUpdateOverrideMap && (wsCategory == L"FunctionList"))
388+
pobjOvMapUpdater->add_udl_assoc(ws_id_name + L".xml", wsFilename);
369389
}
370390
else {
371391
// check if it needs to be overwritten before elevating permissions
372392
if (pobjCI->ask_overwrite_if_exists(wsPath)) {
373393
mapUacDelayed[wsURL] = wsPath;
374394
total--;
395+
// TODO: need to add a delayed-FL-ov map as well
375396
}
376397
else {
377398
total--;
@@ -397,11 +418,20 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
397418
pobjCI->downloadFileToDisk(xURL, xPath);
398419
count++;
399420
didDownload = true;
421+
422+
// For xtra[FL], need to add the association here if overrideMap-updating is enabled
423+
if (doUpdateOverrideMap && (category == L"FL"))
424+
{
425+
std::wstring xDisp = alsoDownload[category][L"DISPLAY"];
426+
pobjOvMapUpdater->add_udl_assoc(ws_id_name + L".xml", xDisp);
427+
}
428+
400429
}
401430
else {
402431
if (pobjCI->ask_overwrite_if_exists(xPath)) {
403432
mapUacDelayed[xURL] = xPath;
404433
total--;
434+
// TODO: need to add a delayed-FL-ov map as well
405435
}
406436
else {
407437
total--;
@@ -464,9 +494,18 @@ INT_PTR CALLBACK ciDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
464494
::SendDlgItemMessage(hwndDlg, IDC_CI_PROGRESSBAR, PBM_SETPOS, 100, 0);
465495
swprintf_s(wcDLPCT, L"Downloading %d%% [DONE]", 100);
466496
Edit_SetText(GetDlgItem(hwndDlg, IDC_CI_PROGRESSLBL), wcDLPCT);
497+
498+
if (doUpdateOverrideMap)
499+
pobjOvMapUpdater->add_udl_assoc(mapUacDelayed);
500+
467501
}
468502
}
469503

504+
if (doUpdateOverrideMap) {
505+
// need to save the overrideMap.xml at the end, whether
506+
// it's been updating the XML one-at-a-time, or delayed until the end
507+
pobjOvMapUpdater->saveFile();
508+
}
470509
return true;
471510
}
472511
case IDC_CI_HELPBTN:

0 commit comments

Comments
 (0)