mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 03:25:03 +03:00
Correctly clean up swps when closing and quitting
This commit is contained in:
parent
ae69318199
commit
bce3e9e5f0
@ -22,8 +22,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
enum Action {
|
||||
|
||||
case newMainWindow(urls: [URL], cwd: URL)
|
||||
case closeAllMainWindowsWithoutSaving
|
||||
case closeAllMainWindows
|
||||
case quitWithoutSaving
|
||||
case quit
|
||||
}
|
||||
|
||||
@IBOutlet var debugMenu: NSMenuItem?
|
||||
@ -83,10 +83,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
.subscribe(onNext: { appState in
|
||||
self.hasMainWindows = !appState.mainWindows.isEmpty
|
||||
self.hasDirtyWindows = appState.mainWindows.values.reduce(false) { $1.isDirty ? true : $0 }
|
||||
|
||||
if self.quitWhenAllWindowsAreClosed && appState.mainWindows.isEmpty {
|
||||
NSApp.stop(self)
|
||||
}
|
||||
})
|
||||
.addDisposableTo(self.disposeBag)
|
||||
|
||||
@ -145,7 +141,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
fileprivate let stateContext: StateContext
|
||||
fileprivate let uiRoot: UiRoot
|
||||
fileprivate var hasDirtyWindows = true
|
||||
fileprivate var hasDirtyWindows = false
|
||||
fileprivate var hasMainWindows = false
|
||||
}
|
||||
|
||||
@ -218,7 +214,7 @@ extension AppDelegate {
|
||||
|
||||
if alert.runModal() == NSAlertSecondButtonReturn {
|
||||
self.quitWhenAllWindowsAreClosed = true
|
||||
self.stateContext.actionEmitter.emit(AppDelegate.Action.closeAllMainWindowsWithoutSaving)
|
||||
self.stateContext.actionEmitter.emit(AppDelegate.Action.quitWithoutSaving)
|
||||
}
|
||||
|
||||
return .terminateCancel
|
||||
@ -226,7 +222,7 @@ extension AppDelegate {
|
||||
|
||||
if self.hasMainWindows {
|
||||
self.quitWhenAllWindowsAreClosed = true
|
||||
self.stateContext.actionEmitter.emit(AppDelegate.Action.closeAllMainWindows)
|
||||
self.stateContext.actionEmitter.emit(AppDelegate.Action.quit)
|
||||
|
||||
return .terminateCancel
|
||||
}
|
||||
|
@ -29,13 +29,13 @@ class AppDelegateTransformer: Transformer {
|
||||
|
||||
state.mainWindows[mainWindow.uuid] = mainWindow
|
||||
|
||||
return StateActionPair(state: state, action: pair.action)
|
||||
|
||||
case .closeAllMainWindowsWithoutSaving, .closeAllMainWindows:
|
||||
case .quitWithoutSaving, .quit:
|
||||
state.mainWindows.removeAll()
|
||||
return StateActionPair(state: state, action: pair.action)
|
||||
state.quitWhenNoMainWindow = true
|
||||
|
||||
}
|
||||
|
||||
return StateActionPair(state: state, action: pair.action)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,6 +95,10 @@ class StateContext {
|
||||
#endif
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.stateSubject.onCompleted()
|
||||
}
|
||||
|
||||
fileprivate let stateSubject = PublishSubject<AppState>()
|
||||
fileprivate let scheduler = SerialDispatchQueueScheduler(qos: .userInitiated)
|
||||
fileprivate let disposeBag = DisposeBag()
|
||||
|
@ -102,18 +102,24 @@ class MainWindow: NSObject,
|
||||
self.windowController.window?.delegate = self
|
||||
|
||||
source
|
||||
// .debug()
|
||||
.observeOn(MainScheduler.instance)
|
||||
.subscribe(onNext: { [unowned self] state in
|
||||
if state.previewTool.isReverseSearchAutomatically
|
||||
&& state.preview.previewPosition.mark != self.previewPosition.mark
|
||||
{
|
||||
NSLog("!!!!!!!!!!!!!!! reverse!")
|
||||
self.neoVimView.cursorGo(to: state.preview.previewPosition.payload)
|
||||
}
|
||||
.subscribe(
|
||||
onNext: { [unowned self] state in
|
||||
if state.isClosed {
|
||||
return
|
||||
}
|
||||
|
||||
self.previewPosition = state.preview.previewPosition
|
||||
})
|
||||
if state.previewTool.isReverseSearchAutomatically
|
||||
&& state.preview.previewPosition.mark != self.previewPosition.mark {
|
||||
NSLog("!!!!!!!!!!!!!!! reverse!")
|
||||
self.neoVimView.cursorGo(to: state.preview.previewPosition.payload)
|
||||
}
|
||||
|
||||
self.previewPosition = state.preview.previewPosition
|
||||
},
|
||||
onCompleted: {
|
||||
self.windowController.close()
|
||||
})
|
||||
.addDisposableTo(self.disposeBag)
|
||||
|
||||
let neoVimView = self.neoVimView
|
||||
@ -208,7 +214,7 @@ class MainWindow: NSObject,
|
||||
extension MainWindow {
|
||||
|
||||
func neoVimStopped() {
|
||||
self.windowController.close()
|
||||
self.emitter.emit(self.uuidAction(for: .close))
|
||||
}
|
||||
|
||||
func set(title: String) {
|
||||
@ -274,7 +280,7 @@ extension MainWindow {
|
||||
}
|
||||
|
||||
func windowWillClose(_: Notification) {
|
||||
self.emitter.emit(self.uuidAction(for: .close))
|
||||
// self.emitter.emit(self.uuidAction(for: .close))
|
||||
}
|
||||
|
||||
func windowShouldClose(_: Any) -> Bool {
|
||||
|
@ -118,6 +118,7 @@ struct AppState {
|
||||
|
||||
var currentMainWindow: MainWindow.State
|
||||
var mainWindows: [String: MainWindow.State] = [:]
|
||||
var quitWhenNoMainWindow = false
|
||||
|
||||
let baseServerUrl: URL
|
||||
|
||||
|
@ -29,30 +29,47 @@ class UiRoot: UiComponent {
|
||||
.subtracting(uuidsInState)
|
||||
.forEach { uuid in
|
||||
self.mainWindows[uuid]?.closeAllNeoVimWindowsWithoutSaving()
|
||||
self.mainWindows.removeValue(forKey: uuid)
|
||||
self.removeMainWindow(with: uuid)
|
||||
}
|
||||
|
||||
// remove already closed windows
|
||||
state.mainWindows
|
||||
.filter { (uuid, mainWindow) in return mainWindow.isClosed }
|
||||
.forEach { (uuid, mainWindow) in self.mainWindows.removeValue(forKey: uuid) }
|
||||
.forEach { (uuid, _) in self.removeMainWindow(with: uuid) }
|
||||
|
||||
if state.quitWhenNoMainWindow && self.mainWindows.isEmpty {
|
||||
NSApp.stop(self)
|
||||
}
|
||||
})
|
||||
.addDisposableTo(self.disposeBag)
|
||||
}
|
||||
|
||||
fileprivate func createNewMainWindow(with state: MainWindow.State) {
|
||||
let mainWindow = MainWindow(source: source.mapOmittingNil { $0.mainWindows[state.uuid] },
|
||||
emitter: self.emitter,
|
||||
state: state)
|
||||
self.mainWindows[state.uuid] = mainWindow
|
||||
let subject = PublishSubject<MainWindow.State>()
|
||||
let source = self.source.mapOmittingNil { $0.mainWindows[state.uuid] }
|
||||
|
||||
self.subjectForMainWindows[state.uuid] = subject
|
||||
self.disposables[state.uuid] = source.subscribe(subject)
|
||||
|
||||
let mainWindow = MainWindow(source: subject.asObservable(), emitter: self.emitter, state: state)
|
||||
self.mainWindows[state.uuid] = mainWindow
|
||||
mainWindow.show()
|
||||
}
|
||||
|
||||
fileprivate func removeMainWindow(with uuid: String) {
|
||||
self.subjectForMainWindows[uuid]?.onCompleted()
|
||||
self.disposables[uuid]?.dispose()
|
||||
|
||||
self.subjectForMainWindows.removeValue(forKey: uuid)
|
||||
self.disposables.removeValue(forKey: uuid)
|
||||
self.mainWindows.removeValue(forKey: uuid)
|
||||
}
|
||||
|
||||
fileprivate let source: Observable<AppState>
|
||||
fileprivate let emitter: ActionEmitter
|
||||
fileprivate let disposeBag = DisposeBag()
|
||||
|
||||
fileprivate var mainWindows = [String: MainWindow]()
|
||||
fileprivate var subjectForMainWindows = [String: PublishSubject<MainWindow.State>]()
|
||||
fileprivate var disposables = [String: Disposable]()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user