Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 9be0f97

Browse files
author
khcrysalis
committed
Copyboard(Views): Add preview button for right click action
1 parent a8b8505 commit 9be0f97

4 files changed

Lines changed: 46 additions & 13 deletions

File tree

Copyboard/Resources/Localizable.xcstrings

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,17 @@
449449
}
450450
}
451451
},
452+
"Preview" : {
453+
"extractionState" : "manual",
454+
"localizations" : {
455+
"en" : {
456+
"stringUnit" : {
457+
"state" : "translated",
458+
"value" : "Preview"
459+
}
460+
}
461+
}
462+
},
452463
"Quit %@" : {
453464
"comment" : "Quit Copyboard",
454465
"extractionState" : "manual",

Copyboard/Views/Common/CBCollectionView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class CBCollectionView: NSCollectionView {
9696
AppDelegate.main.menuBar?.statusItem.toggleWindow()
9797
case (true, _, 35): // P Key
9898
if let indexPath = selectionIndexPaths.first {
99-
_showPreviewPopover(for: indexPath)
99+
showPreviewPopover(for: indexPath)
100100
}
101101
case (true, _, 3): // F Key
102102
if let indexPath = selectionIndexPaths.first {
@@ -137,7 +137,7 @@ class CBCollectionView: NSCollectionView {
137137
StorageManager.shared.toggleFavoriteHistory(for: item.object)
138138
}
139139

140-
private func _showPreviewPopover(for indexPath: IndexPath) {
140+
func showPreviewPopover(for indexPath: IndexPath) {
141141
guard let item = item(at: indexPath) as? CBContentViewItem else { return }
142142

143143
// Avoid showing multiple

Copyboard/Views/Content/CBContentView.swift

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,35 @@ extension CBContentView: CBCollectionViewDelegate {
197197

198198
let menu = NSMenu()
199199

200-
let favoriteTitle: String = item.isFavorited ? .localized("Unfavorite") : .localized("Favorite")
201-
let favoriteItem = NSMenuItem(title: favoriteTitle, action: #selector(_handleFavoriteMenuItem(_:)), keyEquivalent: "f")
200+
let previewItem = NSMenuItem(title: .localized("Preview"), action: #selector(_handlePreviewItem(_:)), keyEquivalent: "p")
201+
previewItem.target = self
202+
previewItem.representedObject = indexPath
203+
menu.addItem(previewItem)
204+
205+
menu.addItem(NSMenuItem.separator())
206+
207+
let favoriteItem = NSMenuItem(title: item.isFavorited ? .localized("Unfavorite") : .localized("Favorite"), action: #selector(_handleFavoriteMenuItem(_:)), keyEquivalent: "f")
202208
favoriteItem.target = self
203209
favoriteItem.representedObject = item
204210
menu.addItem(favoriteItem)
205211

206212
menu.addItem(NSMenuItem.separator())
207213

214+
let copyParentItem = NSMenuItem(title: .localized("Copy"), action: nil, keyEquivalent: "")
215+
let copySubmenu = NSMenu()
216+
208217
let copyItem = NSMenuItem(title: .localized("Copy"), action: #selector(_handleCopyMenuItem(_:)), keyEquivalent: "")
209218
copyItem.target = self
210219
copyItem.representedObject = item
211-
menu.addItem(copyItem)
212-
220+
copySubmenu.addItem(copyItem)
221+
213222
let copyPlainItem = NSMenuItem(title: .localized("Copy Without Formatting"), action: #selector(_handleCopyPlainMenuItem(_:)), keyEquivalent: "")
214223
copyPlainItem.target = self
215224
copyPlainItem.representedObject = item
216-
menu.addItem(copyPlainItem)
225+
copySubmenu.addItem(copyPlainItem)
226+
227+
copyParentItem.submenu = copySubmenu
228+
menu.addItem(copyParentItem)
217229

218230
menu.addItem(NSMenuItem.separator())
219231

@@ -243,6 +255,11 @@ extension CBContentView: CBCollectionViewDelegate {
243255
guard let object = sender.representedObject as? CBObject else { return }
244256
_copyItem(for: object, asPlain: true)
245257
}
258+
/// Helper function for preview, for NSMenuItem
259+
@objc private func _handlePreviewItem(_ sender: NSMenuItem) {
260+
guard let object = sender.representedObject as? IndexPath else { return }
261+
_previewItem(for: object)
262+
}
246263
/// Deletes history object entirely.
247264
/// - Parameter object: History object
248265
private func _deleteItem(for object: CBObject) {
@@ -259,6 +276,11 @@ extension CBContentView: CBCollectionViewDelegate {
259276
private func _favoriteItem(for object: CBObject) {
260277
StorageManager.shared.toggleFavoriteHistory(for: object)
261278
}
279+
/// Preview history item.
280+
/// - Parameter indexPath: indexPath
281+
private func _previewItem(for indexPath: IndexPath) {
282+
(collectionView as? CBCollectionView)?.showPreviewPopover(for: indexPath)
283+
}
262284
}
263285

264286
// MARK: - CBContentView (Extension): CBSearchDelegate

Copyboard/Views/Settings/Shortcuts/CBSettingsShortcutsView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ struct CBSettingsShortcutsView: View {
2727
#warning("unfinished")
2828
Text("""
2929
These are the default keybinds that can be used when you're interacting with the clipboard items.
30-
• Quick Copy: `⌘ 1...9`
31-
• Selection: `↑ ↓`
32-
• Copy: `⏎`
33-
• Preview: `⌘ + p`
34-
• Favorite: `⌘ + f`
35-
• Delete: `⌘ + ⌫`
30+
• Quick Copy: `⌘ + 1...9`
31+
• Selection: `↑ ↓`
32+
• Copy: `⏎`
33+
• Preview: `⌘ + p`
34+
• Favorite: `⌘ + f`
35+
• Delete: `⌘ + ⌫`
3636
""").foregroundStyle(.secondary)
3737
}
3838

0 commit comments

Comments
 (0)