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 {
|
2017-10-21 21:13:20 +02:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-21 21:13:20 +02:00
|
|
|
|
var isNavigationKey = false
|
2017-05-27 19:43:27 +02:00
|
|
|
|
var keyHandled = false
|
2017-10-21 21:13:20 +02:00
|
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
|
switch(ch) {
|
|
|
|
|
|
|
|
|
|
case NSRightArrowFunctionKey:
|
2017-10-21 21:13:20 +02:00
|
|
|
|
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
|
2017-10-21 21:13:20 +02:00
|
|
|
|
sidebarViewController?.delete(event)
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
keyHandled = false
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-21 21:13:20 +02:00
|
|
|
|
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)
|
2017-10-21 21:13:20 +02:00
|
|
|
|
return
|
2017-05-27 19:43:27 +02:00
|
|
|
|
}
|
2017-10-21 21:13:20 +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 {
|
|
|
|
|
|
2017-11-20 05:42:37 +01:00
|
|
|
|
// Don’t 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
|
2017-11-20 05:42:37 +01:00
|
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
}
|