Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Implement OS::shell_show_in_file_manager() #76428

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/macos/os_macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class OS_MacOS : public OS_Unix {
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;

Expand Down
21 changes: 21 additions & 0 deletions platform/macos/os_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,27 @@
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];
Expand Down