Move toolbars to code, improve text mode and buttons size

This commit is contained in:
Damiano Galassi committed 2024-07-18 18:24:23 +02:00
1 parent c5ef95fb92
commit d59f73bcb0
9 files changed
+293 -293

No files matched your search

+5 -178
View File
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="DocumentWindowController" customModule="Subler" customModuleProvider="target">
<connections>
<outlet property="addTracks" destination="FY3-O2-t3T" id="fcf-d9-3eB"/>
<outlet property="deleteTrack" destination="rhw-S4-nZ8" id="VaB-n8-rPm"/>
<outlet property="searchMetadata" destination="uiq-J2-uPs" id="lv3-UJ-53r"/>
<outlet property="sendToQueue" destination="app-IS-8EB" id="jdh-iz-uSq"/>
<outlet property="window" destination="s5f-yH-26m" id="YRM-He-gQ6"/>
</connections>
</customObject>
@@ -20,186 +16,17 @@
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" toolbarStyle="expanded" id="s5f-yH-26m" userLabel="Window">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="59" y="509" width="520" height="510"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
<rect key="contentRect" x="70" y="318" width="520" height="510"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
<value key="minSize" type="size" width="520" height="510"/>
<view key="contentView" id="rip-YL-WpY">
<rect key="frame" x="0.0" y="0.0" width="520" height="486"/>
<rect key="frame" x="0.0" y="0.0" width="520" height="510"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</view>
<toolbar key="toolbar" implicitIdentifier="61E0A00C-CBF2-4937-9418-AC0758672070" explicitIdentifier="SBDocumentToolbar26" displayMode="iconOnly" sizeMode="regular" id="PRH-t4-qwh">
<allowedToolbarItems>
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="Af5-ai-sw9"/>
<toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="qX7-s1-81X"/>
<toolbarItem implicitItemIdentifier="D2E8E21C-DCD4-456F-B15A-9AC0AA5556DF" label="Import" paletteLabel="Import" toolTip="Import tracks from external files" image="NSAddTemplate" sizingBehavior="auto" id="FY3-O2-t3T" customClass="ButtonToolbarItem" customModule="Subler" customModuleProvider="target">
<button key="view" verticalHuggingPriority="750" id="UZy-eh-ZBz">
<rect key="frame" x="8" y="14" width="26" height="23"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSAddTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="r0z-KC-Ehd">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<connections>
<action selector="selectFile:" target="-2" id="mTY-vt-vsv"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="5B6FDF6D-9486-49B2-8EA4-184D76D0864C" label="Delete Track" paletteLabel="Delete Track" toolTip="Delete the selected track" image="ToolbarRemoveTemplate" sizingBehavior="auto" id="rhw-S4-nZ8" customClass="ButtonToolbarItem" customModule="Subler" customModuleProvider="target">
<button key="view" verticalHuggingPriority="750" id="e81-Qg-Ncc">
<rect key="frame" x="23" y="14" width="28" height="23"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="ToolbarRemoveTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="HWd-4N-V3A">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<connections>
<action selector="deleteTrack:" target="-2" id="N1h-dg-CaR"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="66402BE4-4A7B-4048-A584-2BC0F5E69600" label="Search Metadata" paletteLabel="Search Metadata" toolTip="Search metadata on the web" image="NSRevealFreestandingTemplate" sizingBehavior="auto" id="uiq-J2-uPs" customClass="ButtonToolbarItem" customModule="Subler" customModuleProvider="target">
<button key="view" verticalHuggingPriority="750" id="Nes-H1-fbL">
<rect key="frame" x="35" y="14" width="27" height="23"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSRevealFreestandingTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="hLF-cH-6MQ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<connections>
<action selector="searchMetadata:" target="-2" id="3Jl-xK-nb3"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="9F789D5F-C25E-449F-ABCE-DDF99B4FF988" label="Send to Queue" paletteLabel="Send to Queue" toolTip="Send the current document to the queue" image="ToolbarActionTemplate" sizingBehavior="auto" id="app-IS-8EB" customClass="ButtonToolbarItem" customModule="Subler" customModuleProvider="target">
<button key="view" verticalHuggingPriority="750" id="c38-NC-1I2">
<rect key="frame" x="28" y="14" width="30" height="23"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="ToolbarActionTemplate" imagePosition="only" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ZbH-ut-l4n">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<connections>
<action selector="sendToQueue:" target="-1" id="rIw-6k-8we"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="2E3AB086-491A-436E-A610-14E36AEE8F49" label="Action" paletteLabel="Action" image="NSActionTemplate" bordered="YES" sizingBehavior="auto" id="V6w-Ey-bjV">
<nil key="toolTip"/>
<popUpButton key="view" verticalHuggingPriority="750" id="QuP-nB-KsX">
<rect key="frame" x="0.0" y="14" width="50" height="25"/>
<autoresizingMask key="autoresizingMask"/>
<popUpButtonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" pullsDown="YES" selectedItem="LML-iW-skB" id="LNp-Kr-404">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="VNR-O6-D9w">
<items>
<menuItem state="on" image="NSActionTemplate" hidden="YES" id="LML-iW-skB"/>
<menuItem title="Insert a chapter every" id="0vu-Jl-QDb">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Insert a chapter every" id="o5I-IO-kDx">
<items>
<menuItem title="1 minute" tag="1" id="5Fm-fy-9es">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="addChaptersEvery:" target="-2" id="89f-wa-n6U"/>
</connections>
</menuItem>
<menuItem title="2 minutes" tag="2" id="2M2-Yg-cgc">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="addChaptersEvery:" target="-2" id="Sdq-Mm-1zi"/>
</connections>
</menuItem>
<menuItem title="5 minutes" tag="5" id="8ah-BL-bge">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="addChaptersEvery:" target="-2" id="s3s-EG-fNY"/>
</connections>
</menuItem>
<menuItem title="10 minutes" tag="10" id="lJT-6k-8XM">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="addChaptersEvery:" target="-2" id="zT1-7g-Dhw"/>
</connections>
</menuItem>
<menuItem title="15 minutes" tag="15" id="0bq-Ez-KMl">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="addChaptersEvery:" target="-2" id="CKK-mb-yau"/>
</connections>
</menuItem>
<menuItem title="20 minutes" tag="20" id="xWX-8M-yu0">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="addChaptersEvery:" target="-2" id="4SM-8E-UH8"/>
</connections>
</menuItem>
<menuItem title="30 minutes" tag="30" id="bmM-jp-jgC">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="addChaptersEvery:" target="-2" id="YWf-yb-tYK"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Organize alternate groups" id="lIX-K2-pbc">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="iTunesFriendlyTrackGroups:" target="-2" id="2bI-YD-rCZ"/>
</connections>
</menuItem>
<menuItem title="Clear tracks names" id="pB8-A8-7tv">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="clearTrackNames:" target="-2" id="MeX-3f-VXG"/>
</connections>
</menuItem>
<menuItem title="Prettify audio track names" id="SN3-Fe-fRS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="prettifyAudioTrackNames:" target="-2" id="Sde-MB-ZdJ"/>
</connections>
</menuItem>
<menuItem title="Fix audio fallbacks" id="rGe-lx-aht">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="fixAudioFallbacks:" target="-2" id="0By-xS-vpS"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="gUx-Ht-5aq"/>
<menuItem title="Offset…" id="9r1-yN-sCW">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showTrackOffsetSheet:" target="-2" id="0CQ-FC-l5B"/>
</connections>
</menuItem>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
</toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="FY3-O2-t3T"/>
<toolbarItem reference="V6w-Ey-bjV"/>
<toolbarItem reference="rhw-S4-nZ8"/>
<toolbarItem reference="qX7-s1-81X"/>
<toolbarItem reference="Af5-ai-sw9"/>
<toolbarItem reference="uiq-J2-uPs"/>
</defaultToolbarItems>
</toolbar>
<connections>
<outlet property="delegate" destination="-2" id="ifJ-VT-BdP"/>
</connections>
<point key="canvasLocation" x="212" y="-864"/>
</window>
</objects>
<resources>
<image name="NSActionTemplate" width="20" height="20"/>
<image name="NSAddTemplate" width="18" height="17"/>
<image name="NSRevealFreestandingTemplate" width="20" height="20"/>
<image name="ToolbarActionTemplate" width="24" height="24"/>
<image name="ToolbarRemoveTemplate" width="16" height="16"/>
</resources>
</document>
+59 -6
View File
@@ -9,18 +9,71 @@ import Cocoa
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) {
super.init(itemIdentifier: itemIdentifier)
self.label = label
self.toolTip = toolTip
self.image = NSImage(named: image)
self.action = action
if #available(macOS 14, *) {
self.isBordered = true
} else {
let button = NSButton.init(image: self.image!, target: self.target, action: self.action)
button.isBordered = true
button.bezelStyle = .toolbar
if #available(macOS 11, *) {
self.isBordered = true
let views = ["button" : button];
let constraint = NSLayoutConstraint.constraints(withVisualFormat: "H:[button(>=40)]",
options: [], metrics: nil, views: views)
NSLayoutConstraint.activate(constraint)
} else {
self.minSize = NSMakeSize(32, 16)
}
self.view = button
}
}
override func validate() {
if let target = target {
isEnabled = target.validateToolbarItem(self)
guard let action else { return }
if let target = NSApplication.shared.target(forAction: action, to: target, from: self) as? AnyObject {
if target.responds(to: #selector(NSUserInterfaceValidations.validateUserInterfaceItem(_:))) {
self.isEnabled = target.validateUserInterfaceItem(self)
} else if target.responds(to: #selector(NSToolbarItemValidation.validateToolbarItem(_:))) {
self.isEnabled = target.validateToolbarItem(self)
} else {
super.validate()
}
} else {
super.validate()
}
}
override var menuFormRepresentation: NSMenuItem? {
get {
let menuItem = NSMenuItem(title: label, action: action, keyEquivalent: "")
menuItem.target = target
menuItem.isEnabled = target?.validateToolbarItem(self) ?? false
return menuItem
if let menu = self.view?.menu {
let menuItem = NSMenuItem()
menuItem.title = self.label
if menu.numberOfItems > 0 {
menuItem.submenu = menu
} else {
menuItem.action = self.action
}
return menuItem
} else {
return NSMenuItem(title: self.label, action: self.action, keyEquivalent: "")
}
}
set (menuItem) {
super.menuFormRepresentation = menuItem
+121 -1
View File
@@ -7,6 +7,126 @@
import Cocoa
class DocumentToolbarDelegate: NSObject {
private extension NSToolbarItem.Identifier {
static let importTracks: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "AddTracks")
static let deleteTracks: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "DeleteTracks")
static let actions: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "Actions")
static let searchMetadata: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "SearchMetadata")
static let sendToQueue: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "SendToQueue")
static let showQueue: NSToolbarItem.Identifier = NSToolbarItem.Identifier(rawValue: "ShowQueue")
}
class DocumentToolbarDelegate: NSObject, NSToolbarDelegate {
@MainActor func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
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(_:)))
} 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(_:)))
} else if itemIdentifier == .actions {
let submenu = NSMenu()
for minutes in [1, 2, 5, 10, 15, 20, 30] {
let menuItem = NSMenuItem()
menuItem.title = minutes == 1 ? NSLocalizedString("1 minute", comment: "Toolbar") :
NSLocalizedString("\(minutes) minutes", comment: "Toolbar")
menuItem.action = #selector(DocumentWindowController.addChaptersEvery(_:))
menuItem.tag = minutes
submenu.addItem(menuItem)
}
let chapters = NSMenuItem()
chapters.title = NSLocalizedString("Insert a chapter every", comment: "Toolbar")
chapters.submenu = submenu
let menu = NSMenu()
menu.addItem(chapters)
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: NSLocalizedString("Organize alternate groups", comment: "Toolbar"),
action: #selector(DocumentWindowController.iTunesFriendlyTrackGroups(_:)),
keyEquivalent: "")
menu.addItem(withTitle: NSLocalizedString("Clear tracks names", comment: "Toolbar"),
action: #selector(DocumentWindowController.clearTrackNames(_:)),
keyEquivalent: "")
menu.addItem(withTitle: NSLocalizedString("Prettify audio track names", comment: "Toolbar"),
action: #selector(DocumentWindowController.prettifyAudioTrackNames(_:)),
keyEquivalent: "")
menu.addItem(withTitle: NSLocalizedString("Fix audio fallbacks", comment: "Toolbar"),
action: #selector(DocumentWindowController.fixAudioFallbacks(_:)),
keyEquivalent: "")
menu.addItem(NSMenuItem.separator())
menu.addItem(withTitle: NSLocalizedString("Offset…", comment: "Toolbar"),
action: #selector(DocumentWindowController.showTrackOffsetSheet(_:)),
keyEquivalent: "")
let label = NSLocalizedString("Action", comment: "Toolbar")
if #available(macOS 10.15, *) {
let item = NSMenuToolbarItem(itemIdentifier: itemIdentifier)
item.label = label
if #available(macOS 11.0, *) {
item.image = NSImage.init(systemSymbolName: "ellipsis.circle", accessibilityDescription: nil)
} else {
item.image = NSImage(named:"NSActionTemplate")
}
item.menu = menu
return item
} else {
let imageItem = NSMenuItem()
imageItem.image = NSImage(named:"NSActionTemplate")
imageItem.title = ""
menu.insertItem(imageItem, at: 0)
let popUpButton = NSPopUpButton()
popUpButton.bezelStyle = .toolbar
popUpButton.pullsDown = true
popUpButton.menu = menu
let item = ButtonToolbarItem(itemIdentifier: itemIdentifier)
item.label = label
item.view = popUpButton
item.minSize = NSSize(width: 48, height: 16)
return item
}
} 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(_:)))
} 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(_:)))
// 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(_:)))
}
return nil
}
@MainActor func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.importTracks, .deleteTracks, .actions, .flexibleSpace, .searchMetadata]
}
@MainActor func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.importTracks, .deleteTracks, .actions, .flexibleSpace, .searchMetadata, .sendToQueue, .showQueue, .flexibleSpace, .space]
}
}
+14 -24
View File
@@ -8,7 +8,7 @@
import Cocoa
import MP42Foundation
final class DocumentWindowController: NSWindowController, TracksViewControllerDelegate, MetadataSearchViewControllerDelegate, FileImportControllerDelegate, ProgressViewControllerDelegate, NSDraggingDestination, NSMenuItemValidation, NSToolbarItemValidation {
final class DocumentWindowController: NSWindowController, TracksViewControllerDelegate, MetadataSearchViewControllerDelegate, FileImportControllerDelegate, ProgressViewControllerDelegate, NSDraggingDestination, NSUserInterfaceValidations {
private var doc: Document {
return document as! Document
@@ -30,6 +30,8 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
fatalError("init(coder:) has not been implemented")
}
private let toolbarDelegate = DocumentToolbarDelegate()
override func windowDidLoad() {
super.windowDidLoad()
@@ -41,7 +43,12 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
window.toolbarStyle = .expanded
}
sendToQueue.image = NSImage(named: NSImage.shareTemplateName);
let toolbar = NSToolbar(identifier: "SublerDocumentToolbar")
toolbar.delegate = toolbarDelegate
toolbar.allowsUserCustomization = true
toolbar.autosavesConfiguration = true
toolbar.displayMode = .iconAndLabel
self.window?.toolbar = toolbar
window.contentViewController = splitViewController
window.registerForDraggedTypes([NSPasteboard.PasteboardType.fileURL])
@@ -208,29 +215,9 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
// MARK: Validation
@IBOutlet var addTracks: NSToolbarItem!
@IBOutlet var deleteTrack: NSToolbarItem!
@IBOutlet var searchMetadata: NSToolbarItem!
@IBOutlet var searchChapters: NSToolbarItem!
@IBOutlet var sendToQueue: NSToolbarItem!
func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
switch item.action {
func validateToolbarItem(_ item: NSToolbarItem) -> Bool {
if item == addTracks ||
item == searchMetadata ||
item == searchChapters ||
item == sendToQueue {
return true;
}
if item == deleteTrack {
return tracksViewController.selectedTracks.isEmpty == false && NSApp.isActive;
}
return false
}
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
switch menuItem.action {
case #selector(selectFile(_:)),
#selector(selectMetadataFile(_:)),
#selector(searchMetadata(_:)),
@@ -254,6 +241,9 @@ final class DocumentWindowController: NSWindowController, TracksViewControllerDe
return false
}
case #selector(DocumentWindowController.deleteTrack(_:)):
return tracksViewController.selectedTracks.isEmpty == false && NSApp.isActive
default:
return false
}
+32 -23
View File
@@ -8,7 +8,7 @@
import Cocoa
import MP42Foundation
final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDelegate, ItemViewDelegate, NSTableViewDataSource, NSTableViewDelegate, ExpandedTableViewDelegate, NSToolbarItemValidation, NSMenuItemValidation {
final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDelegate, ItemViewDelegate, NSTableViewDataSource, NSTableViewDelegate, ExpandedTableViewDelegate, NSUserInterfaceValidations {
static let shared = QueueController()
@@ -17,6 +17,7 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
private var popover: NSPopover?
private var itemPopover: NSPopover?
private var windowController: OptionsViewController?
private let toolbarDelegate = QueueToolbarDelegate()
private let tablePasteboardType = NSPasteboard.PasteboardType("SublerBatchTableViewDataType")
private lazy var docImg: NSImage = {
@@ -27,7 +28,6 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
}()
@IBOutlet var table: ExpandedTableView!
@IBOutlet var startItem: NSToolbarItem!
@IBOutlet var statusLabel: NSTextField!
@IBOutlet var progressBar: NSProgressIndicator!
@@ -61,6 +61,13 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
window?.toolbarStyle = .unified
}
let toolbar = NSToolbar(identifier: "SublerQueueToolbar")
toolbar.delegate = toolbarDelegate
toolbar.allowsUserCustomization = true
toolbar.autosavesConfiguration = true
toolbar.displayMode = .iconOnly
self.window?.toolbar = toolbar
table.registerForDraggedTypes([NSPasteboard.PasteboardType.fileURL, tablePasteboardType])
progressBar.isHidden = true
@@ -89,7 +96,9 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
self.progressBar.doubleValue = 0
self.progressBar.isIndeterminate = true
self.startItem.image = NSImage(named: "playBackTemplate")
if let toolbar = self.window?.toolbar {
self.toolbarDelegate.setState(working: false, toolbar: toolbar)
}
self.statusLabel.stringValue = NSLocalizedString("Done", comment: "Queue -> Done")
self.updateUI()
@@ -128,10 +137,9 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
//MARK: User Interface Validation
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
let action = menuItem.action
if action == #selector(removeSelectedItems(_:)) {
func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
switch item.action {
case #selector(removeSelectedItems(_:)):
if let row = table?.selectedRow, row != -1 {
let item = queue.item(at: row)
if item.status != .working {
@@ -143,35 +151,34 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
return true
}
}
}
if action == #selector(showInFinder(_:)) {
return false
case #selector(showInFinder(_:)):
if let row = table?.clickedRow, row != -1 {
let item = queue.item(at: row)
if item.status == .completed {
return true
}
}
}
if action == #selector(edit(_:)) {
return false
case #selector(edit(_:)):
if let row = table?.clickedRow, row != -1 {
let item = queue.item(at: row)
if item.status == .completed || item.status == .ready {
return true
}
}
}
if action == #selector(removeCompletedItems(_:)) {
return false
case #selector(removeCompletedItems(_:)):
return true
case #selector(toggleOptions(_:)):
return true
case #selector(toggleStartStop(_:)):
return true
case #selector(open(_:)):
return true
default:
return false
}
return false
}
func validateToolbarItem(_ item: NSToolbarItem) -> Bool {
return true
}
//MARK: Queue
@@ -600,7 +607,9 @@ final class QueueController : NSWindowController, NSWindowDelegate, NSPopoverDel
return
}
startItem.image = NSImage(named: "stopTemplate")
if let toolbar = self.window?.toolbar {
self.toolbarDelegate.setState(working: true, toolbar: toolbar)
}
statusLabel.stringValue = NSLocalizedString("Working.", comment: "Queue -> Working")
progressBar.isHidden = false
progressBar.startAnimation(self)
+50 -2
View File
@@ -7,6 +7,54 @@
import Cocoa
class QueueToolbarDelegate: NSObject {
private 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")
}
class QueueToolbarDelegate: NSObject, NSToolbarDelegate {
@MainActor func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
if itemIdentifier == .queueAdd {
return ButtonToolbarItem(itemIdentifier: itemIdentifier,
label: NSLocalizedString("Add Item", comment: "Toolbar"),
toolTip: NSLocalizedString("Add an item to the queue", comment: "Toolbar"),
image: "NSAddTemplate",
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",
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",
action: #selector(QueueController.toggleStartStop(_:)))
}
return nil
}
@MainActor func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.queueStartStop, .space, .queueSettings, .queueAdd]
}
@MainActor func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.queueStartStop, .queueSettings, .queueAdd, .flexibleSpace, .space]
}
func setState(working: Bool, toolbar: NSToolbar) {
guard let item = toolbar.items.first(where: { $0.itemIdentifier == .queueStartStop }) else { return }
if working {
item.image = NSImage(named: "stopTemplate")
} else {
item.image = NSImage(named: "playBackTemplate")
}
}
}