How to close the color well's color selection window


#1

I had this question all ready to post and I saw to the right where it says “your question is similar to…”

That led me to a 4th edition forum post using objective-c. I was able to figure out from that post how to close the colorPanel when clicking the OK or Cancel buttons.

If anybody else wants to know, here it is…

Located in the MainWindowController.swift:

@IBAction func showDieConfiguration(sender: AnyObject?) {
	if let window = window, let dieView = window.firstResponder as? DieView {
		// Create and configure the window controller to present as a sheet:
		let windowController = ConfigurationWindowController()
		windowController.configuration = DieConfiguration(color: dieView.color,
													rolls: dieView.numberOfTimesToRoll)
		window.beginSheet(windowController.window!,
						  completionHandler: { response in
							//The sheet has finished.  Did the user click 'OK'?
							if response == NSApplication.ModalResponse.OK {
								let configuration = self.configurationWindowController!.configuration
								dieView.color = configuration.color
								dieView.numberOfTimesToRoll = configuration.rolls
							}
							// All done with the window controller
							self.configurationWindowController = nil
							// closing the color panel
							let sharedColorPanel: NSColorPanel = NSColorPanel.shared
							sharedColorPanel.close()
		})
		configurationWindowController = windowController
	}
}