Folder browser (like when clicking Browse...): Preinitialize with the current folder.

This commit is contained in:
Henrik Rydgård 2024-01-25 12:47:37 +01:00
parent 9218efd286
commit bc92226715
10 changed files with 49 additions and 27 deletions

View File

@ -138,3 +138,7 @@ void System_CreateGameShortcut(const Path &path, const std::string &title) {
void System_ShowFileInFolder(const Path &path) {
g_requestManager.MakeSystemRequest(SystemRequestType::SHOW_FILE_IN_FOLDER, NO_REQUESTER_TOKEN, nullptr, nullptr, path.ToString(), "", 0);
}
void System_BrowseForFolder(RequesterToken token, const std::string &title, const Path &initialPath, RequestCallback callback, RequestFailedCallback failedCallback) {
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FOLDER, token, callback, failedCallback, title, initialPath.ToCString(), 0);
}

View File

@ -107,9 +107,7 @@ inline void System_BrowseForFile(RequesterToken token, const std::string &title,
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FILE, token, callback, failedCallback, title, "", (int)type);
}
inline void System_BrowseForFolder(RequesterToken token, const std::string &title, RequestCallback callback, RequestFailedCallback failedCallback = nullptr) {
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FOLDER, token, callback, failedCallback, title, "", 0);
}
void System_BrowseForFolder(RequesterToken token, const std::string &title, const Path &initialPath, RequestCallback callback, RequestFailedCallback failedCallback = nullptr);
// The returned string is username + '\n' + password.
inline void System_AskUsernamePassword(RequesterToken token, const std::string &title, RequestCallback callback, RequestFailedCallback failedCallback = nullptr) {

View File

@ -713,7 +713,7 @@ std::string FileChooserChoice::ValueText() const {
FolderChooserChoice::FolderChooserChoice(RequesterToken token, std::string *value, const std::string &text, LayoutParams *layoutParams)
: AbstractChoiceWithValueDisplay(text, layoutParams), value_(value), token_(token) {
OnClick.Add([=](UI::EventParams &) {
System_BrowseForFolder(token_, text_, [=](const std::string &returnValue, int) {
System_BrowseForFolder(token_, text_, Path(*value), [=](const std::string &returnValue, int) {
if (*value_ != returnValue) {
*value = returnValue;
UI::EventParams e{};

View File

@ -1343,7 +1343,8 @@ UI::EventReturn GameSettingsScreen::OnSavePathOther(UI::EventParams &e) {
const Path &PPSSPPpath = File::GetExeDirectory();
if (otherinstalled_) {
auto di = GetI18NCategory(I18NCat::DIALOG);
std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), di->T("Choose PPSSPP save folder"));
std::string initialPath = g_Config.memStickDirectory.ToCString();
std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), di->T("Choose PPSSPP save folder"), initialPath);
if (folder.size()) {
g_Config.memStickDirectory = Path(folder);
FILE *f = File::OpenCFile(PPSSPPpath / "installed.txt", "wb");

View File

@ -604,7 +604,7 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) {
UI::EventReturn GameBrowser::BrowseClick(UI::EventParams &e) {
auto mm = GetI18NCategory(I18NCat::MAINMENU);
System_BrowseForFolder(token_, mm->T("Choose folder"), [this](const std::string &filename, int) {
System_BrowseForFolder(token_, mm->T("Choose folder"), path_.GetPath(), [this](const std::string &filename, int) {
this->SetPath(Path(filename));
});
return UI::EVENT_DONE;

View File

@ -418,7 +418,7 @@ UI::EventReturn MemStickScreen::UseStorageRoot(UI::EventParams &params) {
UI::EventReturn MemStickScreen::Browse(UI::EventParams &params) {
auto mm = GetI18NCategory(I18NCat::MAINMENU);
System_BrowseForFolder(GetRequesterToken(), mm->T("Choose folder"), [=](const std::string &value, int) {
System_BrowseForFolder(GetRequesterToken(), mm->T("Choose folder"), g_Config.memStickDirectory, [=](const std::string &value, int) {
Path pendingMemStickFolder = Path(value);
INFO_LOG(SYSTEM, "Got folder: '%s'", pendingMemStickFolder.c_str());
// Browse finished. Let's pop up the confirmation dialog.

View File

@ -333,7 +333,7 @@ namespace MainWindow {
W32Util::MakeTopMost(GetHWND(), false);
if (browseDirectory) {
System_BrowseForFolder(token, mm->T("Load"), [](const std::string &value, int) {
System_BrowseForFolder(token, mm->T("Load"), Path(), [](const std::string &value, int) {
BrowseAndBootDone(value);
});
} else {

View File

@ -14,18 +14,32 @@
namespace W32Util
{
std::string BrowseForFolder(HWND parent, const char *title)
{
std::string BrowseForFolder(HWND parent, std::string_view title, std::string_view initialPath) {
std::wstring titleString = ConvertUTF8ToWString(title);
return BrowseForFolder(parent, titleString.c_str());
return BrowseForFolder(parent, titleString.c_str(), initialPath);
}
std::string BrowseForFolder(HWND parent, const wchar_t *title)
{
static int CALLBACK BrowseFolderCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) {
if (uMsg == BFFM_INITIALIZED) {
LPCTSTR path = reinterpret_cast<LPCTSTR>(lpData);
::SendMessage(hwnd, BFFM_SETSELECTION, true, (LPARAM)path);
}
return 0;
}
std::string BrowseForFolder(HWND parent, const wchar_t *title, std::string_view initialPath) {
BROWSEINFO info{};
info.hwndOwner = parent;
info.lpszTitle = title;
info.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
info.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS | BIF_USENEWUI | BIF_NEWDIALOGSTYLE;
std::wstring initialPathW;
if (!initialPath.empty()) {
initialPathW = ConvertUTF8ToWString(initialPath);
info.lParam = reinterpret_cast<LPARAM>(initialPathW.c_str());
info.lpfn = BrowseFolderCallback;
}
//info.pszDisplayName
auto idList = SHBrowseForFolder(&info);

View File

@ -1,20 +1,25 @@
#pragma once
#include <string>
#include <string_view>
#include <vector>
#include <thread>
namespace W32Util
{
std::string BrowseForFolder(HWND parent, const char *title);
std::string BrowseForFolder(HWND parent, const wchar_t *title);
bool BrowseForFileName (bool _bLoad, HWND _hParent, const wchar_t*_pTitle,
const wchar_t *_pInitialFolder,const wchar_t *_pFilter,const wchar_t*_pExtension,
std::string& _strFileName);
std::vector<std::string> BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const wchar_t*_pTitle,
const wchar_t*_pInitialFolder,const wchar_t*_pFilter,const wchar_t*_pExtension);
namespace W32Util {
std::string UserDocumentsPath();
// Can't make initialPath a string_view, need the null so might as well require it.
std::string BrowseForFolder(HWND parent, std::string_view title, std::string_view initialPath);
std::string BrowseForFolder(HWND parent, const wchar_t *title, std::string_view initialPath);
bool CreateDesktopShortcut(const std::string &argumentPath, std::string gameTitle);
}
bool BrowseForFileName(bool _bLoad, HWND _hParent,
const wchar_t *_pTitle, const wchar_t *_pInitialFolder, const wchar_t *_pFilter, const wchar_t *_pExtension,
std::string& _strFileName);
std::vector<std::string> BrowseForFileNameMultiSelect(bool _bLoad, HWND _hParent, const wchar_t *_pTitle,
const wchar_t *_pInitialFolder, const wchar_t *_pFilter, const wchar_t *_pExtension);
std::string UserDocumentsPath();
bool CreateDesktopShortcut(const std::string &argumentPath, std::string gameTitle);
} // namespace

View File

@ -598,7 +598,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case SystemRequestType::BROWSE_FOR_FOLDER:
{
std::thread([=] {
std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), param1.c_str());
std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), param1, param2);
if (folder.size()) {
g_requestManager.PostSystemSuccess(requestId, folder.c_str());
} else {