From 6ced2ff6b534529c70965c5463c156872348f456 Mon Sep 17 00:00:00 2001 From: Kartik Venugopal Date: Tue, 23 Apr 2024 22:33:13 +0200 Subject: [PATCH] Track Info - replace tables with textView, pretty scroller improvements --- macOS/Aural-macOS.xcodeproj/project.pbxproj | 12 +- .../UI/CustomViews/PrettyScroller.swift | 8 + .../TextFields/TintableTextField.swift | 10 ++ .../ExpandedView/PlayQueueExpandedView.xib | 18 ++- .../SimpleView/PlayQueueSimpleView.xib | 8 +- .../TrackInfo/CoverArt/CoverArtTrackInfo.xib | 140 ++++------------- .../CoverArt/CoverArtTrackInfoSource.swift | 4 + .../CoverArtTrackInfoViewController.swift | 50 +++--- .../LyricsTrackInfoViewController.swift | 5 +- .../TrackInfo/Metadata/MetadataTrackInfo.xib | 147 ------------------ .../Metadata/MetadataTrackInfoSource.swift | 4 + .../MetadataTrackInfoViewController.swift | 60 +------ macOS/Source/UI/TrackInfo/TrackInfoKVList.xib | 60 +++++++ .../TrackInfoKVListViewController.swift | 108 +++++++++++++ .../Extensions/NSTableViewExtensions.swift | 36 +---- 15 files changed, 278 insertions(+), 392 deletions(-) delete mode 100644 macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfo.xib create mode 100644 macOS/Source/UI/TrackInfo/TrackInfoKVList.xib create mode 100644 macOS/Source/UI/TrackInfo/TrackInfoKVListViewController.swift diff --git a/macOS/Aural-macOS.xcodeproj/project.pbxproj b/macOS/Aural-macOS.xcodeproj/project.pbxproj index 6bdfe4023..c883abad5 100644 --- a/macOS/Aural-macOS.xcodeproj/project.pbxproj +++ b/macOS/Aural-macOS.xcodeproj/project.pbxproj @@ -585,6 +585,8 @@ 3EE9BCB7278A896800DFFDD7 /* ColorSchemeableBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EE9BCB6278A896800DFFDD7 /* ColorSchemeableBox.swift */; }; 3EEBC6EC27C14A4B00880DFD /* HorizontalSliderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEBC6EB27C14A4B00880DFD /* HorizontalSliderCell.swift */; }; 3EEBC6EE27C16CF700880DFD /* EffectsUnitStateObserverRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEBC6ED27C16CF700880DFD /* EffectsUnitStateObserverRegistry.swift */; }; + 3EEC6EC92BD8464A00BC5D32 /* TrackInfoKVListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEC6EC82BD8464A00BC5D32 /* TrackInfoKVListViewController.swift */; }; + 3EEC6ECB2BD8472200BC5D32 /* TrackInfoKVList.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3EEC6ECA2BD8472200BC5D32 /* TrackInfoKVList.xib */; }; 3EEFF58927DE842C002CB0FE /* PlayQueueDelegateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEFF58327DE842C002CB0FE /* PlayQueueDelegateProtocol.swift */; }; 3EEFF58A27DE842C002CB0FE /* PlayQueueDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEFF58427DE842C002CB0FE /* PlayQueueDelegate.swift */; }; 3EEFF58B27DE842C002CB0FE /* PlayQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EEFF58527DE842C002CB0FE /* PlayQueue.swift */; }; @@ -611,7 +613,6 @@ 3EFAA8D52B7146AC001A6682 /* ChaptersListSearchFieldCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EFAA8D42B7146AC001A6682 /* ChaptersListSearchFieldCell.swift */; }; 3EFB64932772361D00D47A6B /* TimeStretchSliderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EFB64922772361D00D47A6B /* TimeStretchSliderCell.swift */; }; 3EFB64952772491C00D47A6B /* EffectsUnitTriStateCheckButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EFB64942772491C00D47A6B /* EffectsUnitTriStateCheckButton.swift */; }; - 3EFB9ECF26A689D800EA8440 /* MetadataTrackInfo.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3EFB9ECE26A689D800EA8440 /* MetadataTrackInfo.xib */; }; 3EFB9ED326A68A2400EA8440 /* TrackInfoViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EFB9ED226A68A2400EA8440 /* TrackInfoViewDelegate.swift */; }; 3EFB9ED626A68B1F00EA8440 /* MetadataTrackInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EFB9ED526A68B1F00EA8440 /* MetadataTrackInfoViewController.swift */; }; 3EFE0A8C2B4B364200C9B121 /* TrackHistoryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EFE0A8B2B4B364200C9B121 /* TrackHistoryItem.swift */; }; @@ -1633,6 +1634,8 @@ 3EEABD432B56D47E00263797 /* Library+Build.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Library+Build.swift"; sourceTree = ""; }; 3EEBC6EB27C14A4B00880DFD /* HorizontalSliderCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HorizontalSliderCell.swift; sourceTree = ""; }; 3EEBC6ED27C16CF700880DFD /* EffectsUnitStateObserverRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EffectsUnitStateObserverRegistry.swift; sourceTree = ""; }; + 3EEC6EC82BD8464A00BC5D32 /* TrackInfoKVListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackInfoKVListViewController.swift; sourceTree = ""; }; + 3EEC6ECA2BD8472200BC5D32 /* TrackInfoKVList.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TrackInfoKVList.xib; sourceTree = ""; }; 3EEFF58327DE842C002CB0FE /* PlayQueueDelegateProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayQueueDelegateProtocol.swift; sourceTree = ""; }; 3EEFF58427DE842C002CB0FE /* PlayQueueDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayQueueDelegate.swift; sourceTree = ""; }; 3EEFF58527DE842C002CB0FE /* PlayQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayQueue.swift; sourceTree = ""; }; @@ -1674,7 +1677,6 @@ 3EFAA8D42B7146AC001A6682 /* ChaptersListSearchFieldCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChaptersListSearchFieldCell.swift; sourceTree = ""; }; 3EFB64922772361D00D47A6B /* TimeStretchSliderCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeStretchSliderCell.swift; sourceTree = ""; }; 3EFB64942772491C00D47A6B /* EffectsUnitTriStateCheckButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EffectsUnitTriStateCheckButton.swift; sourceTree = ""; }; - 3EFB9ECE26A689D800EA8440 /* MetadataTrackInfo.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MetadataTrackInfo.xib; sourceTree = ""; }; 3EFB9ED226A68A2400EA8440 /* TrackInfoViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackInfoViewDelegate.swift; sourceTree = ""; }; 3EFB9ED526A68B1F00EA8440 /* MetadataTrackInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetadataTrackInfoViewController.swift; sourceTree = ""; }; 3EFE0A8B2B4B364200C9B121 /* TrackHistoryItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrackHistoryItem.swift; sourceTree = ""; }; @@ -3359,6 +3361,8 @@ 3E1341272B6F008E009782B6 /* TrackInfoViewController+MenuDelegate.swift */, 3EFB9ED226A68A2400EA8440 /* TrackInfoViewDelegate.swift */, 3E36BD4D26A6AA5A00B6E28B /* TableViewRepresentations.swift */, + 3EEC6ECA2BD8472200BC5D32 /* TrackInfoKVList.xib */, + 3EEC6EC82BD8464A00BC5D32 /* TrackInfoKVListViewController.swift */, 3EFB9ECC26A688B100EA8440 /* Metadata */, 3E36BD2F26A68E7800B6E28B /* Lyrics */, 3E36BD3626A68F6300B6E28B /* CoverArt */, @@ -4232,7 +4236,6 @@ 3EFB9ECC26A688B100EA8440 /* Metadata */ = { isa = PBXGroup; children = ( - 3EFB9ECE26A689D800EA8440 /* MetadataTrackInfo.xib */, 3EFB9ED526A68B1F00EA8440 /* MetadataTrackInfoViewController.swift */, 3E6C103725CEB98600BF0D07 /* MetadataTrackInfoSource.swift */, ); @@ -5219,7 +5222,6 @@ 3EF0C3E5262A9EF30042C720 /* CreateTheme.xib in Resources */, 3EAF96FD28DCE1B6008561A7 /* coming-soon.regular.ttf in Resources */, 3E51CCF0285E8986002CBEF2 /* UnifiedPlayerSidebar.xib in Resources */, - 3EFB9ECF26A689D800EA8440 /* MetadataTrackInfo.xib in Resources */, 3E6C125E25CEBE0600BF0D07 /* ReverbPresetsManager.xib in Resources */, 3E6C12A425CEBE2700BF0D07 /* AboutDialog.xib in Resources */, 3E8C370D2BD402080045FC92 /* CompactPlayerCoverArtTrackInfo.xib in Resources */, @@ -5234,6 +5236,7 @@ 3ECBF3082619D58E00AD5C30 /* AudioUnits.xib in Resources */, 3E6C126625CEBE0600BF0D07 /* DelayPresetsManager.xib in Resources */, 3E5F943425E571A6002DEF80 /* Visualizer.xib in Resources */, + 3EEC6ECB2BD8472200BC5D32 /* TrackInfoKVList.xib in Resources */, 3E2000C1267CE00E008BAB70 /* GesturesPreferences.xib in Resources */, 3E6C12FC25CEBE8F00BF0D07 /* ModularPlayer.xib in Resources */, 3EAF96FF28DCE1B6008561A7 /* CarroisGothicSC-Regular.ttf in Resources */, @@ -5339,6 +5342,7 @@ 3EFE3A8727864898006F8B8C /* FileSystemInfo.swift in Sources */, 3ECBF30A2619DF7200AD5C30 /* AudioUnitsViewController+TableViewDelegate.swift in Sources */, 3E6C66A92B54686D00AA0D81 /* LegacyAudioGraphPersistentState.swift in Sources */, + 3EEC6EC92BD8464A00BC5D32 /* TrackInfoKVListViewController.swift in Sources */, 3EFE387527864896006F8B8C /* ReverbUnit.swift in Sources */, 3ECBF3062619D58500AD5C30 /* AudioUnitsViewController.swift in Sources */, 3E6C128525CEBE1800BF0D07 /* AuralColorPicker.swift in Sources */, diff --git a/macOS/Source/UI/CustomViews/PrettyScroller.swift b/macOS/Source/UI/CustomViews/PrettyScroller.swift index bb48d2225..a1e92222b 100644 --- a/macOS/Source/UI/CustomViews/PrettyScroller.swift +++ b/macOS/Source/UI/CustomViews/PrettyScroller.swift @@ -21,14 +21,22 @@ class PrettyScroller: NSScroller { var knobColor: NSColor = NSColor.gray + @IBOutlet weak var scrollView: NSScrollView! + @IBOutlet weak var contentView: NSView! + override func awakeFromNib() { self.scrollerStyle = .overlay } override func drawKnob() { + if contentView != nil, scrollView != nil, contentView.height <= scrollView.height { + return + } + let knobRect = self.rect(for: .knob).insetBy(dx: knobInsetX, dy: knobInsetY) if knobRect.height <= 0 || knobRect.width <= 0 {return} + NSBezierPath.fillRoundedRect(knobRect, radius: knobRadius, withColor: .scrollerKnobColor) } diff --git a/macOS/Source/UI/CustomViews/TextFields/TintableTextField.swift b/macOS/Source/UI/CustomViews/TextFields/TintableTextField.swift index 44158a8f9..a3ab8fa2b 100644 --- a/macOS/Source/UI/CustomViews/TextFields/TintableTextField.swift +++ b/macOS/Source/UI/CustomViews/TextFields/TintableTextField.swift @@ -23,3 +23,13 @@ extension NSTextField: ColorSchemePropertyChangeReceiver { // font = newFont // } //} + +extension NSTextView { + + func setBackgroundColor(_ newColor: PlatformColor) { + + backgroundColor = newColor + enclosingScrollView?.backgroundColor = newColor + enclosingScrollView?.contentView.backgroundColor = newColor + } +} diff --git a/macOS/Source/UI/PlayQueue/ExpandedView/PlayQueueExpandedView.xib b/macOS/Source/UI/PlayQueue/ExpandedView/PlayQueueExpandedView.xib index 0947efda4..85acea0bd 100644 --- a/macOS/Source/UI/PlayQueue/ExpandedView/PlayQueueExpandedView.xib +++ b/macOS/Source/UI/PlayQueue/ExpandedView/PlayQueueExpandedView.xib @@ -1,8 +1,8 @@ - + - + @@ -98,7 +98,7 @@ - + @@ -109,7 +109,7 @@ - + @@ -120,7 +120,7 @@ - + @@ -168,7 +168,7 @@ - + @@ -205,9 +205,13 @@ - diff --git a/macOS/Source/UI/PlayQueue/SimpleView/PlayQueueSimpleView.xib b/macOS/Source/UI/PlayQueue/SimpleView/PlayQueueSimpleView.xib index 2b251a21f..4b60377d1 100644 --- a/macOS/Source/UI/PlayQueue/SimpleView/PlayQueueSimpleView.xib +++ b/macOS/Source/UI/PlayQueue/SimpleView/PlayQueueSimpleView.xib @@ -14,7 +14,7 @@ - + @@ -173,9 +173,13 @@ - diff --git a/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfo.xib b/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfo.xib index 775605a82..db67d3b5b 100644 --- a/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfo.xib +++ b/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfo.xib @@ -10,8 +10,7 @@ - - + @@ -34,101 +33,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + - - - + - - - - - diff --git a/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfoSource.swift b/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfoSource.swift index 13d8e566c..f95c5ddea 100644 --- a/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfoSource.swift +++ b/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfoSource.swift @@ -16,6 +16,10 @@ class CoverArtTrackInfoSource: TrackInfoSource { private(set) var trackInfo: [KeyValuePair] = [] + static let instance: CoverArtTrackInfoSource = .init() + + private init() {} + func loadTrackInfo(for track: Track) { trackInfo.removeAll() diff --git a/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfoViewController.swift b/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfoViewController.swift index cdaf5ce56..af7c2468f 100644 --- a/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfoViewController.swift +++ b/macOS/Source/UI/TrackInfo/CoverArt/CoverArtTrackInfoViewController.swift @@ -9,45 +9,38 @@ // import Cocoa -class CoverArtTrackInfoViewController: NSViewController, TrackInfoViewProtocol { +class CoverArtTrackInfoViewController: TrackInfoKVListViewController { override var nibName: String? {"CoverArtTrackInfo"} - @IBOutlet weak var tableView: NSTableView! - // Displays track artwork @IBOutlet weak var artView: NSImageView! @IBOutlet weak var lblNoArt: NSTextField! - private let trackInfoSource: CoverArtTrackInfoSource = .init() - @IBOutlet weak var tableViewDelegate: TrackInfoViewDelegate! { - - didSet { - tableViewDelegate.trackInfoSource = trackInfoSource - } + override var trackInfoSource: TrackInfoSource { + CoverArtTrackInfoSource.instance } // Called each time the popover is shown ... refreshes the data in the table view depending on which track is currently playing - func refresh() { + override func refresh() { guard let track = TrackInfoViewContext.displayedTrack else {return} - trackInfoSource.loadTrackInfo(for: track) - artView?.image = track.art?.image lblNoArt.showIf(artView?.image == nil) - tableView.reloadData() + super.refresh() } func trackInfoUpdated(_ notification: TrackInfoUpdatedNotification) { refresh() } - var jsonObject: AnyObject? { - artView.image != nil ? tableView.jsonObject : nil + override var jsonObject: AnyObject? { +// artView.image != nil ? tableView.jsonObject : nil + nil } - func writeHTML(to writer: HTMLWriter) { + override func writeHTML(to writer: HTMLWriter) { guard let track = TrackInfoViewContext.displayedTrack else {return} @@ -67,7 +60,7 @@ class CoverArtTrackInfoViewController: NSViewController, TrackInfoViewProtocol { writer.addImage(imgFile.lastPathComponent, "(Cover Art)") if artView.image != nil { - writer.addTable("Cover Art Metadata:", 3, nil, tableView.htmlTable) +// writer.addTable("Cover Art Metadata:", 3, nil, tableView.htmlTable) } } @@ -90,29 +83,22 @@ class CoverArtTrackInfoViewController: NSViewController, TrackInfoViewProtocol { // MARK: Theming --------------------------------------------------- - func fontSchemeChanged() { + override func fontSchemeChanged() { lblNoArt.font = systemFontScheme.normalFont - tableView.reloadData() + super.fontSchemeChanged() } - func colorSchemeChanged() { + override func colorSchemeChanged() { lblNoArt.textColor = systemColorScheme.primaryTextColor - tableView.setBackgroundColor(.yellow) - tableView.reloadData() + super.colorSchemeChanged() } - func backgroundColorChanged(_ newColor: PlatformColor) { - tableView.setBackgroundColor(newColor) - } - - func primaryTextColorChanged(_ newColor: PlatformColor) { - tableView.reloadAllRows(columns: [1]) - } - - func secondaryTextColorChanged(_ newColor: PlatformColor) { - tableView.reloadAllRows(columns: [0]) + override func primaryTextColorChanged(_ newColor: PlatformColor) { + + lblNoArt.textColor = newColor + super.primaryTextColorChanged(newColor) } } diff --git a/macOS/Source/UI/TrackInfo/Lyrics/LyricsTrackInfoViewController.swift b/macOS/Source/UI/TrackInfo/Lyrics/LyricsTrackInfoViewController.swift index 11aa328b6..da7a13812 100644 --- a/macOS/Source/UI/TrackInfo/Lyrics/LyricsTrackInfoViewController.swift +++ b/macOS/Source/UI/TrackInfo/Lyrics/LyricsTrackInfoViewController.swift @@ -58,10 +58,7 @@ class LyricsTrackInfoViewController: NSViewController, TrackInfoViewProtocol { } func backgroundColorChanged(_ newColor: PlatformColor) { - - textView.backgroundColor = newColor - textView.enclosingScrollView?.backgroundColor = newColor - textView.enclosingScrollView?.contentView.backgroundColor = newColor + textView.setBackgroundColor(newColor) } func primaryTextColorChanged(_ newColor: PlatformColor) { diff --git a/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfo.xib b/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfo.xib deleted file mode 100644 index 025d50b58..000000000 --- a/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfo.xib +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfoSource.swift b/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfoSource.swift index 266e8c8f6..17f6d0849 100644 --- a/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfoSource.swift +++ b/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfoSource.swift @@ -13,6 +13,10 @@ class MetadataTrackInfoSource: TrackInfoSource { private(set) var trackInfo: [KeyValuePair] = [] + static let instance: MetadataTrackInfoSource = .init() + + private init() {} + func loadTrackInfo(for track: Track) { trackInfo.removeAll() diff --git a/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfoViewController.swift b/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfoViewController.swift index 8f125dc2d..a12636cb1 100644 --- a/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfoViewController.swift +++ b/macOS/Source/UI/TrackInfo/Metadata/MetadataTrackInfoViewController.swift @@ -9,64 +9,14 @@ // import Cocoa -class MetadataTrackInfoViewController: NSViewController, TrackInfoViewProtocol { +class MetadataTrackInfoViewController: TrackInfoKVListViewController { - override var nibName: String? {"MetadataTrackInfo"} - - private let trackInfoSource: MetadataTrackInfoSource = .init() - @IBOutlet weak var tableViewDelegate: TrackInfoViewDelegate! { - - didSet { - tableViewDelegate.trackInfoSource = trackInfoSource - } - } - - // The table view that displays the track info - @IBOutlet weak var tableView: NSTableView! { - - didSet { - tableView.enclosingScrollView?.scrollerInsets = NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 1) - } - } - - // Called each time the popover is shown ... refreshes the data in the table view depending on which track is currently playing - func refresh() { - - guard let track = TrackInfoViewContext.displayedTrack else {return} - trackInfoSource.loadTrackInfo(for: track) - tableView.reloadData() - } - - var jsonObject: AnyObject? { - tableView.jsonObject - } - - func writeHTML(to writer: HTMLWriter) { - writer.addTable("Metadata:", 3, nil, tableView.htmlTable) - } - - // MARK: Theming --------------------------------------------------- - - func fontSchemeChanged() { - tableView.reloadData() - } - - func colorSchemeChanged() { - - tableView.setBackgroundColor(systemColorScheme.backgroundColor) - tableView.reloadData() - } - - func backgroundColorChanged(_ newColor: PlatformColor) { - tableView.setBackgroundColor(newColor) - } - - func primaryTextColorChanged(_ newColor: PlatformColor) { - tableView.reloadAllRows(columns: [1]) + override var trackInfoSource: TrackInfoSource { + MetadataTrackInfoSource.instance } - func secondaryTextColorChanged(_ newColor: PlatformColor) { - tableView.reloadAllRows(columns: [0]) + override func writeHTML(to writer: HTMLWriter) { +// writer.addTable("Metadata:", 3, nil, tableView.htmlTable) } } diff --git a/macOS/Source/UI/TrackInfo/TrackInfoKVList.xib b/macOS/Source/UI/TrackInfo/TrackInfoKVList.xib new file mode 100644 index 000000000..16e0f8fc7 --- /dev/null +++ b/macOS/Source/UI/TrackInfo/TrackInfoKVList.xib @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macOS/Source/UI/TrackInfo/TrackInfoKVListViewController.swift b/macOS/Source/UI/TrackInfo/TrackInfoKVListViewController.swift new file mode 100644 index 000000000..23c71e5f0 --- /dev/null +++ b/macOS/Source/UI/TrackInfo/TrackInfoKVListViewController.swift @@ -0,0 +1,108 @@ +// +// TrackInfoKVListViewController.swift +// Aural +// +// Copyright © 2021 Kartik Venugopal. All rights reserved. +// +// This software is licensed under the MIT software license. +// See the file "LICENSE" in the project root directory for license terms. +// + +import AppKit + +class TrackInfoKVListViewController: NSViewController, TrackInfoViewProtocol { + + override var nibName: String? {"TrackInfoKVList"} + + var trackInfoSource: TrackInfoSource { + MetadataTrackInfoSource.instance + } + + // The table view that displays the track info + @IBOutlet weak var textView: NSTextView! + + // Called each time the popover is shown ... refreshes the data in the table view depending on which track is currently playing + func refresh() { + + guard let track = TrackInfoViewContext.displayedTrack else {return} + trackInfoSource.loadTrackInfo(for: track) + update() + } + + // Constructs the formatted "rich" text to be displayed in the text view + func update() { + + // First, clear the view to remove any old text + textView.string = "" + + for (key, value) in trackInfoSource.trackInfo { + + appendString(text: key, font: systemFontScheme.normalFont, color: systemColorScheme.secondaryTextColor, lineSpacing: 20) + appendString(text: value, font: systemFontScheme.normalFont, color: systemColorScheme.primaryTextColor, lineSpacing: 5) + } + } + + /* + Helper factory function to construct an NSAttributedString (i.e. "rich text"), given all its attributes. + + @param lineSpacing (optional) + Amout of spacing between this line of text and the next line. Nil value indicates no spacing. + Non-nil value will result in a line break being added to the text (to separate lines). + */ + private func appendString(text: String, font: NSFont, color: NSColor, lineSpacing: CGFloat? = nil) { + + var attributes: [NSAttributedString.Key: Any] = [.font: font, .foregroundColor: color] + let style = NSMutableParagraphStyle() + var str: String = text + + style.alignment = .left + + if let spacing = lineSpacing { + + // If lineSpacing is specified, add a paragraph style attribute and set its lineSpacing field. + style.lineSpacing = spacing + + // Add a newline character to the text to create a line break + str += "\n" + } + + attributes[.paragraphStyle] = style + + textView.textStorage?.append(NSAttributedString(string: str, attributes: attributes)) + } + + // MARK: Export --------------------------------------------------- + + var jsonObject: AnyObject? { +// tableView.jsonObject + nil + } + + func writeHTML(to writer: HTMLWriter) { +// writer.addTable("Metadata:", 3, nil, tableView.htmlTable) + } + + // MARK: Theming --------------------------------------------------- + + func fontSchemeChanged() { + update() + } + + func colorSchemeChanged() { + + textView.setBackgroundColor(systemColorScheme.backgroundColor) + update() + } + + func backgroundColorChanged(_ newColor: PlatformColor) { + textView.setBackgroundColor(systemColorScheme.backgroundColor) + } + + func primaryTextColorChanged(_ newColor: PlatformColor) { + update() + } + + func secondaryTextColorChanged(_ newColor: PlatformColor) { + update() + } +} diff --git a/macOS/Source/UI/Utils/Extensions/NSTableViewExtensions.swift b/macOS/Source/UI/Utils/Extensions/NSTableViewExtensions.swift index 7dc615756..d1fd6992d 100644 --- a/macOS/Source/UI/Utils/Extensions/NSTableViewExtensions.swift +++ b/macOS/Source/UI/Utils/Extensions/NSTableViewExtensions.swift @@ -123,45 +123,13 @@ extension NSTableView { } func pageUp() { - - guard self.numberOfRows > 3 else {return} - - // Determine if the last row currently displayed has been truncated so it is not fully visible - let visibleRect = self.visibleRect - let visibleRows = self.rows(in: visibleRect) - let numVisibleRows = Int(visibleRect.height / heightOfARow) - - let firstRowShown = visibleRows.lowerBound - let firstRowShownRect = self.rect(ofRow: firstRowShown) - let firstRowShownFully = CGRectContainsRect(visibleRect, firstRowShownRect) - - // If the first row currently displayed has been truncated more than 10%, show it again in the next page - - let lastRowToShow = firstRowShownFully ? firstRowShown - 1 : firstRowShown - let scrollRow = max(lastRowToShow - numVisibleRows + 1, 0) - - scrollRowToVisible(scrollRow) + enclosingScrollView?.pageUp(self) } var heightOfARow: CGFloat {self.rect(ofRow: 0).height} func pageDown() { - - guard self.numberOfRows > 3 else {return} - - // Determine if the last row currently displayed has been truncated so it is not fully visible - let visibleRect = self.visibleRect - let visibleRows = self.rows(in: visibleRect) - let numVisibleRows = Int(visibleRect.height / heightOfARow) - - let lastRowShown = visibleRows.lowerBound + visibleRows.length - 1 - let lastRowShownRect = self.rect(ofRow: lastRowShown) - let lastRowShownFully = CGRectContainsRect(visibleRect, lastRowShownRect) - - let firstRowToShow = lastRowShownFully ? lastRowShown + 1 : lastRowShown - let scrollRow = min(firstRowToShow + numVisibleRows - 1, self.numberOfRows - 1) - - scrollRowToVisible(scrollRow) + enclosingScrollView?.pageDown(self) } // Scrolls the playlist view to the very top