|
56 | 56 | #include <stdio.h>
|
57 | 57 | #include <windows.h>
|
58 | 58 | #include <process.h>
|
| 59 | +#include <ShlObj.h> // used for OS_Request_Dir |
59 | 60 |
|
60 | 61 | #include "reb-host.h"
|
61 | 62 | #include "host-lib.h"
|
@@ -1331,3 +1332,65 @@ static void *Task_Ready;
|
1331 | 1332 | return ret;
|
1332 | 1333 | }
|
1333 | 1334 |
|
| 1335 | +static LPITEMIDLIST lpLastBrowseFolder = NULL; |
| 1336 | +static BOOL bBrowseFolderInit = FALSE; |
| 1337 | +static BFFCALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { |
| 1338 | + // Using this callback to set default folder. |
| 1339 | + // The SendMessage in BFFM_SELCHANGED is there to update focus on the directory |
| 1340 | + // Without it it would select the folder on init, but the folder could not be visible. |
| 1341 | + REBOOL set = FALSE; |
| 1342 | + |
| 1343 | + switch (uMsg) { |
| 1344 | + case BFFM_INITIALIZED: |
| 1345 | + bBrowseFolderInit = TRUE; |
| 1346 | + set = TRUE; |
| 1347 | + break; |
| 1348 | + case BFFM_SELCHANGED: |
| 1349 | + if (bBrowseFolderInit) { |
| 1350 | + bBrowseFolderInit = FALSE; |
| 1351 | + set = TRUE; |
| 1352 | + } |
| 1353 | + break; |
| 1354 | + } |
| 1355 | + if (lpData && set) { |
| 1356 | + SendMessage(hwnd, BFFM_SETSELECTION, lpLastBrowseFolder != lpData, lpData); |
| 1357 | + } |
| 1358 | + return 0; |
| 1359 | +} |
| 1360 | +/*********************************************************************** |
| 1361 | +** |
| 1362 | +*/ REBOOL OS_Request_Dir(REBRFR *fr) |
| 1363 | +/* |
| 1364 | +***********************************************************************/ |
| 1365 | +{ |
| 1366 | + BROWSEINFO bInfo = {0}; |
| 1367 | + REBOOL keep = GET_FLAG(fr->flags, FRF_KEEP); |
| 1368 | + REBCHR *dir = fr->dir; |
| 1369 | + |
| 1370 | + //bInfo.hwndOwner = Owner window // Must find a way to set this |
| 1371 | + bInfo.pidlRoot = NULL; |
| 1372 | + bInfo.pszDisplayName = fr->files; // Address of a buffer to receive the name of the folder selected by the user |
| 1373 | + bInfo.lpszTitle = fr->title; // Title of the dialog |
| 1374 | + bInfo.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS; |
| 1375 | + bInfo.lpfn = BrowseCallbackProc; |
| 1376 | + // start in dir location is used /dir |
| 1377 | + // else use last keeped result if used /keep |
| 1378 | + // else NULL if no /keep and /dir is there |
| 1379 | + bInfo.lParam = (dir) ? dir : (keep) ? lpLastBrowseFolder : NULL; |
| 1380 | + bInfo.iImage = -1; |
| 1381 | + |
| 1382 | + LPITEMIDLIST lpItem = SHBrowseForFolder( &bInfo); |
| 1383 | + if(lpItem == NULL) { |
| 1384 | + // nothing selected |
| 1385 | + return FALSE; |
| 1386 | + } |
| 1387 | + if (keep) { |
| 1388 | + // release last result if there was any |
| 1389 | + if(lpLastBrowseFolder) |
| 1390 | + CoTaskMemFree(lpLastBrowseFolder); |
| 1391 | + // and store result for next request |
| 1392 | + lpLastBrowseFolder = lpItem; |
| 1393 | + } |
| 1394 | + SHGetPathFromIDList(lpItem, fr->files); |
| 1395 | + return TRUE; |
| 1396 | +} |
0 commit comments