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