macos: register that we accept/send text types for services

This commit is contained in:
Mitchell Hashimoto
2024-01-21 17:07:24 -08:00
parent 8b11d20cb0
commit 4c9fc452b6
2 changed files with 42 additions and 2 deletions

View File

@ -109,9 +109,10 @@ class AppDelegate: NSObject,
// Initial config loading // Initial config loading
configDidReload(ghostty) configDidReload(ghostty)
// Register our service provider. This must happen after everything // Register our service provider. This must happen after everything is initialized.
// else is initialized.
NSApp.servicesProvider = ServiceProvider() NSApp.servicesProvider = ServiceProvider()
// This registers the Ghostty => Services menu to exist.
NSApp.servicesMenu = menuServices NSApp.servicesMenu = menuServices
// Configure user notifications // Configure user notifications

View File

@ -953,3 +953,42 @@ extension Ghostty.SurfaceView: NSTextInputClient {
print("SEL: \(selector)") print("SEL: \(selector)")
} }
} }
// MARK: Services
// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/SysServices/Articles/using.html
extension Ghostty.SurfaceView: NSServicesMenuRequestor {
override func validRequestor(
forSendType sendType: NSPasteboard.PasteboardType?,
returnType: NSPasteboard.PasteboardType?
) -> Any? {
// Types that we accept sent to us
let accepted: [NSPasteboard.PasteboardType] = [.string, .init("public.utf8-plain-text")]
// We can always receive the accepted types
if (returnType == nil || accepted.contains(returnType!)) {
return self
}
// If we have a selection we can send the accepted types too
// TODO selection
if (sendType == nil || accepted.contains(sendType!)) {
return self
}
return super.validRequestor(forSendType: sendType, returnType: returnType)
}
func writeSelection(
to pboard: NSPasteboard,
types: [NSPasteboard.PasteboardType]
) -> Bool {
// TODO
return false
}
func readSelection(from pboard: NSPasteboard) -> Bool {
// TODO
return false
}
}