@@ -8,18 +8,15 @@ class FlippedView: NSView {
88
99public protocol FatSidebarDelegate : class {
1010 func sidebar( _ sidebar: FatSidebar , didMoveItemFrom oldIndex: Int , to newIndex: Int )
11- }
12-
13- public protocol FatSidebarSelectionChangeDelegate : class {
1411 func sidebar( _ sidebar: FatSidebar , didChangeSelection selectionIndex: Int )
12+ func sidebar( _ sidebar: FatSidebar , editItem index: Int )
1513}
1614
1715
1816/// Top-level module facade, acting as a composite view that scrolls.
1917public class FatSidebar : NSView {
2018
2119 public weak var delegate : FatSidebarDelegate ?
22- public weak var selectionDelegate : FatSidebarSelectionChangeDelegate ?
2320
2421 let scrollView = NSScrollView ( )
2522 let sidebarView = FatSidebarView ( )
@@ -103,6 +100,7 @@ public class FatSidebar: NSView {
103100
104101 private var selectionChangeObserver : AnyObject !
105102 private var moveObserver : AnyObject !
103+ private var doubleClickObserver : AnyObject !
106104
107105 fileprivate func observeSidebarSelectionChanges( ) {
108106
@@ -117,13 +115,18 @@ public class FatSidebar: NSView {
117115 forName: FatSidebarView . didReorderItemNotification,
118116 object: sidebarView,
119117 queue: nil ) { [ weak self] in self ? . itemDidMove ( $0) }
118+
119+ doubleClickObserver = notificationCenter. addObserver (
120+ forName: FatSidebarView . didDoubleClickItemNotification,
121+ object: sidebarView,
122+ queue: nil ) { [ weak self] in self ? . itemWasDoubleClicked ( $0) }
120123 }
121124
122125 fileprivate func selectionDidChange( _ notification: Notification ) {
123126
124127 guard let index = notification. userInfo ? [ " index " ] as? Int else { return }
125128
126- selectionDelegate ? . sidebar ( self , didChangeSelection: index)
129+ delegate ? . sidebar ( self , didChangeSelection: index)
127130 }
128131
129132 fileprivate func itemDidMove( _ notification: Notification ) {
@@ -136,6 +139,16 @@ public class FatSidebar: NSView {
136139 self . delegate? . sidebar ( self , didMoveItemFrom: fromIndex, to: toIndex)
137140 }
138141
142+ fileprivate func itemWasDoubleClicked( _ notification: Notification ) {
143+
144+ guard let userInfo = notification. userInfo,
145+ let index = userInfo [ " index " ] as? Int
146+ else { return }
147+
148+ self . delegate? . sidebar ( self , editItem: index)
149+ }
150+
151+
139152 // MARK: - Sidebar Façade
140153
141154 public var itemCount : Int {
0 commit comments