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