2020-12-16 16:35:40 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PostCommands: Commands {
|
2020-12-16 19:25:56 +00:00
|
|
|
@ObservedObject var model: WriteFreelyModel
|
|
|
|
|
2020-12-16 16:35:40 +00:00
|
|
|
var body: some Commands {
|
|
|
|
CommandMenu("Post") {
|
2023-06-10 10:49:45 +00:00
|
|
|
Button("Find In Posts") {
|
|
|
|
if let toolbar = NSApp.keyWindow?.toolbar,
|
|
|
|
let search = toolbar.items.first(where: {
|
|
|
|
$0.itemIdentifier.rawValue == "com.apple.SwiftUI.search"
|
|
|
|
}) as? NSSearchToolbarItem {
|
|
|
|
search.beginSearchInteraction()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.keyboardShortcut("f", modifiers: [.command, .shift])
|
|
|
|
|
2020-12-16 19:25:56 +00:00
|
|
|
Group {
|
|
|
|
Button(action: sendPostUrlToPasteboard, label: { Text("Copy Link To Published Post") })
|
|
|
|
.disabled(model.selectedPost?.status == PostStatus.local.rawValue)
|
2020-12-16 16:35:40 +00:00
|
|
|
}
|
2020-12-16 19:25:56 +00:00
|
|
|
.disabled(model.selectedPost == nil || !model.account.isLoggedIn)
|
2020-12-16 16:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-16 19:25:56 +00:00
|
|
|
|
|
|
|
private func sendPostUrlToPasteboard() {
|
|
|
|
guard let activePost = model.selectedPost else { return }
|
|
|
|
guard let postId = activePost.postId else { return }
|
|
|
|
guard let urlString = activePost.slug != nil ?
|
|
|
|
"\(model.account.server)/\((activePost.collectionAlias)!)/\((activePost.slug)!)" :
|
|
|
|
"\(model.account.server)/\((postId))" else { return }
|
|
|
|
NSPasteboard.general.clearContents()
|
|
|
|
NSPasteboard.general.setString(urlString, forType: .string)
|
|
|
|
}
|
2020-12-16 16:35:40 +00:00
|
|
|
}
|