1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-26 23:36:08 +03:00

GH-458 Fix open files by drag-n-dropping on VimR window

This commit is contained in:
Tae Won Ha 2019-03-12 10:54:00 +01:00
parent 31c49215bc
commit efbc9af8da
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -7,11 +7,15 @@ import Cocoa
extension NvimView { extension NvimView {
override public func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation { override public func draggingEntered(
_ sender: NSDraggingInfo
) -> NSDragOperation {
return isFile(sender: sender) ? .copy : NSDragOperation() return isFile(sender: sender) ? .copy : NSDragOperation()
} }
override public func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation { override public func draggingUpdated(
_ sender: NSDraggingInfo
) -> NSDragOperation {
return isFile(sender: sender) ? .copy : NSDragOperation() return isFile(sender: sender) ? .copy : NSDragOperation()
} }
@ -20,16 +24,15 @@ extension NvimView {
return false return false
} }
guard let paths = sender.draggingPasteboard.propertyList( guard let urls = sender.draggingPasteboard
forType: NSPasteboard.PasteboardType(String(kUTTypeFileURL)) .readObjects(forClasses: [NSURL.self]) as? [URL] else { return false }
) as? [String] else {
return false
}
self.open(urls: paths.map { URL(fileURLWithPath: $0) }) self.open(urls: urls)
.subscribeOn(self.scheduler) .subscribeOn(self.scheduler)
.subscribe(onError: { error in .subscribe(onError: { error in
self.eventsSubject.onNext(.apiError(msg: "\(paths) could not be opened.", cause: error)) self.eventsSubject.onNext(
.apiError(msg: "\(urls) could not be opened.", cause: error)
)
}) })
.disposed(by: self.disposeBag) .disposed(by: self.disposeBag)
@ -38,5 +41,7 @@ extension NvimView {
} }
private func isFile(sender: NSDraggingInfo) -> Bool { private func isFile(sender: NSDraggingInfo) -> Bool {
return (sender.draggingPasteboard.types?.contains(NSPasteboard.PasteboardType(String(kUTTypeFileURL)))) ?? false return (sender.draggingPasteboard.types?.contains(
NSPasteboard.PasteboardType(String(kUTTypeFileURL))
)) ?? false
} }