         }
         
         self.binding!.treeController?.removeObserver(self, forKeyPath: self.binding!.treeKeyPath)
-        self.binding!.selectionController?.removeObserver(self, forKeyPath: self.binding!.selectionKeyPath)
         self.binding = nil
     }
     


fileprivate struct JumpBarControlBinding {
    fileprivate static var treeObserverContext = 1
    fileprivate static var selectionObserverContext = 3
    fileprivate weak var treeController: NSTreeController?
    fileprivate weak var selectionController: NSObject?
    fileprivate var treeKeyPath: String
    fileprivate var selectionKeyPath: String
    
    var selectedIndexPath: IndexPath? {
        get { return self.selectionController?.value(forKey: self.selectionKeyPath) as! IndexPath? }
    }
}

open class JumpBarControl: NSControl, JumpBarSegmentControlDelegate {

    // MARK: - Content
    
    open func bind(itemsTreeTo treeController: NSTreeController,
                   withKeyPath treeKeyPath: String = "arrangedObjects") throws
    {
        guard self.binding == nil else {
            throw JumpBarControlError.alreadyBound("JumpBarControl \(self) is already bound to tree and selection controllers. Unbind first.")
        }
        
        self.binding = JumpBarControlBinding(treeController: treeController, treeKeyPath: treeKeyPath)
        
        treeController.addObserver(self,
                                   forKeyPath: treeKeyPath,
                                   options: [.new, .old],
                                   context: &JumpBarControlBinding.treeObserverContext)
        
        self.useItemsTree(treeController.arrangedRootObjects())
    }
    
