Toolbars improvements, use SF Symbols when possible
This commit is contained in:
6 files changed
+72
-32
No files matched your search
@@ -1,8 +1,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>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22690"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
@@ -456,7 +456,7 @@
|
||||
<menuItem title="Show Queue" keyEquivalent="p" id="595">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="showBatchWindow:" target="-1" id="596"/>
|
||||
<action selector="showQueueWindow:" target="-1" id="596"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Show Message Log" id="9t4-R8-Exy">
|
||||
|
||||
@@ -243,7 +243,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
QueueController.shared.open(sender)
|
||||
}
|
||||
|
||||
@IBAction func showBatchWindow(_ sender: Any) {
|
||||
@IBAction func showQueueWindow(_ sender: Any) {
|
||||
QueueController.shared.showWindow(self)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,18 +7,39 @@
|
||||
|
||||
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 {
|
||||
|
||||
override init(itemIdentifier: NSToolbarItem.Identifier) {
|
||||
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)
|
||||
|
||||
self.label = label
|
||||
self.toolTip = toolTip
|
||||
self.image = NSImage(named: image)
|
||||
self.setSymbol(symbolName: symbolName, fallbackName: image)
|
||||
self.action = action
|
||||
|
||||
if #available(macOS 14, *) {
|
||||
|
||||
@@ -22,16 +22,18 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
|
||||
|
||||
if itemIdentifier == .importTracks {
|
||||
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
|
||||
label: NSLocalizedString("Import", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Import tracks from external files", comment: "Toolbar"),
|
||||
image: "NSAddTemplate",
|
||||
action: #selector(DocumentWindowController.selectFile(_:)))
|
||||
label: NSLocalizedString("Import", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Import tracks from external files", comment: "Toolbar"),
|
||||
image: "NSAddTemplate",
|
||||
symbolName: "plus",
|
||||
action: #selector(DocumentWindowController.selectFile(_:)))
|
||||
} else if itemIdentifier == .deleteTracks {
|
||||
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
|
||||
label: NSLocalizedString("Delete", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Delete the selected track", comment: "Toolbar"),
|
||||
image: "ToolbarRemoveTemplate",
|
||||
action: #selector(DocumentWindowController.deleteTrack(_:)))
|
||||
label: NSLocalizedString("Delete", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Delete the selected track", comment: "Toolbar"),
|
||||
image: "ToolbarRemoveTemplate",
|
||||
symbolName: "minus",
|
||||
action: #selector(DocumentWindowController.deleteTrack(_:)))
|
||||
} else if itemIdentifier == .actions {
|
||||
let submenu = NSMenu()
|
||||
for minutes in [1, 2, 5, 10, 15, 20, 30] {
|
||||
@@ -99,34 +101,37 @@ class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
|
||||
}
|
||||
} else if itemIdentifier == .searchMetadata {
|
||||
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
|
||||
label: NSLocalizedString("Search Metadata", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Search metadata on the web", comment: "Toolbar"),
|
||||
image: "NSRevealFreestandingTemplate",
|
||||
action: #selector(DocumentWindowController.searchMetadata(_:)))
|
||||
label: NSLocalizedString("Search Metadata", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Search metadata on the web", comment: "Toolbar"),
|
||||
image: "NSRevealFreestandingTemplate",
|
||||
symbolName: "sparkle.magnifyingglass",
|
||||
action: #selector(DocumentWindowController.searchMetadata(_:)))
|
||||
} else if itemIdentifier == .sendToQueue {
|
||||
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
|
||||
label: NSLocalizedString("Send to Queue", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Send the current document to the queue", comment: "Toolbar"),
|
||||
image: "ToolbarActionTemplate",
|
||||
action: #selector(Document.sendToQueue(_:)))
|
||||
label: NSLocalizedString("Send to Queue", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Send the current document to the queue", comment: "Toolbar"),
|
||||
image: "ToolbarActionTemplate",
|
||||
symbolName: "photo.badge.plus",
|
||||
action: #selector(Document.sendToQueue(_:)))
|
||||
// sendToQueue.image = NSImage(named: NSImage.shareTemplateName);
|
||||
} else if itemIdentifier == .showQueue {
|
||||
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
|
||||
label: NSLocalizedString("Show Queue", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Show the Queue window", comment: "Toolbar"),
|
||||
image: "ToolbarActionTemplate",
|
||||
action: #selector(Document.sendToQueue(_:)))
|
||||
label: NSLocalizedString("Show Queue", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Show the Queue window", comment: "Toolbar"),
|
||||
image: "ToolbarActionTemplate",
|
||||
symbolName: "photo.stack",
|
||||
action: #selector(AppDelegate.showQueueWindow(_:)))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@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] {
|
||||
return [.importTracks, .deleteTracks, .actions, .flexibleSpace, .searchMetadata, .sendToQueue, .showQueue, .flexibleSpace, .space]
|
||||
return [.importTracks, .deleteTracks, .actions, .searchMetadata, .sendToQueue, .showQueue, .flexibleSpace, .space]
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
|
||||
private var windowController: OptionsViewController?
|
||||
private let toolbarDelegate = QueueToolbarDelegate()
|
||||
|
||||
private let tablePasteboardType = NSPasteboard.PasteboardType("SublerBatchTableViewDataType")
|
||||
private let tablePasteboardType = NSPasteboard.PasteboardType("SublerQueueTableViewDataType")
|
||||
private lazy var docImg: NSImage = {
|
||||
// Load a generic movie icon to display in the table view
|
||||
let img = NSWorkspace.shared.icon(forFileType: "mov")
|
||||
@@ -632,10 +632,20 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
|
||||
}
|
||||
|
||||
@IBAction func toggleOptions(_ sender: Any?) {
|
||||
guard let window = self.window else { return }
|
||||
createOptionsPopover()
|
||||
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
private extension NSToolbarItem.Identifier {
|
||||
extension NSToolbarItem.Identifier {
|
||||
static let queueAdd: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueAdd")
|
||||
static let queueSettings: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueSettings")
|
||||
static let queueStartStop: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "QueueStartStop")
|
||||
@@ -22,18 +22,21 @@ class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
|
||||
label: NSLocalizedString("Add Item", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Add an item to the queue", comment: "Toolbar"),
|
||||
image: "NSAddTemplate",
|
||||
symbolName: "plus",
|
||||
action: #selector(QueueController.open(_:)))
|
||||
} else if itemIdentifier == .queueSettings {
|
||||
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
|
||||
label: NSLocalizedString("Settings", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Show/Hide settings", comment: "Toolbar"),
|
||||
image: "NSActionTemplate",
|
||||
symbolName: "ellipsis.circle",
|
||||
action: #selector(QueueController.toggleOptions(_:)))
|
||||
} else if itemIdentifier == .queueStartStop {
|
||||
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
|
||||
label: NSLocalizedString("Start", comment: "Toolbar"),
|
||||
toolTip: NSLocalizedString("Start/Stop queue", comment: "Toolbar"),
|
||||
image: "playBackTemplate",
|
||||
symbolName: "play.fill",
|
||||
action: #selector(QueueController.toggleStartStop(_:)))
|
||||
}
|
||||
|
||||
@@ -52,9 +55,10 @@ class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
|
||||
guard let item = toolbar.items.first(where: { $0.itemIdentifier == .queueStartStop }) else { return }
|
||||
|
||||
if working {
|
||||
item.setSymbol(symbolName: "stop.fill", fallbackName: "stopTemplate")
|
||||
item.image = NSImage(named: "stopTemplate")
|
||||
} else {
|
||||
item.image = NSImage(named: "playBackTemplate")
|
||||
item.setSymbol(symbolName: "play.fill", fallbackName: "playBackTemplate")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user