NetNewsWire/Evergreen/MainWindow/Sidebar/SidebarOutlineView.swift

96 lines
2.0 KiB
Swift
Raw Normal View History

2017-05-27 19:43:27 +02:00
//
// SidebarOutlineView.swift
// Evergreen
//
// Created by Brent Simmons on 11/17/15.
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
//
import AppKit
2017-10-21 19:55:20 +02:00
import RSCore
2017-11-19 01:56:36 +01:00
import RSTree
2017-05-27 19:43:27 +02:00
class SidebarOutlineView : NSOutlineView {
weak var sidebarViewController: SidebarViewController?
2017-05-27 19:43:27 +02:00
//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
2017-05-27 19:43:27 +02:00
var keyHandled = false
2017-05-27 19:43:27 +02:00
switch(ch) {
case NSRightArrowFunctionKey:
isNavigationKey = true
2017-05-27 19:43:27 +02:00
keyHandled = true
2017-10-21 19:55:20 +02:00
case NSDeleteFunctionKey, Int(kDeleteKeyCode):
2017-05-27 19:43:27 +02:00
keyHandled = true
sidebarViewController?.delete(event)
2017-05-27 19:43:27 +02:00
default:
keyHandled = false
}
if isNavigationKey {
2017-09-24 21:24:44 +02:00
let appInfo = AppInfo()
appInfo.navigationKey = ch
NotificationCenter.default.post(name: .AppNavigationKeyPressed, object: self, userInfo: appInfo.userInfo)
return
2017-05-27 19:43:27 +02:00
}
if !keyHandled {
2017-05-27 19:43:27 +02:00
super.keyDown(with: event)
}
}
2017-11-19 01:56:36 +01:00
override func frameOfCell(atColumn column: Int, row: Int) -> NSRect {
// Dont allow the pseudo-feeds at the top level to be indented.
2017-11-19 01:56:36 +01:00
var frame = super.frameOfCell(atColumn: column, row: row)
let node = item(atRow: row) as! Node
guard let parentNode = node.parent, parentNode.isRoot else {
return frame
}
guard node.representedObject is PseudoFeed else {
2017-11-19 01:56:36 +01:00
return frame
}
frame.origin.x -= indentationPerLevel
frame.size.width += indentationPerLevel
return frame
}
2017-05-27 19:43:27 +02:00
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()
}
}