Set toolbar items target

This commit is contained in:
Damiano Galassi committed 2025-03-10 11:01:03 +01:00
1 parent 8071145c7f
commit ae2addbac4
5 files changed
+19 -2

No files matched your search

+3 -2
View File
@@ -34,14 +34,15 @@ final class ButtonToolbarItem : NSToolbarItem {
super.init(itemIdentifier: itemIdentifier)
}
init(itemIdentifier: NSToolbarItem.Identifier, label: String, toolTip: String, image: String, symbolName: String? = nil, action: Selector) {
init(itemIdentifier: NSToolbarItem.Identifier, label: String, toolTip: String, image: String, symbolName: String? = nil, target: AnyObject?, action: Selector) {
super.init(itemIdentifier: itemIdentifier)
self.label = label
self.paletteLabel = label
self.toolTip = toolTip
self.setSymbol(symbolName: symbolName, fallbackName: image)
self.target = target
self.action = action
self.setSymbol(symbolName: symbolName, fallbackName: image)
if #available(macOS 14, *) {
self.isBordered = true
+7
View File
@@ -18,6 +18,8 @@ private extension NSToolbarItem.Identifier {
class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
var target: AnyObject?
@MainActor func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
if itemIdentifier == .importTracks {
@@ -26,6 +28,7 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
toolTip: NSLocalizedString("Import tracks from external files", comment: "Toolbar"),
image: "NSAddTemplate",
symbolName: "plus",
target: target,
action: #selector(DocumentWindowController.selectFile(_:)))
} else if itemIdentifier == .deleteTracks {
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
@@ -33,6 +36,7 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
toolTip: NSLocalizedString("Delete the selected track", comment: "Toolbar"),
image: "NSRemoveTemplate",
symbolName: "minus",
target: target,
action: #selector(DocumentWindowController.deleteTrack(_:)))
} else if itemIdentifier == .actions {
let submenu = NSMenu()
@@ -109,6 +113,7 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
toolTip: NSLocalizedString("Search metadata on the web", comment: "Toolbar"),
image: "NSRevealFreestandingTemplate",
symbolName: "sparkle.magnifyingglass",
target: target,
action: #selector(DocumentWindowController.searchMetadata(_:)))
} else if itemIdentifier == .sendToQueue {
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
@@ -116,6 +121,7 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
toolTip: NSLocalizedString("Send the current document to the queue", comment: "Toolbar"),
image: "ToolbarActionTemplate",
symbolName: "photo.badge.plus",
target: target,
action: #selector(Document.sendToQueue(_:)))
} else if itemIdentifier == .showQueue {
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
@@ -123,6 +129,7 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
toolTip: NSLocalizedString("Show the Queue window", comment: "Toolbar"),
image: "ToolbarActionTemplate",
symbolName: "photo.stack",
target: target,
action: #selector(AppDelegate.showQueueWindow(_:)))
}
+2
View File
@@ -43,6 +43,8 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
window.toolbarStyle = .expanded
}
toolbarDelegate.target = self
let toolbar = NSToolbar(identifier: "SublerDocumentToolbar")
toolbar.delegate = toolbarDelegate
toolbar.allowsUserCustomization = true
+2
View File
@@ -61,6 +61,8 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
window?.toolbarStyle = .unified
}
toolbarDelegate.target = self
let toolbar = NSToolbar(identifier: "SublerQueueToolbar")
toolbar.delegate = toolbarDelegate
toolbar.allowsUserCustomization = true
+5
View File
@@ -15,6 +15,8 @@ extension NSToolbarItem.Identifier {
class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
var target: AnyObject?
@MainActor func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
if itemIdentifier == .queueAdd {
@@ -23,6 +25,7 @@ class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
toolTip: NSLocalizedString("Add an item to the queue", comment: "Toolbar"),
image: "NSAddTemplate",
symbolName: "plus",
target: target,
action: #selector(QueueController.open(_:)))
} else if itemIdentifier == .queueSettings {
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
@@ -30,6 +33,7 @@ class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
toolTip: NSLocalizedString("Show/Hide settings", comment: "Toolbar"),
image: "NSActionTemplate",
symbolName: "ellipsis.circle",
target: target,
action: #selector(QueueController.toggleOptions(_:)))
} else if itemIdentifier == .queueStartStop {
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
@@ -37,6 +41,7 @@ class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
toolTip: NSLocalizedString("Start/Stop queue", comment: "Toolbar"),
image: "playBackTemplate",
symbolName: "play.fill",
target: target,
action: #selector(QueueController.toggleStartStop(_:)))
}