mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-19 04:53:12 +01:00
Merge pull request #12491 from janisozaur/openurl
Add OpenURL method, with implementation for Linux and Windows
This commit is contained in:
@@ -65,6 +65,11 @@ namespace OpenRCT2::Ui
|
||||
void OpenFolder(const std::string& path) override
|
||||
{
|
||||
}
|
||||
|
||||
void OpenURL(const std::string& url) override
|
||||
{
|
||||
STUB();
|
||||
}
|
||||
};
|
||||
|
||||
IPlatformUiContext* CreatePlatformUiContext()
|
||||
|
||||
@@ -119,6 +119,12 @@ namespace OpenRCT2::Ui
|
||||
Execute(cmd);
|
||||
}
|
||||
|
||||
void OpenURL(const std::string& url) override
|
||||
{
|
||||
std::string cmd = String::Format("xdg-open %s", url.c_str());
|
||||
Execute(cmd);
|
||||
}
|
||||
|
||||
std::string ShowFileDialog(SDL_Window* window, const FileDialogDesc& desc) override
|
||||
{
|
||||
std::string result;
|
||||
|
||||
@@ -97,6 +97,12 @@ namespace OpenRCT2::Ui
|
||||
ShellExecuteW(NULL, L"open", pathW.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
void OpenURL(const std::string& url) override
|
||||
{
|
||||
std::wstring urlW = String::ToWideChar(url);
|
||||
ShellExecuteW(NULL, L"open", urlW.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||
}
|
||||
|
||||
std::string ShowFileDialog(SDL_Window* window, const FileDialogDesc& desc) override
|
||||
{
|
||||
std::wstring wcFilename = String::ToWideChar(desc.DefaultFilename);
|
||||
|
||||
@@ -609,6 +609,11 @@ public:
|
||||
_platformUiContext->OpenFolder(path);
|
||||
}
|
||||
|
||||
void OpenURL(const std::string& url) override
|
||||
{
|
||||
_platformUiContext->OpenURL(url);
|
||||
}
|
||||
|
||||
std::string ShowFileDialog(const FileDialogDesc& desc) override
|
||||
{
|
||||
return _platformUiContext->ShowFileDialog(_window, desc);
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace OpenRCT2
|
||||
|
||||
virtual void ShowMessageBox(SDL_Window * window, const std::string& message) abstract;
|
||||
virtual void OpenFolder(const std::string& path) abstract;
|
||||
virtual void OpenURL(const std::string& url) abstract;
|
||||
virtual std::string ShowFileDialog(SDL_Window * window, const FileDialogDesc& desc) abstract;
|
||||
virtual std::string ShowDirectoryDialog(SDL_Window * window, const std::string& title) abstract;
|
||||
};
|
||||
|
||||
@@ -19,9 +19,12 @@
|
||||
# undef interface
|
||||
# undef abstract
|
||||
|
||||
# include <ApplicationServices/ApplicationServices.h>
|
||||
# import <Cocoa/Cocoa.h>
|
||||
# include <CoreFoundation/CFBundle.h>
|
||||
# include <SDL.h>
|
||||
# include <mach-o/dyld.h>
|
||||
# include <string>
|
||||
|
||||
namespace OpenRCT2::Ui
|
||||
{
|
||||
@@ -71,6 +74,14 @@ namespace OpenRCT2::Ui
|
||||
}
|
||||
}
|
||||
|
||||
void OpenURL(const std::string& url) override
|
||||
{
|
||||
CFURLRef urlRef = CFURLCreateWithBytes(
|
||||
nullptr, reinterpret_cast<const UInt8*>(url.c_str()), url.length(), kCFStringEncodingUTF8, nullptr);
|
||||
LSOpenCFURLRef(urlRef, 0);
|
||||
CFRelease(urlRef);
|
||||
}
|
||||
|
||||
std::string ShowFileDialog(SDL_Window* window, const FileDialogDesc& desc) override
|
||||
{
|
||||
@autoreleasepool
|
||||
|
||||
@@ -92,6 +92,9 @@ namespace OpenRCT2::Ui
|
||||
void OpenFolder(const std::string& /*path*/) override
|
||||
{
|
||||
}
|
||||
void OpenURL(const std::string& /*url*/) override
|
||||
{
|
||||
}
|
||||
std::string ShowFileDialog(const FileDialogDesc& /*desc*/) override
|
||||
{
|
||||
return std::string();
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace OpenRCT2
|
||||
|
||||
virtual void ShowMessageBox(const std::string& message) abstract;
|
||||
virtual void OpenFolder(const std::string& path) abstract;
|
||||
virtual void OpenURL(const std::string& url) abstract;
|
||||
virtual std::string ShowFileDialog(const FileDialogDesc& desc) abstract;
|
||||
virtual std::string ShowDirectoryDialog(const std::string& title) abstract;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user