2018-01-09 06:53:49 +01:00
|
|
|
//
|
|
|
|
// SendToMarsEditCommand.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 1/8/18.
|
|
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-01-12 07:18:46 +01:00
|
|
|
import Cocoa
|
2018-01-09 06:53:49 +01:00
|
|
|
|
2018-01-09 07:10:56 +01:00
|
|
|
final class SendToMarsEditCommand: SendToCommand {
|
2018-01-09 06:53:49 +01:00
|
|
|
|
2018-01-12 07:18:46 +01:00
|
|
|
let title = NSLocalizedString("Send to MarsEdit", comment: "Send to command")
|
|
|
|
|
|
|
|
var image: NSImage? {
|
|
|
|
return appSpecifierToUse()?.icon ?? nil
|
|
|
|
}
|
|
|
|
|
|
|
|
private let marsEditApps = [ApplicationSpecifier(bundleID: "com.red-sweater.marsedit4"), ApplicationSpecifier(bundleID: "com.red-sweater.marsedit")]
|
|
|
|
|
2018-01-10 07:04:45 +01:00
|
|
|
func canSendObject(_ object: Any?, selectedText: String?) -> Bool {
|
2018-01-09 06:53:49 +01:00
|
|
|
|
2018-01-12 07:18:46 +01:00
|
|
|
if let _ = appSpecifierToUse() {
|
|
|
|
return true
|
|
|
|
}
|
2018-01-09 06:53:49 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-01-10 07:04:45 +01:00
|
|
|
func sendObject(_ object: Any?, selectedText: String?) {
|
2018-01-09 06:53:49 +01:00
|
|
|
|
2018-01-12 07:18:46 +01:00
|
|
|
if !canSendObject(object, selectedText: selectedText) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension SendToMarsEditCommand {
|
|
|
|
|
|
|
|
func appSpecifierToUse() -> ApplicationSpecifier? {
|
|
|
|
|
|
|
|
for specifier in marsEditApps {
|
|
|
|
specifier.update()
|
|
|
|
if specifier.existsOnDisk {
|
|
|
|
return specifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-01-09 06:53:49 +01:00
|
|
|
}
|
|
|
|
}
|