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-14 20:00:42 +01:00
|
|
|
import RSCore
|
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-14 21:13:25 +01:00
|
|
|
let title = "MarsEdit"
|
2018-01-12 07:18:46 +01:00
|
|
|
|
|
|
|
var image: NSImage? {
|
2018-01-14 20:00:42 +01:00
|
|
|
return appToUse()?.icon ?? nil
|
2018-01-12 07:18:46 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 20:00:42 +01:00
|
|
|
private let marsEditApps = [UserApp(bundleID: "com.red-sweater.marsedit4"), UserApp(bundleID: "com.red-sweater.marsedit")]
|
2018-01-12 07:18:46 +01:00
|
|
|
|
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-14 20:00:42 +01:00
|
|
|
if let _ = appToUse() {
|
2018-01-12 07:18:46 +01:00
|
|
|
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 {
|
|
|
|
|
2018-01-14 20:00:42 +01:00
|
|
|
func appToUse() -> UserApp? {
|
2018-01-12 07:18:46 +01:00
|
|
|
|
2018-01-14 20:12:28 +01:00
|
|
|
marsEditApps.forEach{ $0.updateStatus() }
|
|
|
|
|
2018-01-14 20:00:42 +01:00
|
|
|
for app in marsEditApps {
|
|
|
|
if app.isRunning {
|
|
|
|
return app
|
|
|
|
}
|
2018-01-14 20:12:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for app in marsEditApps {
|
2018-01-14 20:00:42 +01:00
|
|
|
if app.existsOnDisk {
|
|
|
|
return app
|
2018-01-12 07:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-01-09 06:53:49 +01:00
|
|
|
}
|
|
|
|
}
|