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

+3 -58
View File
@@ -1,15 +1,14 @@
<?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"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="QueueController" customModule="Subler" customModuleProvider="target">
<connections>
<outlet property="progressBar" destination="91" id="Pyo-9s-F6Q"/>
<outlet property="startItem" destination="xeY-tT-tF2" id="MmM-v9-enw"/>
<outlet property="statusLabel" destination="12" id="VYp-DC-guz"/>
<outlet property="table" destination="7" id="KrN-pl-mlK"/>
<outlet property="window" destination="1" id="25"/>
@@ -21,7 +20,7 @@
<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="98" y="651" width="378" height="351"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
<value key="minSize" type="size" width="378" height="200"/>
<view key="contentView" wantsLayer="YES" id="2">
<rect key="frame" x="0.0" y="0.0" width="378" height="351"/>
@@ -136,57 +135,6 @@
<constraint firstItem="12" firstAttribute="top" secondItem="91" secondAttribute="top" id="lVR-wY-vXK"/>
</constraints>
</view>
<toolbar key="toolbar" implicitIdentifier="7CCC4E53-430A-4EDF-8C9B-E7533A5972A1" autosavesConfiguration="NO" displayMode="iconOnly" sizeMode="regular" id="DiU-kc-8B9">
<allowedToolbarItems>
<toolbarItem implicitItemIdentifier="NSToolbarSpaceItem" id="4Tn-KL-e86"/>
<toolbarItem implicitItemIdentifier="NSToolbarFlexibleSpaceItem" id="Iau-lm-QMb"/>
<toolbarItem implicitItemIdentifier="3A987BC3-AE8F-4D56-8562-D2F37B9DA021" label="Add Item" paletteLabel="Add Item" toolTip="Add an item to the queue" image="NSAddTemplate" sizingBehavior="auto" id="mbj-v3-fFG" customClass="ButtonToolbarItem" customModule="Subler" customModuleProvider="target">
<button key="view" verticalHuggingPriority="750" id="sUh-2y-iie">
<rect key="frame" x="14" y="14" width="26" height="23"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSAddTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ZQu-If-3ju">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<connections>
<action selector="open:" target="-2" id="sdm-Bo-vsx"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="403860A1-8562-4F5B-BBEE-E8C1270A9077" label="Settings" paletteLabel="Settings" toolTip="Show/hide settings" image="NSActionTemplate" sizingBehavior="auto" id="Qif-lh-Rps" customClass="ButtonToolbarItem" customModule="Subler" customModuleProvider="target">
<button key="view" verticalHuggingPriority="750" id="tU5-DL-6vU">
<rect key="frame" x="12" y="14" width="27" height="23"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="NSActionTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Zdg-cC-Bdm">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<connections>
<action selector="toggleOptions:" target="-2" id="f6O-LF-uNy"/>
</connections>
</toolbarItem>
<toolbarItem implicitItemIdentifier="90FECCE0-5997-4C12-9158-9F7391313970" label="Start" paletteLabel="Start" toolTip="Start/stop queue" image="playBackTemplate" sizingBehavior="auto" id="xeY-tT-tF2" customClass="ButtonToolbarItem" customModule="Subler" customModuleProvider="target">
<button key="view" verticalHuggingPriority="750" id="sOU-an-jdB">
<rect key="frame" x="1" y="14" width="31" height="23"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="playBackTemplate" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="NP2-Hq-1TK">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<connections>
<action selector="toggleStartStop:" target="-2" id="hYg-up-ePS"/>
</connections>
</toolbarItem>
</allowedToolbarItems>
<defaultToolbarItems>
<toolbarItem reference="xeY-tT-tF2"/>
<toolbarItem reference="Iau-lm-QMb"/>
<toolbarItem reference="Qif-lh-Rps"/>
<toolbarItem reference="mbj-v3-fFG"/>
</defaultToolbarItems>
</toolbar>
<connections>
<outlet property="delegate" destination="-2" id="c4X-w0-NMZ"/>
</connections>
@@ -228,10 +176,7 @@
</objects>
<resources>
<image name="EncodeComplete" width="16" height="16"/>
<image name="NSActionTemplate" width="20" height="20"/>
<image name="NSAddTemplate" width="18" height="17"/>
<image name="info" width="16" height="16"/>
<image name="info-pressed" width="16" height="16"/>
<image name="playBackTemplate" width="19" height="18"/>
</resources>
</document>
+1 -1
View File
@@ -487,7 +487,7 @@
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="LiA-V6-VEx" userLabel="Change Subtitle Language Track">
<rect key="frame" x="111" y="247" width="218" height="16"/>
<string key="toolTip">In files with multiple subtitle tracks in different languages, this will enable the preferred langauge and disable all other tracks. For AppleTV and some other players, this allows the preferred language subtitles to play by default. A subtitle track labeled with the preferred language must exist in the file.</string>
<buttonCell key="cell" type="check" title="Enabled subtitles track with language" bezelStyle="regularSquare" imagePosition="left" controlSize="small" state="on" inset="2" id="LD5-Kv-x0M" userLabel="Change Subtitle Language Track">
<buttonCell key="cell" type="check" title="Enable subtitles track with language" bezelStyle="regularSquare" imagePosition="left" controlSize="small" state="on" inset="2" id="LD5-Kv-x0M" userLabel="Change Subtitle Language Track">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="smallSystem"/>
</buttonCell>
+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")
}
}
}
+8
View File
@@ -29,7 +29,9 @@
A90C3E0C1FD16AF200F64532 /* TokensViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A90C3E0A1FD16AF200F64532 /* TokensViewController.swift */; };
A90CD5C01FD177230070A067 /* TokensViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A90CD5C21FD177230070A067 /* TokensViewController.xib */; };
A90CD5C51FD177280070A067 /* OutputPrefsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A90CD5C71FD177280070A067 /* OutputPrefsViewController.xib */; };
A90D327D2C4931A700BC7A48 /* DocumentToolbarDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A90D327C2C4931A700BC7A48 /* DocumentToolbarDelegate.swift */; };
A91576EB204ECA6E00D93CE7 /* Token.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91576EA204ECA6E00D93CE7 /* Token.swift */; };
A9196C532C497030008C97F8 /* QueueToolbarDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9196C522C497030008C97F8 /* QueueToolbarDelegate.swift */; };
A91B196C1F2B0DCB0008675F /* QueueAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91B196B1F2B0DCB0008675F /* QueueAction.swift */; };
A91EB969205ABAF400392E1C /* NSWindowAdditions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91EB968205ABAF400392E1C /* NSWindowAdditions.swift */; };
A91F0FA023797F2800C9DCC9 /* PropertyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91F0F9F23797F2800C9DCC9 /* PropertyView.swift */; };
@@ -209,6 +211,7 @@
A90BC5E21F3A139700F9F3F3 /* MetadataResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MetadataResult.swift; path = Classes/MetadataImporters/MetadataResult.swift; sourceTree = "<group>"; };
A90C3E0A1FD16AF200F64532 /* TokensViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TokensViewController.swift; path = Classes/TokensViewController.swift; sourceTree = "<group>"; };
A90CD5C11FD177230070A067 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/TokensViewController.xib; sourceTree = "<group>"; };
A90D327C2C4931A700BC7A48 /* DocumentToolbarDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DocumentToolbarDelegate.swift; path = Classes/DocumentToolbarDelegate.swift; sourceTree = "<group>"; };
A9146847278D8EFB00860468 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/AdvancedPrefsViewController.strings; sourceTree = "<group>"; };
A9146848278D8EFB00860468 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/ArtworkSelector.strings; sourceTree = "<group>"; };
A9146849278D8EFB00860468 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/FileImportController.strings; sourceTree = "<group>"; };
@@ -240,6 +243,7 @@
A9146863278D8EFB00860468 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/InfoPlist.strings; sourceTree = "<group>"; };
A9146864278D8EFB00860468 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
A91576EA204ECA6E00D93CE7 /* Token.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Token.swift; path = Classes/Token.swift; sourceTree = "<group>"; };
A9196C522C497030008C97F8 /* QueueToolbarDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = QueueToolbarDelegate.swift; path = Classes/QueueToolbarDelegate.swift; sourceTree = "<group>"; };
A91B196B1F2B0DCB0008675F /* QueueAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = QueueAction.swift; path = Classes/QueueAction.swift; sourceTree = "<group>"; };
A91EB968205ABAF400392E1C /* NSWindowAdditions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NSWindowAdditions.swift; path = Classes/NSWindowAdditions.swift; sourceTree = "<group>"; };
A91F0F9F23797F2800C9DCC9 /* PropertyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PropertyView.swift; path = Classes/PropertyView/PropertyView.swift; sourceTree = "<group>"; };
@@ -618,6 +622,7 @@
A9AF6A7818D0537F00FAAB08 /* Queue */ = {
isa = PBXGroup;
children = (
A9196C522C497030008C97F8 /* QueueToolbarDelegate.swift */,
A97FBE3B21FC7F1C00F1FD35 /* QueueController.swift */,
A961476513F568210068F161 /* Queue.xib */,
A9C73535206B8F9900794673 /* QueuePreferences.swift */,
@@ -638,6 +643,7 @@
isa = PBXGroup;
children = (
A956C1E3202F1B170050C5E2 /* Document.swift */,
A90D327C2C4931A700BC7A48 /* DocumentToolbarDelegate.swift */,
A979B3842025C8BF00468362 /* DocumentWindowController.swift */,
A9ECA0592029A10B00D5F30C /* DocumentWindowController.xib */,
A9B1056C2025D9B9009E91FC /* TracksViewController.swift */,
@@ -873,6 +879,7 @@
A98542DC20D1A7E500EB9803 /* ArtworkSelectorViewItem.swift in Sources */,
A90C3E0C1FD16AF200F64532 /* TokensViewController.swift in Sources */,
A90B094C235614D200F1B191 /* AppleTV.swift in Sources */,
A9196C532C497030008C97F8 /* QueueToolbarDelegate.swift in Sources */,
A97D99DA22A0240C001FA3A7 /* OCRManager.swift in Sources */,
A90331BD23ED7EE5006BB91D /* Prefs.swift in Sources */,
A9DA03E322A0211C0056AE7B /* OCRPrefsViewController.swift in Sources */,
@@ -924,6 +931,7 @@
A9B514191EFC12310055A035 /* TheTVDB.swift in Sources */,
A9C31E602029A80F00CEF474 /* AdvancedPrefsViewController.swift in Sources */,
A979B3862025C8BF00468362 /* DocumentWindowController.swift in Sources */,
A90D327D2C4931A700BC7A48 /* DocumentToolbarDelegate.swift in Sources */,
A9067A0C1F3CA4E6008011DC /* MetadataPrefsViewController.swift in Sources */,
A9CBAB1E1F29C083001C26B3 /* MetadataImporter.swift in Sources */,
A92BBAB41F557CC0007EA182 /* PresetEditorViewController.swift in Sources */,