mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
CtrlLib: FileSelNative::ExecuteSelectDir
This commit is contained in:
parent
b170ee242b
commit
1be735e8a5
4 changed files with 80 additions and 23 deletions
|
|
@ -290,6 +290,7 @@ public:
|
|||
bool Execute(bool open, const char *title = NULL);
|
||||
bool ExecuteOpen(const char *title = NULL) { return Execute(true, title); }
|
||||
bool ExecuteSaveAs(const char *title = NULL) { return Execute(false, title); }
|
||||
bool ExecuteSelectDir(const char *title = NULL);
|
||||
|
||||
String Get() const;
|
||||
void Set(const String& s) { filename.At(0) = s; }
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@
|
|||
#include <commdlg.h>
|
||||
#include <cderr.h>
|
||||
|
||||
#define CY win32_CY_
|
||||
#include <ShlObj.h>
|
||||
#undef CY
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
@ -97,6 +101,53 @@ static UINT_PTR CALLBACK sCenterHook(HWND hdlg, UINT msg, WPARAM wParam, LPARAM
|
|||
#define OFN_ENABLESIZING 0x00800000
|
||||
#endif
|
||||
|
||||
INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
|
||||
{
|
||||
if (uMsg==BFFM_INITIALIZED) {
|
||||
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
|
||||
SendMessage(hwnd, BFFM_SETEXPANDED, TRUE, pData);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FileSelNative::ExecuteSelectDir(const char *title)
|
||||
{
|
||||
Vector<Vector<char16>> s16;
|
||||
auto W32 = [&](const String& s) -> char16* {
|
||||
auto& h = s16.Add();
|
||||
h = ToSystemCharsetW(s);
|
||||
return h;
|
||||
};
|
||||
|
||||
String ret;
|
||||
|
||||
BROWSEINFOW br;
|
||||
memset(&br, 0, sizeof(BROWSEINFO));
|
||||
Ctrl *q = Ctrl::GetActiveWindow();
|
||||
if(q) br.hwndOwner = q->GetHWND();
|
||||
br.lpfn = BrowseCallbackProc;
|
||||
br.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
|
||||
br.lpszTitle = W32(title);
|
||||
br.lParam = (LPARAM)W32(activedir);
|
||||
|
||||
LPITEMIDLIST pidl = NULL;
|
||||
if((pidl = SHBrowseForFolderW(&br)) != NULL) {
|
||||
char16 buffer[MAX_PATH];
|
||||
if(SHGetPathFromIDListW(pidl, buffer))
|
||||
filename << FromSystemCharsetW(buffer);
|
||||
else
|
||||
filename << Null;
|
||||
IMalloc *pMalloc;
|
||||
if(SHGetMalloc(&pMalloc) == NOERROR) {
|
||||
pMalloc->Free(pidl);
|
||||
pMalloc->Release();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileSelNative::Execute(bool open, const char *dlgtitle) {
|
||||
Vector<Vector<char16>> s16;
|
||||
auto W32 = [&](const String& s) -> char16* {
|
||||
|
|
|
|||
|
|
@ -1,23 +1,28 @@
|
|||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
FileSelNative sel;
|
||||
sel.AllFilesType();
|
||||
sel.Type("Test2", "*.tst");
|
||||
sel.Type("All", "*.*");
|
||||
sel.Type("All 2", "*");
|
||||
sel.ActiveType(1);
|
||||
while(sel.ExecuteSaveAs("Test!")) {
|
||||
for(int i = 0; i < sel.GetCount(); i++)
|
||||
DDUMP(sel[i]);
|
||||
sel.Multi();
|
||||
sel.NoAsking();
|
||||
}
|
||||
sel = GetDataFile("main.cpp");
|
||||
if(!sel.ExecuteSaveAs("as"))
|
||||
return;
|
||||
DDUMP(~sel);
|
||||
}
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
FileSelNative sel;
|
||||
sel.ActiveDir(GetHomeDirectory());
|
||||
while(sel.ExecuteSelectDir("Just a test"))
|
||||
PromptOK(sel.Get());
|
||||
|
||||
sel.AllFilesType();
|
||||
sel.Type("Test2", "*.tst");
|
||||
sel.Type("All", "*.*");
|
||||
sel.Type("All 2", "*");
|
||||
sel.ActiveType(1);
|
||||
|
||||
while(sel.ExecuteSaveAs("Test!")) {
|
||||
for(int i = 0; i < sel.GetCount(); i++)
|
||||
DDUMP(sel[i]);
|
||||
sel.Multi();
|
||||
sel.NoAsking();
|
||||
}
|
||||
sel = GetDataFile("main.cpp");
|
||||
if(!sel.ExecuteSaveAs("as"))
|
||||
return;
|
||||
DDUMP(~sel);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue