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

Add scroll to source

This commit is contained in:
Tae Won Ha 2017-02-24 10:51:24 +01:00
parent 2b2fb3a736
commit febe337a91
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 38 additions and 33 deletions

View File

@ -93,7 +93,7 @@ class StateContext {
.filter { $0.modified }
.map { $0.state },
actionSource
.mapOmittingNil { $0 as? UuidAction<FileOutlineView.Action> }
.mapOmittingNil { $0 as? UuidAction<FileBrowser.Action> }
.mapOmittingNil { action in
guard let mainWindowState = self.appState.mainWindows[action.uuid] else {
return nil
@ -103,7 +103,7 @@ class StateContext {
action: action.payload,
modified: false)
}
.transform(by: self.fileOutlineViewTransformer)
.transform(by: self.fileBrowserTransformer)
.filter { $0.modified }
.map { $0.state }
)
@ -143,7 +143,7 @@ class StateContext {
fileprivate let previewTransformer: PreviewTransformer
fileprivate let previewToolTransformer: PreviewToolTransformer
fileprivate let fileOutlineViewTransformer = FileOutlineViewTransformer()
fileprivate let fileBrowserTransformer = FileBrowserTransformer()
fileprivate let previewService = PreviewNewService()
fileprivate let httpServerService: HttpServerService

View File

@ -14,8 +14,8 @@ class FileBrowser: NSView,
enum Action {
case setAsWorkingDirectory(url: URL)
case scrollToSource(cwd: URL)
case open(url: URL, mode: MainWindow.OpenMode)
case setAsWorkingDirectory(URL)
}
let innerCustomToolbar = InnerCustomToolbar()
@ -44,8 +44,8 @@ class FileBrowser: NSView,
self.addViews()
source
.subscribe(onNext: { state in
.subscribe(onNext: { [unowned self] state in
self.currentBufferUrl = state.currentBuffer?.url
})
.addDisposableTo(self.disposeBag)
}
@ -55,6 +55,8 @@ class FileBrowser: NSView,
fileprivate let uuid: String
fileprivate var currentBufferUrl: URL?
fileprivate let fileView: FileOutlineView
fileprivate var cwd: URL {
@ -149,10 +151,14 @@ extension FileBrowser {
}
func goToParentAction(_ sender: Any?) {
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.setAsWorkingDirectory(url: self.cwd.parent)))
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.setAsWorkingDirectory(self.cwd.parent)))
}
func scrollToSourceAction(_ sender: Any?) {
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.scrollToSource(cwd: self.cwd)))
guard let url = self.currentBufferUrl else {
return
}
self.fileView.select(url)
}
}

View File

@ -6,9 +6,9 @@
import Foundation
import RxSwift
class FileOutlineViewTransformer: Transformer {
class FileBrowserTransformer: Transformer {
typealias Pair = StateActionPair<UuidState<MainWindow.State>, FileOutlineView.Action>
typealias Pair = StateActionPair<UuidState<MainWindow.State>, FileBrowser.Action>
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source.map { pair in
@ -28,12 +28,3 @@ class FileOutlineViewTransformer: Transformer {
}
}
}
class FileBrowserTransformer {
typealias Pair = StateActionPair<UuidState<MainWindow.State>, FileBrowser.Action>
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
return source
}
}

View File

@ -14,12 +14,6 @@ class FileOutlineView: NSOutlineView,
typealias StateType = MainWindow.State
enum Action {
case open(url: URL, mode: MainWindow.OpenMode)
case setAsWorkingDirectory(URL)
}
var cwd: URL = FileUtils.userHomeUrl
var isShowHidden = false {
didSet {
@ -367,7 +361,9 @@ extension FileOutlineView {
if item.fileItem.isDir {
self.toggle(item: item)
} else {
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.open(url: item.fileItem.url, mode: .default)))
self.emitter.emit(
UuidAction(uuid: self.uuid, action: FileBrowser.Action.open(url: item.fileItem.url, mode: .default))
)
}
}
@ -376,7 +372,9 @@ extension FileOutlineView {
return
}
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.open(url: item.fileItem.url, mode: .newTab)))
self.emitter.emit(
UuidAction(uuid: self.uuid, action: FileBrowser.Action.open(url: item.fileItem.url, mode: .newTab))
)
}
@IBAction func openInCurrentTab(_: Any?) {
@ -384,7 +382,9 @@ extension FileOutlineView {
return
}
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.open(url: item.fileItem.url, mode: .currentTab)))
self.emitter.emit(
UuidAction(uuid: self.uuid, action: FileBrowser.Action.open(url: item.fileItem.url, mode: .currentTab))
)
}
@IBAction func openInHorizontalSplit(_: Any?) {
@ -392,7 +392,9 @@ extension FileOutlineView {
return
}
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.open(url: item.fileItem.url, mode: .horizontalSplit)))
self.emitter.emit(
UuidAction(uuid: self.uuid, action: FileBrowser.Action.open(url: item.fileItem.url, mode: .horizontalSplit))
)
}
@IBAction func openInVerticalSplit(_: Any?) {
@ -400,7 +402,9 @@ extension FileOutlineView {
return
}
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.open(url: item.fileItem.url, mode: .verticalSplit)))
self.emitter.emit(
UuidAction(uuid: self.uuid, action: FileBrowser.Action.open(url: item.fileItem.url, mode: .verticalSplit))
)
}
@IBAction func setAsWorkingDirectory(_: Any?) {
@ -412,7 +416,9 @@ extension FileOutlineView {
return
}
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.setAsWorkingDirectory(item.fileItem.url)))
self.emitter.emit(
UuidAction(uuid: self.uuid, action: FileBrowser.Action.setAsWorkingDirectory(item.fileItem.url))
)
}
}
@ -451,7 +457,9 @@ extension FileOutlineView {
if item.fileItem.isDir || item.fileItem.isPackage {
self.toggle(item: item)
} else {
self.emitter.emit(UuidAction(uuid: self.uuid, action: Action.open(url: item.fileItem.url, mode: .newTab)))
self.emitter.emit(
UuidAction(uuid: self.uuid, action: FileBrowser.Action.open(url: item.fileItem.url, mode: .newTab))
)
}
default: