1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-01 01:32:04 +03:00

GH-228 Add open

This commit is contained in:
Tae Won Ha 2016-08-11 22:37:41 +02:00
parent 8de82c2d30
commit 6e723ddeeb
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 36 additions and 6 deletions

View File

@ -229,6 +229,19 @@ public class NeoVimView: NSView, NSUserInterfaceValidations {
} }
} }
public func open(url: NSURL) {
guard let path = url.path else {
return
}
switch self.mode {
case .Normal:
self.agent.vimInput(":e \(path)<CR>")
default:
self.agent.vimInput("<Esc>:e \(path)<CR>")
}
}
public func openInNewTab(url: NSURL) { public func openInNewTab(url: NSURL) {
guard let path = url.path else { guard let path = url.path else {
return return

View File

@ -92,5 +92,15 @@ extension AppDelegate {
} }
@IBAction func openDocument(sender: AnyObject!) { @IBAction func openDocument(sender: AnyObject!) {
let panel = NSOpenPanel()
panel.canChooseDirectories = true
panel.beginWithCompletionHandler { result in
guard result == NSFileHandlingPanelOKButton else {
return
}
let url = panel.URLs[0]
self.mainWindowManager.newMainWindow(url)
}
} }
} }

View File

@ -23,6 +23,8 @@ class MainWindowComponent: NSObject, NSWindowDelegate, NeoVimViewDelegate, Compo
private let windowController = NSWindowController(windowNibName: "MainWindow") private let windowController = NSWindowController(windowNibName: "MainWindow")
private let window: NSWindow private let window: NSWindow
private var urlToBeOpenedWhenReady: NSURL?
private var defaultEditorFont: NSFont private var defaultEditorFont: NSFont
private var usesLigatures: Bool private var usesLigatures: Bool
@ -32,12 +34,13 @@ class MainWindowComponent: NSObject, NSWindowDelegate, NeoVimViewDelegate, Compo
private let neoVimView = NeoVimView(forAutoLayout: ()) private let neoVimView = NeoVimView(forAutoLayout: ())
init(source: Observable<Any>, manager: MainWindowManager, initialData: PrefData) { init(source: Observable<Any>, manager: MainWindowManager, url: NSURL? = nil, initialData: PrefData) {
self.source = source self.source = source
self.mainWindowManager = manager self.mainWindowManager = manager
self.window = self.windowController.window! self.window = self.windowController.window!
self.defaultEditorFont = initialData.appearance.editorFont self.defaultEditorFont = initialData.appearance.editorFont
self.usesLigatures = initialData.appearance.editorUsesLigatures self.usesLigatures = initialData.appearance.editorUsesLigatures
self.urlToBeOpenedWhenReady = url
super.init() super.init()
@ -49,7 +52,6 @@ class MainWindowComponent: NSObject, NSWindowDelegate, NeoVimViewDelegate, Compo
self.window.makeFirstResponder(self.neoVimView) self.window.makeFirstResponder(self.neoVimView)
self.windowController.showWindow(self) self.windowController.showWindow(self)
} }
deinit { deinit {
@ -131,6 +133,10 @@ extension MainWindowComponent {
func neoVimReady() { func neoVimReady() {
self.neoVimView.font = self.defaultEditorFont self.neoVimView.font = self.defaultEditorFont
self.neoVimView.usesLigatures = self.usesLigatures self.neoVimView.usesLigatures = self.usesLigatures
if let url = self.urlToBeOpenedWhenReady {
self.neoVimView.open(url)
}
} }
func neoVimStopped() { func neoVimStopped() {

View File

@ -22,9 +22,10 @@ class MainWindowManager {
self.addReactions() self.addReactions()
} }
func newMainWindow() { func newMainWindow(url: NSURL? = nil) -> MainWindowComponent {
let mainWindowComponent = MainWindowComponent(source: self.source, manager: self, initialData: self.data) let mainWindowComponent = MainWindowComponent(source: self.source, manager: self, url: url, initialData: self.data)
self.mainWindowComponents[mainWindowComponent.uuid] = mainWindowComponent self.mainWindowComponents[mainWindowComponent.uuid] = mainWindowComponent
return mainWindowComponent
} }
func closeMainWindow(mainWindowComponent: MainWindowComponent) { func closeMainWindow(mainWindowComponent: MainWindowComponent) {