2018-02-18 05:33:30 +01:00
|
|
|
//
|
2018-09-04 02:01:10 +02:00
|
|
|
// SharingServicePickerDelegate.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2018-02-18 05:33:30 +01:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 2/17/18.
|
|
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import AppKit
|
2019-04-13 22:15:22 +02:00
|
|
|
import RSCore
|
2018-02-18 05:33:30 +01:00
|
|
|
|
2018-09-04 02:01:10 +02:00
|
|
|
@objc final class SharingServicePickerDelegate: NSObject, NSSharingServicePickerDelegate {
|
2018-09-08 03:22:13 +02:00
|
|
|
|
|
|
|
private let sharingServiceDelegate: SharingServiceDelegate
|
|
|
|
|
|
|
|
init(_ window: NSWindow?) {
|
|
|
|
sharingServiceDelegate = SharingServiceDelegate(window)
|
|
|
|
}
|
|
|
|
|
2018-02-18 05:33:30 +01:00
|
|
|
func sharingServicePicker(_ sharingServicePicker: NSSharingServicePicker, sharingServicesForItems items: [Any], proposedSharingServices proposedServices: [NSSharingService]) -> [NSSharingService] {
|
2018-09-04 02:01:10 +02:00
|
|
|
return proposedServices + SharingServicePickerDelegate.customSharingServices(for: items)
|
2018-09-08 03:22:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func sharingServicePicker(_ sharingServicePicker: NSSharingServicePicker, delegateFor sharingService: NSSharingService) -> NSSharingServiceDelegate? {
|
|
|
|
return sharingServiceDelegate
|
2018-09-04 02:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static func customSharingServices(for items: [Any]) -> [NSSharingService] {
|
2020-08-02 21:10:02 +02:00
|
|
|
let customServices = ExtensionPointManager.shared.activeSendToCommands.compactMap { (sendToCommand) -> NSSharingService? in
|
2018-02-18 05:33:30 +01:00
|
|
|
|
|
|
|
guard let object = items.first else {
|
|
|
|
return nil
|
|
|
|
}
|
2020-04-08 20:46:15 +02:00
|
|
|
|
2018-02-18 05:33:30 +01:00
|
|
|
guard sendToCommand.canSendObject(object, selectedText: nil) else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-11-12 22:36:03 +01:00
|
|
|
let image = sendToCommand.image ?? NSImage()
|
2018-02-18 05:33:30 +01:00
|
|
|
return NSSharingService(title: sendToCommand.title, image: image, alternateImage: nil) {
|
|
|
|
sendToCommand.sendObject(object, selectedText: nil)
|
|
|
|
}
|
|
|
|
}
|
2018-09-04 02:01:10 +02:00
|
|
|
return customServices
|
2018-02-18 05:33:30 +01:00
|
|
|
}
|
|
|
|
}
|