Make SidebarOutlineDataSource a separate object. Move data source methods out of SidebarViewController.
This commit is contained in:
parent
e773df33e3
commit
f2228120b5
@ -105,6 +105,7 @@
|
||||
84AAF2BF202CF684004A0BC4 /* TimelineContextualMenuDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AAF2BE202CF684004A0BC4 /* TimelineContextualMenuDelegate.swift */; };
|
||||
84AD1EAA2031617300BC20B7 /* FolderPasteboardWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AD1EA92031617300BC20B7 /* FolderPasteboardWriter.swift */; };
|
||||
84AD1EBA2031649C00BC20B7 /* SmartFeedPasteboardWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AD1EB92031649C00BC20B7 /* SmartFeedPasteboardWriter.swift */; };
|
||||
84AD1EBC2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AD1EBB2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift */; };
|
||||
84B06FAE1ED37DBD00F0B54B /* RSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84B06FA91ED37DAD00F0B54B /* RSCore.framework */; };
|
||||
84B06FAF1ED37DBD00F0B54B /* RSCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84B06FA91ED37DAD00F0B54B /* RSCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
84B06FB21ED37DBD00F0B54B /* RSDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84B06F9D1ED37DA000F0B54B /* RSDatabase.framework */; };
|
||||
@ -626,6 +627,7 @@
|
||||
84AAF2BE202CF684004A0BC4 /* TimelineContextualMenuDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineContextualMenuDelegate.swift; sourceTree = "<group>"; };
|
||||
84AD1EA92031617300BC20B7 /* FolderPasteboardWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderPasteboardWriter.swift; sourceTree = "<group>"; };
|
||||
84AD1EB92031649C00BC20B7 /* SmartFeedPasteboardWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartFeedPasteboardWriter.swift; sourceTree = "<group>"; };
|
||||
84AD1EBB2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarOutlineDataSource.swift; sourceTree = "<group>"; };
|
||||
84B06F961ED37DA000F0B54B /* RSDatabase.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSDatabase.xcodeproj; path = Frameworks/RSDatabase/RSDatabase.xcodeproj; sourceTree = "<group>"; };
|
||||
84B06FA21ED37DAC00F0B54B /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = Frameworks/RSCore/RSCore.xcodeproj; sourceTree = "<group>"; };
|
||||
84B06FB61ED37E8B00F0B54B /* RSWeb.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSWeb.xcodeproj; path = Frameworks/RSWeb/RSWeb.xcodeproj; sourceTree = "<group>"; };
|
||||
@ -953,6 +955,7 @@
|
||||
children = (
|
||||
849A97621ED9EB96007D329B /* SidebarViewController.swift */,
|
||||
84B7178B201E66580091657D /* SidebarViewController+ContextualMenus.swift */,
|
||||
84AD1EBB2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift */,
|
||||
849A97601ED9EB96007D329B /* SidebarOutlineView.swift */,
|
||||
849A97611ED9EB96007D329B /* SidebarTreeControllerDelegate.swift */,
|
||||
849A97631ED9EB96007D329B /* UnreadCountView.swift */,
|
||||
@ -1934,6 +1937,7 @@
|
||||
8472058120142E8900AD578B /* FeedInspectorViewController.swift in Sources */,
|
||||
84AD1EAA2031617300BC20B7 /* FolderPasteboardWriter.swift in Sources */,
|
||||
84F204CE1FAACB660076E152 /* FeedListViewController.swift in Sources */,
|
||||
84AD1EBC2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift in Sources */,
|
||||
845A29241FC9255E007B49E3 /* SidebarCellAppearance.swift in Sources */,
|
||||
845EE7B11FC2366500854A1F /* StarredFeedDelegate.swift in Sources */,
|
||||
848F6AE51FC29CFB002D422E /* FaviconDownloader.swift in Sources */,
|
||||
|
@ -337,7 +337,6 @@
|
||||
</tableColumn>
|
||||
</tableColumns>
|
||||
<connections>
|
||||
<outlet property="dataSource" destination="XML-A3-pDn" id="04v-0e-BM6"/>
|
||||
<outlet property="delegate" destination="XML-A3-pDn" id="fPE-cv-p5c"/>
|
||||
<outlet property="keyboardDelegate" destination="h5K-zR-cUa" id="BlT-aW-sea"/>
|
||||
<outlet property="menu" destination="p3f-EZ-sSD" id="KTA-tl-UrO"/>
|
||||
|
57
Evergreen/MainWindow/Sidebar/SidebarOutlineDataSource.swift
Normal file
57
Evergreen/MainWindow/Sidebar/SidebarOutlineDataSource.swift
Normal file
@ -0,0 +1,57 @@
|
||||
//
|
||||
// SidebarOutlineDataSource.swift
|
||||
// Evergreen
|
||||
//
|
||||
// Created by Brent Simmons on 2/12/18.
|
||||
// Copyright © 2018 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import AppKit
|
||||
import RSTree
|
||||
import Data
|
||||
import RSCore
|
||||
|
||||
@objc final class SidebarOutlineDataSource: NSObject, NSOutlineViewDataSource {
|
||||
|
||||
let treeController: TreeController
|
||||
|
||||
init(treeController: TreeController) {
|
||||
self.treeController = treeController
|
||||
}
|
||||
|
||||
// MARK: - NSOutlineViewDataSource
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
|
||||
|
||||
return nodeForItem(item as AnyObject?).numberOfChildNodes
|
||||
}
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
|
||||
|
||||
return nodeForItem(item as AnyObject?).childNodes![index]
|
||||
}
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
|
||||
|
||||
return nodeForItem(item as AnyObject?).canHaveChildNodes
|
||||
}
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? {
|
||||
|
||||
let node = nodeForItem(item as AnyObject?)
|
||||
return (node.representedObject as? PasteboardWriterOwner)?.pasteboardWriter
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private extension SidebarOutlineDataSource {
|
||||
|
||||
func nodeForItem(_ item: AnyObject?) -> Node {
|
||||
|
||||
if item == nil {
|
||||
return treeController.rootNode
|
||||
}
|
||||
return item as! Node
|
||||
}
|
||||
}
|
@ -20,8 +20,12 @@ import RSCore
|
||||
|
||||
let treeControllerDelegate = SidebarTreeControllerDelegate()
|
||||
lazy var treeController: TreeController = {
|
||||
TreeController(delegate: treeControllerDelegate)
|
||||
return TreeController(delegate: treeControllerDelegate)
|
||||
}()
|
||||
lazy var dataSource: SidebarOutlineDataSource = {
|
||||
return SidebarOutlineDataSource(treeController: treeController)
|
||||
}()
|
||||
|
||||
var undoableCommands = [UndoableCommand]()
|
||||
private var animatingChanges = false
|
||||
private var sidebarCellAppearance: SidebarCellAppearance!
|
||||
@ -38,6 +42,7 @@ import RSCore
|
||||
|
||||
sidebarCellAppearance = SidebarCellAppearance(theme: appDelegate.currentTheme, fontSize: AppDefaults.shared.sidebarFontSize)
|
||||
|
||||
outlineView.dataSource = dataSource
|
||||
outlineView.setDraggingSourceOperationMask(.move, forLocal: true)
|
||||
outlineView.setDraggingSourceOperationMask(.copy, forLocal: false)
|
||||
|
||||
@ -270,7 +275,7 @@ import RSCore
|
||||
// TODO: support multiple selection
|
||||
|
||||
let selectedRow = self.outlineView.selectedRow
|
||||
|
||||
|
||||
if selectedRow < 0 || selectedRow == NSNotFound {
|
||||
postSidebarSelectionDidChangeNotification(nil)
|
||||
return
|
||||
@ -280,35 +285,9 @@ import RSCore
|
||||
postSidebarSelectionDidChangeNotification([selectedNode.representedObject])
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: NSOutlineViewDataSource
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, numberOfChildrenOfItem item: Any?) -> Int {
|
||||
|
||||
return nodeForItem(item as AnyObject?).numberOfChildNodes
|
||||
}
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any {
|
||||
|
||||
return nodeForItem(item as AnyObject?).childNodes![index]
|
||||
}
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, isItemExpandable item: Any) -> Bool {
|
||||
|
||||
return nodeForItem(item as AnyObject?).canHaveChildNodes
|
||||
}
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, pasteboardWriterForItem item: Any) -> NSPasteboardWriting? {
|
||||
|
||||
let node = nodeForItem(item as AnyObject?)
|
||||
if let feed = node.representedObject as? Feed {
|
||||
return FeedPasteboardWriter(feed: feed)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: NSUserInterfaceValidations
|
||||
// MARK: - NSUserInterfaceValidations
|
||||
|
||||
extension SidebarViewController: NSUserInterfaceValidations {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user