Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Sources/Pesty/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ final class AppController: NSObject, NSApplicationDelegate {

var suppressAutoHide = false

/// Context-menu paste actions return to the app that was frontmost when
/// Pesty opened. Keep the wording contextual without implying an app will
/// be launched when that target is unavailable.
var pasteDestinationMenuTitle: String {
guard let previousApp,
!previousApp.isTerminated,
let name = previousApp.localizedName?.trimmingCharacters(in: .whitespacesAndNewlines),
!name.isEmpty else { return "Paste" }
return "Paste to \(name)"
}

func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.setActivationPolicy(.accessory)

Expand Down
12 changes: 10 additions & 2 deletions Sources/Pesty/UI/ClipCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,18 @@ struct ClipCardView: View {
private var menu: some View {
if let entry = pasteStackEntry {
if entry.isPasted {
pasteToPreviousAppButton { AppController.shared.pasteItem(item) }
Button("Re-add to Stack") { AppController.shared.reAddPasteStackEntry(entry) }
} else {
Button("Paste") { AppController.shared.pasteStackEntry(entry) }
pasteToPreviousAppButton { AppController.shared.pasteStackEntry(entry) }
}
Button("Copy") { AppController.shared.copyItem(item) }
Divider()
Button("Remove from Paste Stack", role: .destructive) {
AppController.shared.removePasteStackEntry(entry)
}
} else {
Button("Paste") { AppController.shared.pasteItem(item) }
pasteToPreviousAppButton { AppController.shared.pasteItem(item) }
Button("Copy") { AppController.shared.copyItem(item) }
Divider()
if !store.pinboards.isEmpty {
Expand All @@ -274,6 +275,13 @@ struct ClipCardView: View {
}
}

private func pasteToPreviousAppButton(action: @escaping () -> Void) -> some View {
Button(action: action) {
Label(AppController.shared.pasteDestinationMenuTitle,
systemImage: "doc.on.clipboard")
}
}

private func selectCard() {
if let entry = pasteStackEntry {
AppController.shared.pasteSequence.select(entry)
Expand Down