-
Notifications
You must be signed in to change notification settings - Fork 1
/
MasterDetailSourceListWindowController.swift
112 lines (92 loc) · 3.18 KB
/
MasterDetailSourceListWindowController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// MasterDetailSourceListWindowController.swift
// MasterDetailSourceListWindow
//
// Created by Uli Kusterer on 01/05/16.
// Copyright © 2016 Uli Kusterer. All rights reserved.
//
import Cocoa
public class MasterSourceListItem: NSObject {
var viewController: NSViewController?
var image: NSImage?
var isGroup: Bool = false
public init( viewController inVC: NSViewController, image inImage: NSImage, group inIsGroup: Bool = false ) {
super.init()
viewController = inVC
image = inImage
isGroup = inIsGroup
}
}
public class MasterDetailSourceListWindowController: NSWindowController, NSOutlineViewDelegate, NSOutlineViewDataSource {
@IBOutlet weak var sourceListView: NSOutlineView!
@IBOutlet weak var detailView: NSView!
var viewControllers : [MasterSourceListItem] = []
public init( viewControllers inViewControllers: [MasterSourceListItem] )
{
super.init( window: nil )
viewControllers = inViewControllers;
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override public var windowNibName: String? { get { return "MasterDetailSourceListWindowController" } }
override public func windowDidLoad() {
super.windowDidLoad()
sourceListView.reloadData()
sourceListView.selectRowIndexes( NSIndexSet(index: 0), byExtendingSelection: false );
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
}
public func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int
{
if item == nil
{
return viewControllers.count;
}
else
{
return 0;
}
}
public func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject
{
if item == nil
{
return viewControllers[index];
}
else
{
return NSNull()
}
}
public func outlineView(outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool
{
return false
}
public func outlineView(outlineView: NSOutlineView, isGroupItem item: AnyObject) -> Bool
{
let isGroupBool : Bool = item.isGroup
return isGroupBool
}
public func outlineView(outlineView: NSOutlineView, viewForTableColumn tableColumn: NSTableColumn?, item: AnyObject) -> NSView? {
var cellIdentifier: String = "DataCell"
if item.isGroup!
{
cellIdentifier = "HeaderCell"
}
let cell : NSTableCellView = sourceListView.makeViewWithIdentifier( cellIdentifier, owner: self ) as! NSTableCellView
cell.objectValue = item
return cell
}
public func outlineViewSelectionDidChange(notification: NSNotification)
{
detailView.subviews.removeAll()
if sourceListView.selectedRow >= 0
{
let nextViewController = viewControllers[sourceListView.selectedRow].viewController!
let theView = nextViewController.view;
detailView.addSubview(theView)
detailView.addConstraints( NSLayoutConstraint.constraintsWithVisualFormat( "|[theView]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["theView": theView]) )
detailView.addConstraints( NSLayoutConstraint.constraintsWithVisualFormat( "V:|[theView]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["theView": theView]) )
}
}
}