Post

Replies

Boosts

Views

Activity

SwiftUI Table - Double Click Row While Retaining Single Click Selection Behavior
I have an AppKit application that I'm converting to SwiftUI and I'm having some difficulty understanding how to model a Table with single click and double click behavior. My table is relatively simple, it has 3 columns (possibly more in the future), the first with an icon, and the latter two with text. The two text fields are sortable, and the table requires multi-selection and row-based keybindings (return, delete), as well as double-click. The first surprising thing is that I cannot add those behaviors on the TableRow or even the TableCell but rather the views inside of them. That means the subviews must occupy the entire TableCell or else they will not capture the click event. That means repeating the same gestures for the contents of every cell (or wrapping all with the same view)? The second surprise is that adding an onTapGesture(count: 2) prevents the default row selection gesture from firing. Do I really need to re-implement row selection if I want double click support as well? Adding a onTapGesture(count: 2) to the Table itself (analogous to NSTableView -setDoubleAction:) has no effect that I can tell. I'm hoping I'm missing something. Supporting selection and double-click seems like table-stakes for a table view.
2
3
1.7k
Jun ’22
Opening a Volume Folder in Finder
I'm trying to open a folder from my app, but when I call selectFile(_:inFileViewerRootedAtPath:) with a fullPath set to nil and rootFullPath set to a volume mount point in Volumes or a sub-folder of Volumes, it always returns false and I see the following errors in Console: error 22:31:16.832634-0700 CoreServicesUIAgent Failed to open document <private> because the calling process does not have sandbox access at its location. error 22:31:16.833025-0700 CoreServicesUIAgent LAUNCH: Launch failed in CSUI with error Error Domain=NSOSStatusErrorDomain Code=-54 "permErr: permissions error (on file open)" UserInfo={_LSLine=4101, _LSFunction=_LSOpenStuffCallLocal} The related code is simple: @IBAction func open(_ sender: NSMenuItem) { let volume = sender.representedObject as! Volume if !NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: volume.url.path) { print("could not open \(volume.url.path)") } } This may be related to #190213022, however, there is no discussion there. Passing the same directory path as for fullPath as rootFullPath opens a the parent folder of the one I'm interested in with the folder I'd like to open selected. That's nice, but not what I want to do. If I know the name of a file on the volume and pass that in fullPath, the folder will be opened as expected. My app is sandboxed and has no read permissions for any files or folders. I don't have any need to read any user files, so I'd prefer not to have to add a request for full disk access just to display a folder. As far as I can tell activateFileViewerSelecting(_:) can only select files and cannot open a folder with no files selected. If I did know the name of a file in the folder, this will open the folder with that file selected, even if it's in the root of a mounted volume. It seems like an odd restriction to allow opening a Folder with a file selected but not the same Folder with no file selected. open(_:) and friends produce an alert indicating I don't have permission to open the folder. This happens regardless of whether I set .promptsUserIfNeeded or not. I could go the AppleEvent route and tell Finder to open the folder, but again, that would require a permission I don't currently have, don't need, and don't really want, plus, that seems rather silly. Are there any other options? This is a convenient "Show in Finder" type feature. I'd like the same behavior as when you select a volume in Disk Utility and select "Show in Finder" (which opens a folder at the root of the volume).
0
0
498
Mar ’23