mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #1144 from mitchellh/macos_context_menu
macos: Implement context menu functionality to open tabs and windows.
This commit is contained in:
@ -15,12 +15,7 @@ class ServiceProvider: NSObject {
|
||||
userData: String?,
|
||||
error: AutoreleasingUnsafeMutablePointer<NSString>
|
||||
) {
|
||||
guard let str = pasteboard.string(forType: .string) else {
|
||||
error.pointee = Self.errorNoString
|
||||
return
|
||||
}
|
||||
|
||||
openTerminal(str, target: .tab)
|
||||
openTerminalFromPasteboard(pasteboard: pasteboard, target: .tab, error: error)
|
||||
}
|
||||
|
||||
@objc func openWindow(
|
||||
@ -28,23 +23,34 @@ class ServiceProvider: NSObject {
|
||||
userData: String?,
|
||||
error: AutoreleasingUnsafeMutablePointer<NSString>
|
||||
) {
|
||||
guard let str = pasteboard.string(forType: .string) else {
|
||||
openTerminalFromPasteboard(pasteboard: pasteboard, target: .window, error: error)
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
private func openTerminalFromPasteboard(
|
||||
pasteboard: NSPasteboard,
|
||||
target: OpenTarget,
|
||||
error: AutoreleasingUnsafeMutablePointer<NSString>
|
||||
) {
|
||||
guard let objs = pasteboard.readObjects(forClasses: [NSURL.self]) as? [NSURL] else {
|
||||
error.pointee = Self.errorNoString
|
||||
return
|
||||
}
|
||||
let filePaths = objs.map { $0.path }.compactMap { $0 }
|
||||
|
||||
openTerminal(str, target: .window)
|
||||
openTerminal(filePaths, target: target)
|
||||
}
|
||||
|
||||
private func openTerminal(_ path: String, target: OpenTarget) {
|
||||
private func openTerminal(_ paths: [String], target: OpenTarget) {
|
||||
guard let delegateRaw = NSApp.delegate else { return }
|
||||
guard let delegate = delegateRaw as? AppDelegate else { return }
|
||||
let terminalManager = delegate.terminalManager
|
||||
|
||||
for path in paths {
|
||||
// We only open in directories.
|
||||
var isDirectory = ObjCBool(true)
|
||||
guard FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory) else { return }
|
||||
guard isDirectory.boolValue else { return }
|
||||
guard FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory) else { continue }
|
||||
guard isDirectory.boolValue else { continue }
|
||||
|
||||
// Build our config
|
||||
var config = Ghostty.SurfaceConfiguration()
|
||||
@ -58,4 +64,6 @@ class ServiceProvider: NSObject {
|
||||
terminalManager.newTab(withBaseConfig: config)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user