Customise NSPathControl
I found the solution and posted it on github.
I subclassed from NSPathControl. It's pretty simple actually.
NSPathControl and Auto Layout
Solution
Sorry, I guess I asked to fast.
I got it working like this:
NSPathControl subclass
- (NSSize)intrinsicContentSize {
return NSMakeSize(NSViewNoInstrinsicMetric, NSViewNoInstrinsicMetric);
}
SwiftUI NSPathControl open finder location when clicking icons
You can use the Coordinator
pattern with NSViewRepresentable
:
struct PathView: NSViewRepresentable {
var configuration = { (view: NSPathControl) in }
func makeNSView(context: NSViewRepresentableContext<PathView>) -> NSPathControl {
let pathControl = NSPathControl()
pathControl.target = context.coordinator
pathControl.action = #selector(Coordinator.action)
return pathControl
}
func updateNSView(_ nsView: NSPathControl, context: NSViewRepresentableContext<PathView>) {
configuration(nsView)
}
func makeCoordinator() -> Coordinator {
return Coordinator()
}
class Coordinator : NSObject, NSPathControlDelegate {
@objc func action(sender: NSPathControl) {
if let url = sender.clickedPathItem?.url {
print(url)
NSWorkspace.shared.selectFile(url.path, inFileViewerRootedAtPath: url.path)
}
}
}
}
Note: I'm not actually using any NSPathControlDelegate
methods -- that's just to show that it could be extended to be a delegate as well
How to set the URL of a NSPathComponentCell?
- If you want to display a valid URL, just set the
URL
property of theNSPathControl
instance with anNSURL
object - If you want to display relative paths or other invalid URLs, look at the Apple sample code NSPathControl Basics
Related Topics
Hmac Sha512 Using Commoncrypto in Swift 3.1
Play Mp4 Using Mpmovieplayercontroller() in Swift
Convert Swift Dictionary to Nsdictionary
Adding Animation to Tabviews in Swiftui When Switching Between Tabs
How to Capture Multiple Arguments Weakly in a Swift Closure
Firebase Crashlytics Not Showing Crash Report in Console Dashboard Swift
Manually Disposing a Disposebag in Rxswift
How to Trigger Xcode's 'Update to Latest Package Versions' from Command Line
Integer Literal Overflows When Stored into 'Int'
Swift Unit Testing with Xctassertthrows Analogue
Nssortdescriptor Sorting Using Nsdate in Swift
Convert String to Staticstring
How to Compare Cgpoints in Swift
How to Get Walking and Running Distance Using Healthkit in Swift