Skip to content

Commit adda368

Browse files
author
Vadim Shpakovski
committed
Demo: Add support for reloading contents
1 parent 7e443bd commit adda368

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Demo/Demo/EmptyViewController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ extension EmptyViewController {
4242
stackView.orientation = .vertical
4343
stackView.distribution = .fill
4444
stackView.addView(scrollableEditor, in: .center)
45-
stackView.addView(NSButton(title: "Replace Sidebar Contents", target: self, action: #selector(replaceSidebarContents(_:))), in: .center)
45+
stackView.addView(NSButton(title: "Fill Sidebar", target: self, action: #selector(fillSidebar(_:))), in: .center)
46+
stackView.addView(NSButton(title: "Reload Sidebar", target: nil, action: #selector(MasterViewController.reloadSidebar(_:))), in: .center)
4647
stackView.addView(NSButton(title: "Expand All Items", target: nil, action: #selector(MasterViewController.expandAllItems(_:))), in: .center)
4748
stackView.addView(NSButton(title: "Collapse All Items", target: nil, action: #selector(MasterViewController.collapseAllItems(_:))), in: .center)
4849
stackView.setHuggingPriority(.fittingSizeCompression, for: .horizontal)
@@ -71,7 +72,7 @@ extension EmptyViewController {
7172
private extension EmptyViewController {
7273

7374
/// Replaces the whole tree with the given contents.
74-
@IBAction func replaceSidebarContents(_ sender: Any?) {
75+
@IBAction func fillSidebar(_ sender: Any?) {
7576
guard let textView = scrollableEditor.documentView as? NSTextView else { return }
7677
var snapshot: DiffableDataSourceSnapshot<MasterItem> = .init()
7778
let lines = textView.string.components(separatedBy: .newlines)

Demo/Demo/MasterViewController.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,25 @@ extension MasterViewController {
9898

9999
extension MasterViewController {
100100

101+
/// Reloads data from the data source to check consistency.
102+
@IBAction func reloadSidebar(_ sender: Any?) {
103+
scrollableOutlineView.outlineView.reloadData()
104+
}
105+
101106
/// Expands all outline view items.
102107
@IBAction func expandAllItems(_ sender: Any?) {
103-
scrollableOutlineView.outlineView.expandItem(nil, expandChildren: true)
108+
NSAnimationContext.runAnimationGroup { context in
109+
if shouldAnimate == false { context.duration = 0 }
110+
scrollableOutlineView.outlineView.animator().expandItem(nil, expandChildren: true)
111+
}
104112
}
105113

106114
/// Collapses all outline view items.
107115
@IBAction func collapseAllItems(_ sender: Any?) {
108-
scrollableOutlineView.outlineView.collapseItem(nil, collapseChildren: true)
116+
NSAnimationContext.runAnimationGroup { context in
117+
if shouldAnimate == false { context.duration = 0 }
118+
scrollableOutlineView.outlineView.animator().collapseItem(nil, collapseChildren: true)
119+
}
109120
}
110121
}
111122

0 commit comments

Comments
 (0)