From 43c3e69ef3f113160013fababc9c3a6520c56d06 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Tue, 22 Nov 2016 20:57:50 +0100 Subject: [PATCH] GH-297 list the buffers --- NeoVimServer/NeoVimBuffer.h | 7 +++++++ NeoVimServer/NeoVimBuffer.m | 8 ++++++++ VimR/BufferListComponent.swift | 21 ++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/NeoVimServer/NeoVimBuffer.h b/NeoVimServer/NeoVimBuffer.h index dfe9cce8..7dd3e055 100644 --- a/NeoVimServer/NeoVimBuffer.h +++ b/NeoVimServer/NeoVimBuffer.h @@ -10,7 +10,14 @@ NS_ASSUME_NONNULL_BEGIN @interface NeoVimBuffer : NSObject @property (nonatomic, readonly) NSInteger handle; +/** + * Full path + */ @property (nonatomic, retain, nullable) NSString *fileName; +/** + * Only the file name + */ +@property (nonatomic, readonly, nullable) NSString *name; @property (nonatomic, readonly) bool isDirty; @property (nonatomic, readonly) bool isCurrent; @property (nonatomic, readonly) bool isTransient; diff --git a/NeoVimServer/NeoVimBuffer.m b/NeoVimServer/NeoVimBuffer.m index c65a2e9c..0f67fb70 100644 --- a/NeoVimServer/NeoVimBuffer.m +++ b/NeoVimServer/NeoVimBuffer.m @@ -77,6 +77,14 @@ return description; } +- (NSString *)name { + if (self.fileName == nil) { + return nil; + } + + return self.fileName.lastPathComponent; +} + - (bool)isTransient { if (self.isDirty) { return NO; diff --git a/VimR/BufferListComponent.swift b/VimR/BufferListComponent.swift index 74d50338..1869bd05 100644 --- a/VimR/BufferListComponent.swift +++ b/VimR/BufferListComponent.swift @@ -10,6 +10,7 @@ import PureLayout class BufferListComponent: ViewComponent, NSTableViewDataSource, NSTableViewDelegate { let dummy = [ "a", "b", "c" ] + var buffers: [NeoVimBuffer] = [] let bufferList = NSTableView.standardTableView() @@ -34,7 +35,21 @@ class BufferListComponent: ViewComponent, NSTableViewDataSource, NSTableViewDele } override func subscription(source: Observable) -> Disposable { - return Disposables.create() + return source + .filter { $0 is MainWindowAction } + .map { $0 as! MainWindowAction } + .subscribe(onNext: { action in + switch action { + + case let .changeBufferList(mainWindow:_, buffers:buffers): + self.buffers = buffers + self.bufferList.reloadData() + + default: + return + + } + }) } } @@ -43,12 +58,12 @@ extension BufferListComponent { @objc(numberOfRowsInTableView:) func numberOfRows(in tableView: NSTableView) -> Int { - return dummy.count + return self.buffers.count } @objc(tableView:objectValueForTableColumn:row:) func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { - return dummy[row] + return self.buffers[row].name ?? "No Name" } }