@@ -362,3 +362,64 @@ nfdresult_t NFD_SaveDialog( const nfdchar_t *filterList,
362362 NFDi_SetError (" Got invalid response from port" );
363363 return NFD_ERROR;
364364}
365+
366+
367+ /* single folder open dialog */
368+ nfdresult_t NFD_PickFolder ( const nfdchar_t *defaultPath,
369+ nfdchar_t **outPath )
370+ {
371+ BApplication *temporaryApp = NULL ;
372+ if (be_app == NULL ) {
373+ temporaryApp = new BApplication (" application/x-vnd.nfd-dialog" );
374+ }
375+
376+ DialogHandler *handler = new DialogHandler ();
377+ BMessenger messenger (handler);
378+ BFilePanel *panel = new BFilePanel (B_OPEN_PANEL, NULL , NULL , B_DIRECTORY_NODE, false , NULL , NULL , true );
379+
380+ handler->Run ();
381+ panel->SetTarget (messenger);
382+
383+ if (defaultPath != NULL ) {
384+ BEntry directory (defaultPath, true );
385+ panel->SetPanelDirectory (&directory);
386+ }
387+
388+ panel->Show ();
389+
390+ handler->Wait ();
391+
392+ response_data data = handler->ResponseData ();
393+ int32 response = handler->ResponseId ();
394+ handler->PostMessage (B_QUIT_REQUESTED);
395+
396+ if (temporaryApp)
397+ delete temporaryApp;
398+
399+ delete panel;
400+
401+ switch (response) {
402+ case kCancelResponse :
403+ return NFD_CANCEL;
404+ case kOpenResponse : {
405+ if (data.open .count != 1 ) {
406+ delete[] data.open .refs ;
407+
408+ NFDi_SetError (" Got invalid count of refs back" );
409+ return NFD_ERROR;
410+ }
411+
412+ BPath path (&data.open .refs [0 ]);
413+ size_t length = NFDi_UTF8_Strlen ((nfdchar_t *)path.Path ()) + 1 ;
414+
415+ *outPath = (nfdchar_t *)NFDi_Malloc (length);
416+ NFDi_SafeStrncpy (*outPath, path.Path (), length);
417+
418+ delete[] data.open .refs ;
419+ return NFD_OKAY;
420+ }
421+ }
422+
423+ NFDi_SetError (" Got invalid response from port" );
424+ return NFD_ERROR;
425+ }
0 commit comments