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
|
2024-03-21 04:49:15 +01:00
|
|
|
import Core
|
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] {
|
2024-05-03 20:57:20 +02:00
|
|
|
|
|
|
|
MainActor.assumeIsolated {
|
|
|
|
let filteredServices = proposedServices.filter { $0.menuItemTitle != "NetNewsWire" }
|
|
|
|
return filteredServices + 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
|
|
|
}
|
|
|
|
|
2024-05-03 20:57:20 +02:00
|
|
|
@MainActor static func customSharingServices(for items: [Any]) -> [NSSharingService] {
|
2023-06-26 01:48:37 +02:00
|
|
|
let customServices: [SendToCommand] = [SendToMarsEditCommand(), SendToMicroBlogCommand()]
|
|
|
|
|
|
|
|
return customServices.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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|