From a97225c753999f02af30b11f976ce5253f943658 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 25 Apr 2023 11:15:38 +0300 Subject: [PATCH] [macOS] Implement OS::shell_show_in_file_manager() --- platform/macos/os_macos.h | 1 + platform/macos/os_macos.mm | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/platform/macos/os_macos.h b/platform/macos/os_macos.h index c539f7f529c..eb7a30203aa 100644 --- a/platform/macos/os_macos.h +++ b/platform/macos/os_macos.h @@ -98,6 +98,7 @@ public: virtual String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const override; virtual Error shell_open(String p_uri) override; + virtual Error shell_show_in_file_manager(String p_path, bool p_open_folder) override; virtual String get_locale() const override; diff --git a/platform/macos/os_macos.mm b/platform/macos/os_macos.mm index 71a250153bc..74cdef6f259 100644 --- a/platform/macos/os_macos.mm +++ b/platform/macos/os_macos.mm @@ -287,6 +287,27 @@ String OS_MacOS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const { return ret; } +Error OS_MacOS::shell_show_in_file_manager(String p_path, bool p_open_folder) { + bool open_folder = false; + if (DirAccess::dir_exists_absolute(p_path) && p_open_folder) { + open_folder = true; + } + + if (!p_path.begins_with("file://")) { + p_path = String("file://") + p_path; + } + + NSString *string = [NSString stringWithUTF8String:p_path.utf8().get_data()]; + NSURL *uri = [[NSURL alloc] initWithString:[string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]]; + + if (open_folder) { + [[NSWorkspace sharedWorkspace] openURL:uri]; + } else { + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[ uri ]]; + } + return OK; +} + Error OS_MacOS::shell_open(String p_uri) { NSString *string = [NSString stringWithUTF8String:p_uri.utf8().get_data()]; NSURL *uri = [[NSURL alloc] initWithString:string];