mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-28 02:54:31 +03:00
GH-228 Add open
This commit is contained in:
parent
8de82c2d30
commit
6e723ddeeb
@ -228,6 +228,19 @@ public class NeoVimView: NSView, NSUserInterfaceValidations {
|
||||
self.agent.vimInput("<Esc>:table<CR>")
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
guard let path = url.path else {
|
||||
|
@ -92,5 +92,15 @@ extension AppDelegate {
|
||||
}
|
||||
|
||||
@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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ class MainWindowComponent: NSObject, NSWindowDelegate, NeoVimViewDelegate, Compo
|
||||
private let windowController = NSWindowController(windowNibName: "MainWindow")
|
||||
private let window: NSWindow
|
||||
|
||||
private var urlToBeOpenedWhenReady: NSURL?
|
||||
|
||||
private var defaultEditorFont: NSFont
|
||||
private var usesLigatures: Bool
|
||||
|
||||
@ -31,13 +33,14 @@ class MainWindowComponent: NSObject, NSWindowDelegate, NeoVimViewDelegate, Compo
|
||||
}
|
||||
|
||||
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.mainWindowManager = manager
|
||||
self.window = self.windowController.window!
|
||||
self.defaultEditorFont = initialData.appearance.editorFont
|
||||
self.usesLigatures = initialData.appearance.editorUsesLigatures
|
||||
self.urlToBeOpenedWhenReady = url
|
||||
|
||||
super.init()
|
||||
|
||||
@ -49,7 +52,6 @@ class MainWindowComponent: NSObject, NSWindowDelegate, NeoVimViewDelegate, Compo
|
||||
|
||||
self.window.makeFirstResponder(self.neoVimView)
|
||||
self.windowController.showWindow(self)
|
||||
|
||||
}
|
||||
|
||||
deinit {
|
||||
@ -83,7 +85,7 @@ extension MainWindowComponent {
|
||||
@IBAction func newTab(sender: AnyObject!) {
|
||||
self.neoVimView.newTab()
|
||||
}
|
||||
|
||||
|
||||
@IBAction func openInTab(sender: AnyObject!) {
|
||||
let panel = NSOpenPanel()
|
||||
panel.canChooseDirectories = true
|
||||
@ -131,6 +133,10 @@ extension MainWindowComponent {
|
||||
func neoVimReady() {
|
||||
self.neoVimView.font = self.defaultEditorFont
|
||||
self.neoVimView.usesLigatures = self.usesLigatures
|
||||
|
||||
if let url = self.urlToBeOpenedWhenReady {
|
||||
self.neoVimView.open(url)
|
||||
}
|
||||
}
|
||||
|
||||
func neoVimStopped() {
|
||||
|
@ -22,9 +22,10 @@ class MainWindowManager {
|
||||
self.addReactions()
|
||||
}
|
||||
|
||||
func newMainWindow() {
|
||||
let mainWindowComponent = MainWindowComponent(source: self.source, manager: self, initialData: self.data)
|
||||
func newMainWindow(url: NSURL? = nil) -> MainWindowComponent {
|
||||
let mainWindowComponent = MainWindowComponent(source: self.source, manager: self, url: url, initialData: self.data)
|
||||
self.mainWindowComponents[mainWindowComponent.uuid] = mainWindowComponent
|
||||
return mainWindowComponent
|
||||
}
|
||||
|
||||
func closeMainWindow(mainWindowComponent: MainWindowComponent) {
|
||||
|
Loading…
Reference in New Issue
Block a user