Toolbars improvements, use SF Symbols when possible

This commit is contained in:
Damiano Galassi committed 2024-07-19 06:53:22 +02:00
1 parent d59f73bcb0
commit 94c083565f
6 files changed
+72 -32

No files matched your search

+3 -3
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22690"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication"> <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -456,7 +456,7 @@
<menuItem title="Show Queue" keyEquivalent="p" id="595"> <menuItem title="Show Queue" keyEquivalent="p" id="595">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/> <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections> <connections>
<action selector="showBatchWindow:" target="-1" id="596"/> <action selector="showQueueWindow:" target="-1" id="596"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title="Show Message Log" id="9t4-R8-Exy"> <menuItem title="Show Message Log" id="9t4-R8-Exy">
+1 -1
View File
@@ -243,7 +243,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
QueueController.shared.open(sender) QueueController.shared.open(sender)
} }
@IBAction func showBatchWindow(_ sender: Any) { @IBAction func showQueueWindow(_ sender: Any) {
QueueController.shared.showWindow(self) QueueController.shared.showWindow(self)
} }
+23 -2
View File
@@ -7,18 +7,39 @@
import Cocoa import Cocoa
extension NSToolbarItem {
func setSymbol(symbolName: String?, fallbackName: String) {
var image: NSImage?
if #available(macOS 11, *) {
if let symbolName {
image = NSImage.init(systemSymbolName: symbolName, accessibilityDescription: nil)
if image == nil {
image = NSImage(named: symbolName)
}
}
}
if image == nil {
image = NSImage(named: fallbackName)
}
self.image = image
}
}
final class ButtonToolbarItem : NSToolbarItem { final class ButtonToolbarItem : NSToolbarItem {
override init(itemIdentifier: NSToolbarItem.Identifier) { override init(itemIdentifier: NSToolbarItem.Identifier) {
super.init(itemIdentifier: itemIdentifier) super.init(itemIdentifier: itemIdentifier)
} }
init(itemIdentifier: NSToolbarItem.Identifier, label: String, toolTip: String, image: String, action: Selector) { init(itemIdentifier: NSToolbarItem.Identifier, label: String, toolTip: String, image: String, symbolName: String? = nil, action: Selector) {
super.init(itemIdentifier: itemIdentifier) super.init(itemIdentifier: itemIdentifier)
self.label = label self.label = label
self.toolTip = toolTip self.toolTip = toolTip
self.image = NSImage(named: image) self.setSymbol(symbolName: symbolName, fallbackName: image)
self.action = action self.action = action
if #available(macOS 14, *) { if #available(macOS 14, *) {
+27 -22
View File
@@ -22,16 +22,18 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
if itemIdentifier == .importTracks { if itemIdentifier == .importTracks {
return ButtonToolbarItem(itemIdentifier: itemIdentifier, return ButtonToolbarItem(itemIdentifier: itemIdentifier,
label: NSLocalizedString("Import", comment: "Toolbar"), label: NSLocalizedString("Import", comment: "Toolbar"),
toolTip: NSLocalizedString("Import tracks from external files", comment: "Toolbar"), toolTip: NSLocalizedString("Import tracks from external files", comment: "Toolbar"),
image: "NSAddTemplate", image: "NSAddTemplate",
action: #selector(DocumentWindowController.selectFile(_:))) symbolName: "plus",
action: #selector(DocumentWindowController.selectFile(_:)))
} else if itemIdentifier == .deleteTracks { } else if itemIdentifier == .deleteTracks {
return ButtonToolbarItem(itemIdentifier: itemIdentifier, return ButtonToolbarItem(itemIdentifier: itemIdentifier,
label: NSLocalizedString("Delete", comment: "Toolbar"), label: NSLocalizedString("Delete", comment: "Toolbar"),
toolTip: NSLocalizedString("Delete the selected track", comment: "Toolbar"), toolTip: NSLocalizedString("Delete the selected track", comment: "Toolbar"),
image: "ToolbarRemoveTemplate", image: "ToolbarRemoveTemplate",
action: #selector(DocumentWindowController.deleteTrack(_:))) symbolName: "minus",
action: #selector(DocumentWindowController.deleteTrack(_:)))
} else if itemIdentifier == .actions { } else if itemIdentifier == .actions {
let submenu = NSMenu() let submenu = NSMenu()
for minutes in [1, 2, 5, 10, 15, 20, 30] { for minutes in [1, 2, 5, 10, 15, 20, 30] {
@@ -99,34 +101,37 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
} }
} else if itemIdentifier == .searchMetadata { } else if itemIdentifier == .searchMetadata {
return ButtonToolbarItem(itemIdentifier: itemIdentifier, return ButtonToolbarItem(itemIdentifier: itemIdentifier,
label: NSLocalizedString("Search Metadata", comment: "Toolbar"), label: NSLocalizedString("Search Metadata", comment: "Toolbar"),
toolTip: NSLocalizedString("Search metadata on the web", comment: "Toolbar"), toolTip: NSLocalizedString("Search metadata on the web", comment: "Toolbar"),
image: "NSRevealFreestandingTemplate", image: "NSRevealFreestandingTemplate",
action: #selector(DocumentWindowController.searchMetadata(_:))) symbolName: "sparkle.magnifyingglass",
action: #selector(DocumentWindowController.searchMetadata(_:)))
} else if itemIdentifier == .sendToQueue { } else if itemIdentifier == .sendToQueue {
return ButtonToolbarItem(itemIdentifier: itemIdentifier, return ButtonToolbarItem(itemIdentifier: itemIdentifier,
label: NSLocalizedString("Send to Queue", comment: "Toolbar"), label: NSLocalizedString("Send to Queue", comment: "Toolbar"),
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",
action: #selector(Document.sendToQueue(_:))) symbolName: "photo.badge.plus",
action: #selector(Document.sendToQueue(_:)))
// sendToQueue.image = NSImage(named: NSImage.shareTemplateName); // sendToQueue.image = NSImage(named: NSImage.shareTemplateName);
} else if itemIdentifier == .showQueue { } else if itemIdentifier == .showQueue {
return ButtonToolbarItem(itemIdentifier: itemIdentifier, return ButtonToolbarItem(itemIdentifier: itemIdentifier,
label: NSLocalizedString("Show Queue", comment: "Toolbar"), label: NSLocalizedString("Show Queue", comment: "Toolbar"),
toolTip: NSLocalizedString("Show the Queue window", comment: "Toolbar"), toolTip: NSLocalizedString("Show the Queue window", comment: "Toolbar"),
image: "ToolbarActionTemplate", image: "ToolbarActionTemplate",
action: #selector(Document.sendToQueue(_:))) symbolName: "photo.stack",
action: #selector(AppDelegate.showQueueWindow(_:)))
} }
return nil return nil
} }
@MainActor func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { @MainActor func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.importTracks, .deleteTracks, .actions, .flexibleSpace, .searchMetadata] return [.importTracks, .deleteTracks, .space, .actions, .flexibleSpace, .searchMetadata]
} }
@MainActor func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { @MainActor func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.importTracks, .deleteTracks, .actions, .flexibleSpace, .searchMetadata, .sendToQueue, .showQueue, .flexibleSpace, .space] return [.importTracks, .deleteTracks, .actions, .searchMetadata, .sendToQueue, .showQueue, .flexibleSpace, .space]
} }
} }
+12 -2
View File
@@ -19,7 +19,7 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
private var windowController: OptionsViewController? private var windowController: OptionsViewController?
private let toolbarDelegate = QueueToolbarDelegate() private let toolbarDelegate = QueueToolbarDelegate()
private let tablePasteboardType = NSPasteboard.PasteboardType("SublerBatchTableViewDataType") private let tablePasteboardType = NSPasteboard.PasteboardType("SublerQueueTableViewDataType")
private lazy var docImg: NSImage = { private lazy var docImg: NSImage = {
// Load a generic movie icon to display in the table view // Load a generic movie icon to display in the table view
let img = NSWorkspace.shared.icon(forFileType: "mov") let img = NSWorkspace.shared.icon(forFileType: "mov")
@@ -632,10 +632,20 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
} }
@IBAction func toggleOptions(_ sender: Any?) { @IBAction func toggleOptions(_ sender: Any?) {
guard let window = self.window else { return }
createOptionsPopover() createOptionsPopover()
if let p = popover, p.isShown == false { if let p = popover, p.isShown == false {
if let target = ((sender as? NSView) != nil) ? sender as? NSView : window?.contentView { let toolbarItem = window.toolbar?.visibleItems?.first(where: { $0.itemIdentifier == .queueSettings })
let target = ((toolbarItem?.view?.window) != nil) ? toolbarItem?.view : window.contentView
if #available(macOS 14, *) {
if let toolbarItem, let toolbar = window.toolbar, toolbar.isVisible == true {
p.show(relativeTo: toolbarItem)
} else if let target {
p.show(relativeTo: target.bounds, of: target, preferredEdge: .maxY)
}
} else if let target {
p.show(relativeTo: target.bounds, of: target, preferredEdge: .maxY) p.show(relativeTo: target.bounds, of: target, preferredEdge: .maxY)
} }
} else { } else {
+6 -2
View File
@@ -7,7 +7,7 @@
import Cocoa import Cocoa
private extension NSToolbarItem.Identifier { extension NSToolbarItem.Identifier {
static let queueAdd: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueAdd") static let queueAdd: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueAdd")
static let queueSettings: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueSettings") static let queueSettings: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueSettings")
static let queueStartStop: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueStartStop") static let queueStartStop: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueStartStop")
@@ -22,18 +22,21 @@ class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
label: NSLocalizedString("Add Item", comment: "Toolbar"), label: NSLocalizedString("Add Item", comment: "Toolbar"),
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",
action: #selector(QueueController.open(_:))) action: #selector(QueueController.open(_:)))
} else if itemIdentifier == .queueSettings { } else if itemIdentifier == .queueSettings {
return ButtonToolbarItem(itemIdentifier: itemIdentifier, return ButtonToolbarItem(itemIdentifier: itemIdentifier,
label: NSLocalizedString("Settings", comment: "Toolbar"), label: NSLocalizedString("Settings", comment: "Toolbar"),
toolTip: NSLocalizedString("Show/Hide settings", comment: "Toolbar"), toolTip: NSLocalizedString("Show/Hide settings", comment: "Toolbar"),
image: "NSActionTemplate", image: "NSActionTemplate",
symbolName: "ellipsis.circle",
action: #selector(QueueController.toggleOptions(_:))) action: #selector(QueueController.toggleOptions(_:)))
} else if itemIdentifier == .queueStartStop { } else if itemIdentifier == .queueStartStop {
return ButtonToolbarItem(itemIdentifier: itemIdentifier, return ButtonToolbarItem(itemIdentifier: itemIdentifier,
label: NSLocalizedString("Start", comment: "Toolbar"), label: NSLocalizedString("Start", comment: "Toolbar"),
toolTip: NSLocalizedString("Start/Stop queue", comment: "Toolbar"), toolTip: NSLocalizedString("Start/Stop queue", comment: "Toolbar"),
image: "playBackTemplate", image: "playBackTemplate",
symbolName: "play.fill",
action: #selector(QueueController.toggleStartStop(_:))) action: #selector(QueueController.toggleStartStop(_:)))
} }
@@ -52,9 +55,10 @@ class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
guard let item = toolbar.items.first(where: { $0.itemIdentifier == .queueStartStop }) else { return } guard let item = toolbar.items.first(where: { $0.itemIdentifier == .queueStartStop }) else { return }
if working { if working {
item.setSymbol(symbolName: "stop.fill", fallbackName: "stopTemplate")
item.image = NSImage(named: "stopTemplate") item.image = NSImage(named: "stopTemplate")
} else { } else {
item.image = NSImage(named: "playBackTemplate") item.setSymbol(symbolName: "play.fill", fallbackName: "playBackTemplate")
} }
} }
} }