1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 11:35:35 +03:00

GH-286 Add double click action

This commit is contained in:
Tae Won Ha 2016-10-02 14:07:12 +02:00
parent 786f87564d
commit d099954666
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 31 additions and 4 deletions

View File

@ -6,7 +6,7 @@
import Cocoa
import RxSwift
protocol Flow {
protocol Flow: class {
var sink: Observable<Any> { get }
}

View File

@ -6,6 +6,11 @@
import Cocoa
import RxSwift
enum FileBrowserAction {
case open(url: URL)
}
class FileBrowserComponent: ViewComponent, NSOutlineViewDataSource, NSOutlineViewDelegate {
fileprivate var cwd = FileUtils.userHomeUrl
@ -33,7 +38,6 @@ class FileBrowserComponent: ViewComponent, NSOutlineViewDataSource, NSOutlineVie
let scrollView = NSScrollView.standardScrollView()
scrollView.borderType = .noBorder
scrollView.backgroundColor = NSColor.windowBackgroundColor
scrollView.documentView = fileView
self.addSubview(scrollView)
@ -71,7 +75,7 @@ extension FileBrowserComponent {
if item.dir {
self.fileView.expandItem(item)
} else {
NSLog("open \(item)")
self.publish(event: FileBrowserAction.open(url: item.url))
}
}
}
@ -116,7 +120,7 @@ extension FileBrowserComponent {
return false
}
return fileItem.dir && !fileItem.package
return fileItem.dir
}
@objc(outlineView:objectValueForTableColumn:byItem:)

View File

@ -35,6 +35,8 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, WorkspaceDelegate
fileprivate let neoVimView: NeoVimView
fileprivate var tools = [Tool: WorkspaceTool]()
fileprivate var flows = [Flow]()
// MARK: - API
var uuid: String {
return self.neoVimView.uuid
@ -87,10 +89,14 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, WorkspaceDelegate
self.tools[.fileBrowser] = fileBrowserTool
self.workspace.append(tool: fileBrowserTool, location: .left)
self.flows.append(fileBrowser)
// FIXME: temporarily for dev
fileBrowserTool.dimension = 200
self.workspace.bars[.left]?.toggle(fileBrowserTool)
self.addReactions()
self.neoVimView.cwd = cwd // This will publish the MainWindowAction.changeCwd action for the file browser.
self.neoVimView.delegate = self
self.neoVimView.font = self.defaultEditorFont
@ -120,6 +126,23 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, WorkspaceDelegate
self.neoVimView.closeAllWindowsWithoutSaving()
}
// MARK: - Private
fileprivate func addReactions() {
self.flows
.map { $0.sink }
.toMergedObservables()
.subscribe(onNext: { [unowned self] action in
switch action {
case let FileBrowserAction.open(url: url):
self.open(urls: [url])
default:
NSLog("unrecognized action: \(action)")
return
}
})
.addDisposableTo(self.disposeBag)
}
// MARK: - WindowComponent
override func addViews() {
self.window.contentView?.addSubview(self.workspace)