2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// IndeterminateProgressWindowController.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 8/28/16.
|
2017-05-29 22:17:58 +02:00
|
|
|
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
2017-11-12 20:01:17 +01:00
|
|
|
func runIndeterminateProgressWithMessage(_ message: String) {
|
|
|
|
|
|
|
|
IndeterminateProgressController.beginProgressWithMessage(message)
|
|
|
|
}
|
|
|
|
|
|
|
|
func stopIndeterminateProgress() {
|
|
|
|
|
|
|
|
IndeterminateProgressController.endProgress()
|
|
|
|
}
|
|
|
|
|
|
|
|
private final class IndeterminateProgressController {
|
|
|
|
|
|
|
|
static var windowController: IndeterminateProgressWindowController?
|
|
|
|
static var runningProgressWindow = false
|
|
|
|
|
|
|
|
static func beginProgressWithMessage(_ message: String) {
|
|
|
|
|
|
|
|
if runningProgressWindow {
|
|
|
|
assertionFailure("Expected !runningProgressWindow.")
|
|
|
|
endProgress()
|
|
|
|
}
|
|
|
|
|
|
|
|
runningProgressWindow = true
|
|
|
|
windowController = IndeterminateProgressWindowController(message: message)
|
|
|
|
NSApplication.shared.runModal(for: windowController!.window!)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func endProgress() {
|
|
|
|
|
|
|
|
if !runningProgressWindow {
|
|
|
|
assertionFailure("Expected runningProgressWindow.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
runningProgressWindow = false
|
|
|
|
NSApplication.shared.stopModal()
|
|
|
|
windowController?.close()
|
|
|
|
windowController = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final class IndeterminateProgressWindowController: NSWindowController {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
@IBOutlet var messageLabel: NSTextField!
|
|
|
|
@IBOutlet var progressIndicator: NSProgressIndicator!
|
2017-09-17 21:34:10 +02:00
|
|
|
@objc dynamic var message = ""
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
convenience init(message: String) {
|
|
|
|
|
2017-09-17 21:54:08 +02:00
|
|
|
self.init(windowNibName: NSNib.Name(rawValue: "IndeterminateProgressWindow"))
|
2017-05-27 19:43:27 +02:00
|
|
|
self.message = message
|
|
|
|
}
|
|
|
|
|
|
|
|
override func windowDidLoad() {
|
|
|
|
|
|
|
|
progressIndicator.startAnimation(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|