From a1d127f351b878b7155f2c6b52d70c0bd917adfb Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Wed, 23 Nov 2016 21:33:26 +0100 Subject: [PATCH] GH-297 Publish double click on a buffer --- VimR/BufferListComponent.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/VimR/BufferListComponent.swift b/VimR/BufferListComponent.swift index 702a2bd6..f5694578 100644 --- a/VimR/BufferListComponent.swift +++ b/VimR/BufferListComponent.swift @@ -7,6 +7,11 @@ import Cocoa import RxSwift import PureLayout +enum BufferListAction { + + case open(buffer: NeoVimBuffer) +} + class BufferListComponent: ViewComponent, NSTableViewDataSource, NSTableViewDelegate { fileprivate var buffers: [NeoVimBuffer] = [] @@ -27,6 +32,7 @@ class BufferListComponent: ViewComponent, NSTableViewDataSource, NSTableViewDele self.bufferList.dataSource = self self.bufferList.delegate = self + self.bufferList.doubleAction = #selector(BufferListComponent.doubleClickAction) } override func addViews() { @@ -57,6 +63,20 @@ class BufferListComponent: ViewComponent, NSTableViewDataSource, NSTableViewDele } } +// MARK: - Actions +extension BufferListComponent { + + func doubleClickAction(_ sender: Any?) { + let clickedRow = self.bufferList.clickedRow + guard clickedRow >= 0 && clickedRow < self.buffers.count else { + return + } + + NSLog("double clicked: \(self.buffers[clickedRow])") + self.publish(event: BufferListAction.open(buffer: self.buffers[clickedRow])) + } +} + // MARK: - NSTableViewDataSource extension BufferListComponent {