From 5dbc87caf0b4e6ea548baa7972dea766786201cb Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 13 Nov 2020 19:09:30 -0500 Subject: [PATCH] Smarter: just ensures any attached panels are closed at close(). --- .../Documents/MachineDocument.swift | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 2337a84af..47d423d40 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -88,14 +88,30 @@ class MachineDocument: } override func close() { + // Close any dangling sheets. + // + // Be warned: in 11.0 at least, if there are any panels then posting the endSheet request + // will defer the close(), and close() will be called again at the end of that animation. + // + // So: MAKE SURE IT'S SAFE TO ENTER THIS FUNCTION TWICE. Hence the non-assumption here about + // any windows still existing. + if self.windowControllers.count > 0, let window = self.windowControllers[0].window { + for sheet in window.sheets { + window.endSheet(sheet) + } + } + + // Stop the machine, if any. machine?.stop() + // Dismiss panels. activityPanel?.setIsVisible(false) activityPanel = nil optionsPanel?.setIsVisible(false) optionsPanel = nil + // End the update cycle. actionLock.lock() drawLock.lock() machine = nil @@ -103,6 +119,7 @@ class MachineDocument: actionLock.unlock() drawLock.unlock() + // Let the document controller do its thing. super.close() } @@ -364,8 +381,6 @@ class MachineDocument: } @IBAction func cancelCreateMachine(_ sender: NSButton?) { - self.windowControllers[0].window?.endSheet(self.machinePickerPanel!) - self.machinePicker = nil close() } @@ -395,7 +410,6 @@ class MachineDocument: } @IBAction func cancelRequestROMs(_ sender: NSButton?) { - self.windowControllers[0].window?.endSheet(self.romRequesterPanel!) close() }