NetNewsWire/Evergreen/MainWindow/Sidebar/SidebarOutlineView.swift
2017-11-18 16:56:36 -08:00

91 lines
1.8 KiB
Swift

//
// SidebarOutlineView.swift
// Evergreen
//
// Created by Brent Simmons on 11/17/15.
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
//
import AppKit
import RSCore
import RSTree
class SidebarOutlineView : NSOutlineView {
weak var sidebarViewController: SidebarViewController?
//MARK: NSResponder
override func keyDown(with event: NSEvent) {
guard !event.rs_keyIsModified() else {
super.keyDown(with: event)
return
}
let ch = Int(event.rs_unmodifiedCharacter())
if ch == NSNotFound {
super.keyDown(with: event)
return
}
var isNavigationKey = false
var keyHandled = false
switch(ch) {
case NSRightArrowFunctionKey:
isNavigationKey = true
keyHandled = true
case NSDeleteFunctionKey, Int(kDeleteKeyCode):
keyHandled = true
sidebarViewController?.delete(event)
default:
keyHandled = false
}
if isNavigationKey {
let appInfo = AppInfo()
appInfo.navigationKey = ch
NotificationCenter.default.post(name: .AppNavigationKeyPressed, object: self, userInfo: appInfo.userInfo)
return
}
if !keyHandled {
super.keyDown(with: event)
}
}
override func frameOfCell(atColumn column: Int, row: Int) -> NSRect {
var frame = super.frameOfCell(atColumn: column, row: row)
let node = item(atRow: row) as! Node
if node.isGroupItem {
return frame
}
frame.origin.x -= indentationPerLevel
frame.size.width += indentationPerLevel
return frame
}
override func viewWillStartLiveResize() {
if let scrollView = self.enclosingScrollView {
scrollView.hasVerticalScroller = false
}
super.viewWillStartLiveResize()
}
override func viewDidEndLiveResize() {
if let scrollView = self.enclosingScrollView {
scrollView.hasVerticalScroller = true
}
super.viewDidEndLiveResize()
}
}