1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00

GH-297 list the buffers

This commit is contained in:
Tae Won Ha 2016-11-22 20:57:50 +01:00
parent 6aacae34f6
commit 43c3e69ef3
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 33 additions and 3 deletions

View File

@ -10,7 +10,14 @@ NS_ASSUME_NONNULL_BEGIN
@interface NeoVimBuffer : NSObject <NSCoding>
@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;

View File

@ -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;

View File

@ -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<Any>) -> 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"
}
}