From 8241d596fdc877481d331add20767b1adba94d9d Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sun, 11 Jun 2017 16:28:25 +0200 Subject: [PATCH] Adapt to sync neovim stop handling --- VimR/AppDelegate.swift | 14 ++++---------- VimR/AppDelegateReducer.swift | 7 ------- VimR/MainWindow.swift | 24 +++++++++++------------- VimR/States.swift | 4 ---- VimR/UiRoot.swift | 9 +++++---- 5 files changed, 20 insertions(+), 38 deletions(-) diff --git a/VimR/AppDelegate.swift b/VimR/AppDelegate.swift index e79e469d..fa6102ff 100644 --- a/VimR/AppDelegate.swift +++ b/VimR/AppDelegate.swift @@ -28,10 +28,6 @@ class AppDelegate: NSObject, NSApplicationDelegate { case openInKeyWindow(urls: [URL], cwd: URL) case preferences - - case cancelQuit - case quitWithoutSaving - case quit } @IBOutlet var debugMenu: NSMenuItem? @@ -157,18 +153,16 @@ extension AppDelegate { alert.alertStyle = .warning if alert.runModal() == NSAlertSecondButtonReturn { - self.emit(.quitWithoutSaving) - } else { - self.emit(.cancelQuit) + self.uiRoot.prepareQuit() + return .terminateNow } return .terminateCancel } if self.uiRoot.hasMainWindows { - self.emit(.quit) - - return .terminateCancel + self.uiRoot.prepareQuit() + return .terminateNow } // There are no open main window, then just quit. diff --git a/VimR/AppDelegateReducer.swift b/VimR/AppDelegateReducer.swift index 6d709f21..de17385c 100644 --- a/VimR/AppDelegateReducer.swift +++ b/VimR/AppDelegateReducer.swift @@ -35,13 +35,6 @@ class AppDelegateReducer { case .preferences: state.preferencesOpen = Marked(true) - case .cancelQuit: - state.quitWhenNoMainWindow = false - - case .quitWithoutSaving, .quit: - state.mainWindows.keys.forEach { state.mainWindows[$0]?.close = true } - state.quitWhenNoMainWindow = true - } return StateActionPair(state: state, action: pair.action) diff --git a/VimR/MainWindow.swift b/VimR/MainWindow.swift index ca553a0a..a9c55f79 100644 --- a/VimR/MainWindow.swift +++ b/VimR/MainWindow.swift @@ -175,12 +175,6 @@ class MainWindow: NSObject, return } - if state.close && !self.isClosing { - self.closeAllNeoVimWindowsWithoutSaving() - self.isClosing = true - return - } - if state.viewToBeFocused != nil, case .neoVimView = state.viewToBeFocused! { self.window.makeFirstResponder(self.neoVimView) } @@ -216,10 +210,11 @@ class MainWindow: NSObject, self.updateNeoVimAppearance() } - }, + }/*, onCompleted: { - self.windowController.close() - }) + NSLog("Completed!!!!") +// self.windowController.close() + }*/) .disposed(by: self.disposeBag) self.updateNeoVimAppearance() @@ -234,6 +229,12 @@ class MainWindow: NSObject, self.windowController.showWindow(self) } + // The following should only be used when Cmd-Q'ing + func quitNeoVimWithoutSaving() { + self.isClosing = true + self.neoVimView.quitNeoVimWithoutSaving() + } + fileprivate let emit: (UuidAction) -> Void fileprivate let disposeBag = DisposeBag() @@ -275,10 +276,6 @@ class MainWindow: NSObject, fileprivate var isClosing = false - fileprivate func closeAllNeoVimWindowsWithoutSaving() { - self.neoVimView.quitNeoVimWithoutSaving() - } - fileprivate func updateNeoVimAppearance() { self.neoVimView.font = self.defaultFont self.neoVimView.linespacing = self.linespacing @@ -331,6 +328,7 @@ extension MainWindow { func neoVimStopped() { self.isClosing = true + self.windowController.close() self.emit(self.uuidAction(for: .close)) } diff --git a/VimR/States.swift b/VimR/States.swift index 31c9dfd7..51b1bde4 100644 --- a/VimR/States.swift +++ b/VimR/States.swift @@ -21,7 +21,6 @@ struct AppState: SerializableState { var currentMainWindowUuid: String? var mainWindows: [String: MainWindow.State] = [:] - var quitWhenNoMainWindow = false var openQuickly = OpenQuicklyWindow.State.default @@ -218,9 +217,6 @@ extension MainWindow { var appearance = AppearanceState.default var useInteractiveZsh = false - // transient^2 - var close = false - // to be cleaned var urlsToOpen = [URL: OpenMode]() var currentBufferToSet: NeoVimBuffer? diff --git a/VimR/UiRoot.swift b/VimR/UiRoot.swift index 4de8e8cb..1aa624ec 100644 --- a/VimR/UiRoot.swift +++ b/VimR/UiRoot.swift @@ -35,14 +35,15 @@ class UiRoot: UiComponent { self.mainWindows.keys .filter { !uuidsInState.contains($0) } .forEach(self.removeMainWindow) - - if state.quitWhenNoMainWindow && self.mainWindows.isEmpty { - NSApp.terminate(self) - } }) .disposed(by: self.disposeBag) } + // The following should only be used when Cmd-Q'ing + func prepareQuit() { + self.mainWindows.values.forEach { $0.quitNeoVimWithoutSaving() } + } + fileprivate let source: Observable fileprivate let emitter: ActionEmitter fileprivate let disposeBag = DisposeBag()