Skip to content

Commit 5d899e6

Browse files
committed
updated
1 parent 2669366 commit 5d899e6

11 files changed

+332
-99
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
728F108F2B43A32600EE2F2B /* AdvancedCollectionTableView in Frameworks */ = {isa = PBXBuildFile; productRef = 728F108E2B43A32600EE2F2B /* AdvancedCollectionTableView */; };
2424
72A0C7D72B501EE600779BA0 /* AdvancedCollectionTableView in Frameworks */ = {isa = PBXBuildFile; productRef = 72A0C7D62B501EE600779BA0 /* AdvancedCollectionTableView */; };
2525
72AFC23A29804B7D00FEA1C8 /* CollectionItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72AFC23929804B7D00FEA1C8 /* CollectionItem.swift */; };
26-
72AFC2B42980ECA600FEA1C8 /* SidebarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72AFC2B32980ECA600FEA1C8 /* SidebarViewController.swift */; };
26+
72AFC2B42980ECA600FEA1C8 /* TableSidebarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72AFC2B32980ECA600FEA1C8 /* TableSidebarViewController.swift */; };
2727
72DE39892979905C007EACAF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72DE39882979905C007EACAF /* AppDelegate.swift */; };
2828
72DE398B2979905C007EACAF /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72DE398A2979905C007EACAF /* MainViewController.swift */; };
2929
72DE398D2979905D007EACAF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 72DE398C2979905D007EACAF /* Assets.xcassets */; };
3030
72DE39902979905D007EACAF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 72DE398E2979905D007EACAF /* Main.storyboard */; };
3131
72F02E0E2AE117BC00D8D3D7 /* Dystopian City.png in Resources */ = {isa = PBXBuildFile; fileRef = 72F02E0C2AE117BC00D8D3D7 /* Dystopian City.png */; };
3232
72F02E0F2AE117BC00D8D3D7 /* Fireworker Monkey.png in Resources */ = {isa = PBXBuildFile; fileRef = 72F02E0D2AE117BC00D8D3D7 /* Fireworker Monkey.png */; };
3333
72F049452B4325F700A6871E /* Neil Catstrong.png in Resources */ = {isa = PBXBuildFile; fileRef = 72F049442B4325F400A6871E /* Neil Catstrong.png */; };
34+
72F4CC442D3DF8FD00F2A734 /* SplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72F4CC422D3DF8FD00F2A734 /* SplitViewController.swift */; };
3435
72F99B662A44FBCB00DDDA1E /* Section.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72F99B652A44FBCB00DDDA1E /* Section.swift */; };
3536
72F99B682A44FBDD00DDDA1E /* SidebarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72F99B672A44FBDD00DDDA1E /* SidebarItem.swift */; };
3637
/* End PBXBuildFile section */
@@ -48,7 +49,7 @@
4849
727665F52A55E61700F1FD9F /* Cosmojelly.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Cosmojelly.png; path = "Example/Sample Images/Cosmojelly.png"; sourceTree = SOURCE_ROOT; };
4950
727665F62A55E61700F1FD9F /* Berghain.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Berghain.png; path = "Example/Sample Images/Berghain.png"; sourceTree = SOURCE_ROOT; };
5051
72AFC23929804B7D00FEA1C8 /* CollectionItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionItem.swift; sourceTree = "<group>"; };
51-
72AFC2B32980ECA600FEA1C8 /* SidebarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarViewController.swift; sourceTree = "<group>"; };
52+
72AFC2B32980ECA600FEA1C8 /* TableSidebarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableSidebarViewController.swift; sourceTree = "<group>"; };
5253
72DE39852979905C007EACAF /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
5354
72DE39882979905C007EACAF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5455
72DE398A2979905C007EACAF /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
@@ -58,6 +59,7 @@
5859
72F02E0C2AE117BC00D8D3D7 /* Dystopian City.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Dystopian City.png"; sourceTree = "<group>"; };
5960
72F02E0D2AE117BC00D8D3D7 /* Fireworker Monkey.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Fireworker Monkey.png"; sourceTree = "<group>"; };
6061
72F049442B4325F400A6871E /* Neil Catstrong.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Neil Catstrong.png"; sourceTree = "<group>"; };
62+
72F4CC422D3DF8FD00F2A734 /* SplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitViewController.swift; sourceTree = "<group>"; };
6163
72F99B652A44FBCB00DDDA1E /* Section.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Section.swift; sourceTree = "<group>"; };
6264
72F99B672A44FBDD00DDDA1E /* SidebarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarItem.swift; sourceTree = "<group>"; };
6365
/* End PBXFileReference section */
@@ -117,8 +119,9 @@
117119
children = (
118120
72DE39882979905C007EACAF /* AppDelegate.swift */,
119121
72DE398A2979905C007EACAF /* MainViewController.swift */,
120-
72AFC2B32980ECA600FEA1C8 /* SidebarViewController.swift */,
122+
72AFC2B32980ECA600FEA1C8 /* TableSidebarViewController.swift */,
121123
726BE26B2D3DB15700823E9B /* OutlineSidebarViewController.swift */,
124+
72F4CC422D3DF8FD00F2A734 /* SplitViewController.swift */,
122125
72F99B642A44FBC000DDDA1E /* Model */,
123126
72D95F492A46ED86008B1FE6 /* Sample Images */,
124127
72DE398C2979905D007EACAF /* Assets.xcassets */,
@@ -236,7 +239,8 @@
236239
72AFC23A29804B7D00FEA1C8 /* CollectionItem.swift in Sources */,
237240
72F99B662A44FBCB00DDDA1E /* Section.swift in Sources */,
238241
72F99B682A44FBDD00DDDA1E /* SidebarItem.swift in Sources */,
239-
72AFC2B42980ECA600FEA1C8 /* SidebarViewController.swift in Sources */,
242+
72F4CC442D3DF8FD00F2A734 /* SplitViewController.swift in Sources */,
243+
72AFC2B42980ECA600FEA1C8 /* TableSidebarViewController.swift in Sources */,
240244
726BE26C2D3DB15700823E9B /* OutlineSidebarViewController.swift in Sources */,
241245
72DE39892979905C007EACAF /* AppDelegate.swift in Sources */,
242246
);

Example/Example/Base.lproj/Main.storyboard

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -731,11 +731,11 @@
731731
<rect key="frame" x="0.0" y="0.0" width="220" height="556"/>
732732
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
733733
<subviews>
734-
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="13" outlineTableColumn="dkC-fw-nsz" id="OL6-2g-mY0">
734+
<outlineView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="sourceList" selectionHighlightStyle="sourceList" columnReordering="NO" columnResizing="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" viewBased="YES" indentationPerLevel="13" outlineTableColumn="dkC-fw-nsz" id="OL6-2g-mY0">
735735
<rect key="frame" x="0.0" y="0.0" width="220" height="556"/>
736736
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
737-
<size key="intercellSpacing" width="17" height="0.0"/>
738-
<color key="backgroundColor" red="1" green="1" blue="1" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
737+
<size key="intercellSpacing" width="3" height="0.0"/>
738+
<color key="backgroundColor" name="_sourceListBackgroundColor" catalog="System" colorSpace="catalog"/>
739739
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
740740
<tableColumns>
741741
<tableColumn identifier="AutomaticTableColumnIdentifier.0" width="178" minWidth="40" maxWidth="1000" id="dkC-fw-nsz">
@@ -751,11 +751,11 @@
751751
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
752752
<prototypeCellViews>
753753
<tableCellView id="Znc-hb-lwg">
754-
<rect key="frame" x="18" y="0.0" width="173" height="24"/>
754+
<rect key="frame" x="11" y="0.0" width="187" height="24"/>
755755
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
756756
<subviews>
757757
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TwF-bG-26t">
758-
<rect key="frame" x="0.0" y="4" width="173" height="16"/>
758+
<rect key="frame" x="0.0" y="4" width="187" height="16"/>
759759
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
760760
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="mg0-B0-XJ4">
761761
<font key="font" usesAppearanceFont="YES"/>
@@ -784,6 +784,42 @@
784784
<autoresizingMask key="autoresizingMask"/>
785785
</scroller>
786786
</scrollView>
787+
<visualEffectView fixedFrame="YES" blendingMode="withinWindow" material="appearanceBased" state="followsWindowActiveState" translatesAutoresizingMaskIntoConstraints="NO" id="H97-Fn-scY">
788+
<rect key="frame" x="0.0" y="0.0" width="220" height="180"/>
789+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
790+
<subviews>
791+
<box verticalHuggingPriority="750" fixedFrame="YES" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="69l-J2-Vtw">
792+
<rect key="frame" x="20" y="177" width="180" height="5"/>
793+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
794+
</box>
795+
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="s9N-XY-cUg">
796+
<rect key="frame" x="18" y="53" width="184" height="118"/>
797+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
798+
<textFieldCell key="cell" id="2H0-Zm-1Ot">
799+
<font key="font" textStyle="body" name=".SFNS-Regular"/>
800+
<string key="title">Reorder items and outline cells by dragging them and delete them via backspace.
801+
802+
Quicklook collection items via spacebar and favorite them by right-clicking them.</string>
803+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
804+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
805+
</textFieldCell>
806+
</textField>
807+
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6Ef-kZ-Evo">
808+
<rect key="frame" x="17" y="19" width="162" height="24"/>
809+
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
810+
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="ZUF-hD-N4J">
811+
<font key="font" metaFont="system"/>
812+
<segments>
813+
<segment label="TableView"/>
814+
<segment label="OutlineView" selected="YES" tag="1"/>
815+
</segments>
816+
</segmentedCell>
817+
<connections>
818+
<action selector="segmentedPressed:" target="pHe-8d-Ckn" id="4np-g9-H4g"/>
819+
</connections>
820+
</segmentedControl>
821+
</subviews>
822+
</visualEffectView>
787823
</subviews>
788824
</view>
789825
<connections>
@@ -797,11 +833,10 @@
797833
<!--Split View Controller-->
798834
<scene sceneID="kZ3-XE-N79">
799835
<objects>
800-
<splitViewController id="DML-nL-2eg" sceneMemberID="viewController">
836+
<splitViewController id="DML-nL-2eg" customClass="SplitViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
801837
<splitViewItems>
802838
<splitViewItem canCollapse="YES" holdingPriority="260" behavior="sidebar" id="bFe-Mf-mBl"/>
803839
<splitViewItem id="7hD-QQ-ruv"/>
804-
<splitViewItem id="l6a-44-3F1"/>
805840
</splitViewItems>
806841
<splitView key="splitView" dividerStyle="thin" vertical="YES" id="Wb5-Zx-fWz">
807842
<rect key="frame" x="0.0" y="0.0" width="700" height="500"/>
@@ -810,7 +845,6 @@
810845
<connections>
811846
<segue destination="IgV-tW-gYz" kind="relationship" relationship="splitItems" id="NB4-kc-ruk"/>
812847
<segue destination="f1U-rY-vlz" kind="relationship" relationship="splitItems" id="wfQ-Cb-UbV"/>
813-
<segue destination="pHe-8d-Ckn" kind="relationship" relationship="splitItems" id="I6v-Lg-hol"/>
814848
</connections>
815849
</splitViewController>
816850
<customObject id="yJe-I5-mQc" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
@@ -926,7 +960,7 @@
926960
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
927961
</box>
928962
<textField focusRingType="none" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" id="mrG-QP-ihx">
929-
<rect key="frame" x="18" y="53" width="184" height="176"/>
963+
<rect key="frame" x="18" y="58" width="184" height="176"/>
930964
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
931965
<textFieldCell key="cell" id="pTN-Rj-Fnb">
932966
<font key="font" textStyle="body" name=".SFNS-Regular"/>
@@ -940,7 +974,7 @@ Favorite table cells by swiping left and delete them by swiping right.</string>
940974
</textFieldCell>
941975
</textField>
942976
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0Yv-Ur-r5h">
943-
<rect key="frame" x="29" y="19" width="162" height="24"/>
977+
<rect key="frame" x="17" y="19" width="162" height="24"/>
944978
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
945979
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="mug-3m-xIo">
946980
<font key="font" metaFont="system"/>

Example/Example/OutlineSidebarViewController.swift

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,43 @@ class OutlineSidebarViewController: NSViewController {
1515
@IBOutlet var outlineView: NSOutlineView!
1616

1717
lazy var dataSource = DataSource(outlineView: outlineView, cellRegistration: cellRegistration)
18+
19+
var currentSnapshot: OutlineViewDiffableDataSourceSnapshot<OutlineItem> {
20+
dataSource.snapshot()
21+
}
1822

19-
let cellRegistration = CellRegistration { tableCell, _, _, outlineItem in
20-
/// `defaultContentConfiguration` returns a table cell content configuration with default styling based on the table view it's displayed at (in this case a sidebar table).
21-
var configuration = tableCell.defaultContentConfiguration()
23+
lazy var cellRegistration = CellRegistration { tableCell, _, _, outlineItem in
24+
var configuration = NSListContentConfiguration.plain()
2225
configuration.text = outlineItem.title
26+
27+
/// Check if the outline item is a root item and change it's font.
28+
if self.currentSnapshot.rootItems.contains(outlineItem) {
29+
configuration.textProperties.font = .body.bold
30+
}
31+
tableCell.contentConfiguration = configuration
32+
}
33+
34+
lazy var headerRegistration = CellRegistration { tableCell, _, _, outlineItem in
35+
36+
if let rowView = tableCell.rowView, rowView.isGroupRowStyle {
37+
Swift.print("groupRow", rowView.frame, rowView.subviews, rowView.backgroundColor == .controlAccentColor)
38+
39+
rowView.backgroundColor = .controlAccentColor
40+
41+
}
42+
var configuration = NSListContentConfiguration.plain()
43+
configuration.text = outlineItem.title
44+
configuration.textProperties.font = .body.bold
2345
tableCell.contentConfiguration = configuration
2446
}
2547

2648
override func viewDidLoad() {
2749
super.viewDidLoad()
2850

2951
outlineView.dataSource = dataSource
52+
outlineView.floatsGroupRows = false
3053

31-
dataSource.applyHeaderRegistration(cellRegistration)
54+
dataSource.applyHeaderRegistration(headerRegistration)
3255

3356
/// Enables reordering selected rows by dragging them.
3457
dataSource.reorderingHandlers.canReorder = { _, _ in return true }
@@ -44,16 +67,20 @@ class OutlineSidebarViewController: NSViewController {
4467

4568
let rootItems: [OutlineItem] = ["Root 1", "Root 2", "Root 3", "Root 4", "Root 5"]
4669
snapshot.append(rootItems)
47-
70+
snapshot.expand(rootItems)
4871
rootItems.forEach { rootItem in
4972
let childItems = (1...5).map { OutlineItem("\(rootItem.title).\($0)") }
5073
snapshot.append(childItems, to: rootItem)
51-
5274
childItems.forEach { childItem in
5375
let grandchildItems = (1...5).map { OutlineItem("\(childItem.title).\($0)") }
5476
snapshot.append(grandchildItems, to: childItem)
5577
}
5678
}
5779
dataSource.apply(snapshot, .withoutAnimation)
5880
}
81+
82+
@IBAction func segmentedPressed(_ segmentedControl: NSSegmentedControl) {
83+
(view.window?.contentViewController as? SplitViewController)?.swapSidebar()
84+
segmentedControl.selectedSegment = 1
85+
}
5986
}

0 commit comments

Comments
 (0)