mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-10 21:16:24 +02:00
Port the file browser spawned by the Load button to the new request stuff
This commit is contained in:
1 parent
47ae31e293
commit
70f0ac04af
12 files changed
+63
-17
No files matched your search
@@ -12,10 +12,10 @@ const char *RequestTypeAsString(SystemRequestType type) {
|
||||
}
|
||||
}
|
||||
|
||||
bool RequestManager::MakeSystemRequest(SystemRequestType type, RequestCallback callback, const std::string ¶m1, const std::string ¶m2) {
|
||||
bool RequestManager::MakeSystemRequest(SystemRequestType type, RequestCallback callback, const std::string ¶m1, const std::string ¶m2, int param3) {
|
||||
int requestId = idCounter_++;
|
||||
INFO_LOG(SYSTEM, "Making system request %s: id %d, callback_valid %d", RequestTypeAsString(type), requestId, callback != nullptr);
|
||||
if (!System_MakeRequest(type, requestId, param1, param2)) {
|
||||
if (!System_MakeRequest(type, requestId, param1, param2, param3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+13
-3
@@ -16,7 +16,7 @@ class RequestManager {
|
||||
public:
|
||||
// These requests are to be handled by platform implementations.
|
||||
// The callback you pass in will be called on the main thread later.
|
||||
bool MakeSystemRequest(SystemRequestType type, RequestCallback callback, const std::string ¶m1, const std::string ¶m2);
|
||||
bool MakeSystemRequest(SystemRequestType type, RequestCallback callback, const std::string ¶m1, const std::string ¶m2, int param3);
|
||||
|
||||
// Called by the platform implementation, when it's finished with a request.
|
||||
void PostSystemSuccess(int requestId, const char *responseString, int responseValue = 0);
|
||||
@@ -56,9 +56,19 @@ extern RequestManager g_requestManager;
|
||||
// Wrappers for easy requests.
|
||||
// NOTE: Semantics have changed - this no longer calls the callback on cancellation.
|
||||
inline void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, RequestCallback callback) {
|
||||
g_requestManager.MakeSystemRequest(SystemRequestType::INPUT_TEXT_MODAL, callback, title, defaultValue);
|
||||
g_requestManager.MakeSystemRequest(SystemRequestType::INPUT_TEXT_MODAL, callback, title, defaultValue, 0);
|
||||
}
|
||||
|
||||
inline void System_BrowseForImage(const std::string &title, RequestCallback callback) {
|
||||
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_IMAGE, callback, title, "");
|
||||
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_IMAGE, callback, title, "", 0);
|
||||
}
|
||||
|
||||
enum class BrowseFileType {
|
||||
BOOTABLE,
|
||||
INI,
|
||||
ANY,
|
||||
};
|
||||
|
||||
inline void System_BrowseForFile(const std::string &title, BrowseFileType type, RequestCallback callback) {
|
||||
g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FILE, callback, title, "", (int)type);
|
||||
}
|
||||
@@ -54,13 +54,14 @@ void System_LaunchUrl(LaunchUrlType urlType, const char *url);
|
||||
enum class SystemRequestType {
|
||||
INPUT_TEXT_MODAL,
|
||||
BROWSE_FOR_IMAGE,
|
||||
BROWSE_FOR_FILE,
|
||||
};
|
||||
|
||||
// Implementations are supposed to process the request, and post the response to the g_RequestManager (see Message.h).
|
||||
// This is not to be used directly by applications, instead use the g_RequestManager to make the requests.
|
||||
// This can return false if it's known that the platform doesn't support the request, the app is supposed to handle
|
||||
// or ignore that cleanly.
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2);
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3);
|
||||
|
||||
// TODO: To be separated into requests, see Request.h, and a way to post "UI messages".
|
||||
void System_SendMessage(const char *command, const char *parameter);
|
||||
|
||||
+1
-1
@@ -311,7 +311,7 @@ bool MainUI::HandleCustomEvent(QEvent *e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2) {
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) {
|
||||
switch (type) {
|
||||
case SystemRequestType::INPUT_TEXT_MODAL:
|
||||
{
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ void System_Vibrate(int length_ms) {
|
||||
// Ignore on PC
|
||||
}
|
||||
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2) { return false; }
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { return false; }
|
||||
|
||||
void System_SendMessage(const char *command, const char *parameter) {
|
||||
if (!strcmp(command, "toggle_fullscreen")) {
|
||||
|
||||
+6
-1
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "Common/System/Display.h"
|
||||
#include "Common/System/System.h"
|
||||
#include "Common/System/Request.h"
|
||||
#include "Common/System/NativeApp.h"
|
||||
#include "Common/Render/TextureAtlas.h"
|
||||
#include "Common/Render/DrawBuffer.h"
|
||||
#include "Common/UI/Root.h"
|
||||
@@ -1278,7 +1280,10 @@ void MainScreen::update() {
|
||||
|
||||
UI::EventReturn MainScreen::OnLoadFile(UI::EventParams &e) {
|
||||
if (System_GetPropertyBool(SYSPROP_HAS_FILE_BROWSER)) {
|
||||
System_SendMessage("browse_file", "");
|
||||
auto mm = GetI18NCategory("MainMenu");
|
||||
System_BrowseForFile(mm->T("Load"), BrowseFileType::BOOTABLE, [](const std::string &value, int) {
|
||||
NativeMessageReceived("boot", value.c_str());
|
||||
});
|
||||
}
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ void System_Notify(SystemNotification notification) {
|
||||
}
|
||||
}
|
||||
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2) { return false; }
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { return false; }
|
||||
|
||||
void System_SendMessage(const char *command, const char *parameter) {
|
||||
using namespace concurrency;
|
||||
|
||||
+33
-3
@@ -441,7 +441,7 @@ std::wstring MakeFilter(std::wstring filter) {
|
||||
return filter;
|
||||
}
|
||||
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2) {
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) {
|
||||
switch (type) {
|
||||
case SystemRequestType::INPUT_TEXT_MODAL:
|
||||
if (g_dialogRunning) {
|
||||
@@ -474,6 +474,38 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
|
||||
}
|
||||
});
|
||||
return true;
|
||||
case SystemRequestType::BROWSE_FOR_FILE:
|
||||
{
|
||||
BrowseFileType type = (BrowseFileType)param3;
|
||||
std::wstring filter;
|
||||
switch (type) {
|
||||
case BrowseFileType::BOOTABLE:
|
||||
filter = MakeFilter(L"All supported file types (*.iso *.cso *.pbp *.elf *.prx *.zip *.ppdmp)|*.pbp;*.elf;*.iso;*.cso;*.prx;*.zip;*.ppdmp|PSP ROMs (*.iso *.cso *.pbp *.elf *.prx)|*.pbp;*.elf;*.iso;*.cso;*.prx|Homebrew/Demos installers (*.zip)|*.zip|All files (*.*)|*.*||");
|
||||
break;
|
||||
case BrowseFileType::INI:
|
||||
filter = MakeFilter(L"Ini files (*.ini)|*.ini|All files (*.*)|*.*||");
|
||||
break;
|
||||
case BrowseFileType::ANY:
|
||||
filter = MakeFilter(L"All files (*.*)|*.*||");
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (g_dialogRunning) {
|
||||
g_dialogThread.join();
|
||||
}
|
||||
|
||||
g_dialogRunning = true;
|
||||
g_dialogThread = std::thread([=] {
|
||||
std::string out;
|
||||
if (W32Util::BrowseForFileName(true, MainWindow::GetHWND(), ConvertUTF8ToWString(param1).c_str(), nullptr, filter.c_str(), L"", out)) {
|
||||
g_requestManager.PostSystemSuccess(requestId, out.c_str());
|
||||
} else {
|
||||
g_requestManager.PostSystemFailure(requestId);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -503,8 +535,6 @@ void System_SendMessage(const char *command, const char *parameter) {
|
||||
} else if (!strcmp(command, "setclipboardtext")) {
|
||||
std::wstring data = ConvertUTF8ToWString(parameter);
|
||||
W32Util::CopyTextToClipboard(MainWindow::GetDisplayHWND(), data);
|
||||
} else if (!strcmp(command, "browse_file")) {
|
||||
MainWindow::BrowseAndBoot("");
|
||||
} else if (!strcmp(command, "browse_folder")) {
|
||||
auto mm = GetI18NCategory("MainMenu");
|
||||
std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), mm->T("Choose folder"));
|
||||
|
||||
@@ -1027,7 +1027,7 @@ extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_backbufferResize(JNIEnv
|
||||
}
|
||||
}
|
||||
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2) {
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) {
|
||||
switch (type) {
|
||||
case SystemRequestType::INPUT_TEXT_MODAL:
|
||||
{
|
||||
|
||||
@@ -116,7 +116,7 @@ bool System_GetPropertyBool(SystemProperty prop) {
|
||||
}
|
||||
void System_Notify(SystemNotification notification) {}
|
||||
void System_SendMessage(const char *command, const char *parameter) {}
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2) { return false; }
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { return false; }
|
||||
void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb) { cb(false, ""); }
|
||||
void System_AskForPermission(SystemPermission permission) {}
|
||||
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
|
||||
|
||||
@@ -1874,7 +1874,7 @@ void System_Notify(SystemNotification notification) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2) { return false; }
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { return false; }
|
||||
void System_SendMessage(const char *command, const char *parameter) {}
|
||||
void NativeUpdate() {}
|
||||
void NativeRender(GraphicsContext *graphicsContext) {}
|
||||
|
||||
@@ -42,7 +42,7 @@ void NativeRender(GraphicsContext *graphicsContext) { }
|
||||
void NativeResized() { }
|
||||
|
||||
void System_SendMessage(const char *command, const char *parameter) {}
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2) { return false; }
|
||||
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { return false; }
|
||||
void System_InputBoxGetString(const std::string &title, const std::string &defaultValue, std::function<void(bool, const std::string &)> cb) { cb(false, ""); }
|
||||
void System_AskForPermission(SystemPermission permission) {}
|
||||
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
|
||||
|
||||
Reference in new issue
Block a user