// // LibraryController.swift // DocHub // // Created by Tristan Juricek on 6/23/14. // Copyright (c) 2014 Perforce. All rights reserved. // import AppKit import Foundation class LibrarySourceListController : NSViewController, NSOutlineViewDelegate { @IBOutlet var outlineView:NSOutlineView var docHubLocation:DocHubLocation init(nibName:String!, bundle:NSBundle!, docHubLocation:DocHubLocation) { self.docHubLocation = docHubLocation super.init(nibName: nibName, bundle: bundle) } func outlineViewSelectionDidChange(notification: NSNotification!) { if let selectedItem:AnyObject = outlineView.itemAtRow(outlineView.selectedRow) { if selectedItem is Area { docHubLocation.area = (selectedItem as? Area) } } } func outlineView(outlineView: NSOutlineView!, viewForTableColumn tableColumn: NSTableColumn!, item: AnyObject!) -> NSView! { if item is Library ? true : false { let library:Library = item! as Library let cell = outlineView.makeViewWithIdentifier("HeaderCell", owner: self) as NSTableCellView! cell.textField.stringValue = library.name.uppercaseString return cell } else if item is Area ? true : false { let area:Area = item! as Area let cell = outlineView.makeViewWithIdentifier("DataCell", owner: self) as NSTableCellView! cell.textField.stringValue = area.name return cell } println("illegal state: item is not Area or Library: \(item)") return outlineView.makeViewWithIdentifier("DataCell", owner: self) as NSView } func outlineView(outlineView: NSOutlineView!, isGroupItem item: AnyObject!) -> Bool { return (item is Library ? true : false) } func outlineView(outlineView: NSOutlineView!, shouldSelectItem item: AnyObject!) -> Bool { return (item is Library ? false : true) } func reload() { let ds = (outlineView.dataSource()!) as LibraryDataSource ds.updateLibraries() outlineView.reloadItem(nil, reloadChildren:true) } }