From 39d3b217801f80f43f2efc4a1fe26a0d4cb2d6fe Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 6 Jul 2021 15:44:21 +0200 Subject: [PATCH 1/3] Convert URLs to paths returned from `NSOpenPanel` using `[Url path]` --- gpui/src/platform/mac/platform.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gpui/src/platform/mac/platform.rs b/gpui/src/platform/mac/platform.rs index e7ccd280b4..94a6cec8a7 100644 --- a/gpui/src/platform/mac/platform.rs +++ b/gpui/src/platform/mac/platform.rs @@ -283,13 +283,10 @@ impl platform::Platform for MacPlatform { let urls = panel.URLs(); for i in 0..urls.count() { let url = urls.objectAtIndex(i); - let string = url.absoluteString(); - let string = std::ffi::CStr::from_ptr(string.UTF8String()) + let path = std::ffi::CStr::from_ptr(url.path().UTF8String()) .to_string_lossy() .to_string(); - if let Some(path) = string.strip_prefix("file://") { - result.push(PathBuf::from(path)); - } + result.push(PathBuf::from(path)); } Some(result) } else { From ed1eb24ee26b46823d65f8124d505f0db8fcd3f5 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 6 Jul 2021 15:48:07 +0200 Subject: [PATCH 2/3] Convert URLs to paths returned from `NSSavePanel` using `[Url path]` --- gpui/src/platform/mac/platform.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gpui/src/platform/mac/platform.rs b/gpui/src/platform/mac/platform.rs index 94a6cec8a7..7e973ceacf 100644 --- a/gpui/src/platform/mac/platform.rs +++ b/gpui/src/platform/mac/platform.rs @@ -317,15 +317,10 @@ impl platform::Platform for MacPlatform { let block = ConcreteBlock::new(move |response: NSModalResponse| { let result = if response == NSModalResponse::NSModalResponseOk { let url = panel.URL(); - let string = url.absoluteString(); - let string = std::ffi::CStr::from_ptr(string.UTF8String()) + let path = std::ffi::CStr::from_ptr(url.path().UTF8String()) .to_string_lossy() .to_string(); - if let Some(path) = string.strip_prefix("file://") { - Some(PathBuf::from(path)) - } else { - None - } + Some(PathBuf::from(path)) } else { None }; From 75fc371f3627fa70ae79b2e82f12095f24ee536f Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 6 Jul 2021 16:08:19 +0200 Subject: [PATCH 3/3] Ensure returned URLs are files before returning them in path prompts --- gpui/src/platform/mac/platform.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/gpui/src/platform/mac/platform.rs b/gpui/src/platform/mac/platform.rs index 7e973ceacf..dffa2c4a6a 100644 --- a/gpui/src/platform/mac/platform.rs +++ b/gpui/src/platform/mac/platform.rs @@ -7,7 +7,7 @@ use cocoa::{ NSEventModifierFlags, NSMenu, NSMenuItem, NSModalResponse, NSOpenPanel, NSPasteboard, NSPasteboardTypeString, NSSavePanel, NSWindow, }, - base::{id, nil, selector}, + base::{id, nil, selector, YES}, foundation::{NSArray, NSAutoreleasePool, NSData, NSInteger, NSString, NSURL}, }; use ctor::ctor; @@ -283,10 +283,12 @@ impl platform::Platform for MacPlatform { let urls = panel.URLs(); for i in 0..urls.count() { let url = urls.objectAtIndex(i); - let path = std::ffi::CStr::from_ptr(url.path().UTF8String()) - .to_string_lossy() - .to_string(); - result.push(PathBuf::from(path)); + if url.isFileURL() == YES { + let path = std::ffi::CStr::from_ptr(url.path().UTF8String()) + .to_string_lossy() + .to_string(); + result.push(PathBuf::from(path)); + } } Some(result) } else { @@ -317,10 +319,14 @@ impl platform::Platform for MacPlatform { let block = ConcreteBlock::new(move |response: NSModalResponse| { let result = if response == NSModalResponse::NSModalResponseOk { let url = panel.URL(); - let path = std::ffi::CStr::from_ptr(url.path().UTF8String()) - .to_string_lossy() - .to_string(); - Some(PathBuf::from(path)) + if url.isFileURL() == YES { + let path = std::ffi::CStr::from_ptr(url.path().UTF8String()) + .to_string_lossy() + .to_string(); + Some(PathBuf::from(path)) + } else { + None + } } else { None };