59 lines
2.3 KiB
Swift
59 lines
2.3 KiB
Swift
import Cocoa
|
|
|
|
@NSApplicationMain
|
|
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
|
|
@IBAction func showInfoAction(_ sender: Any) {
|
|
NSApplication.shared.keyWindow?.contentViewController?.performSegue(withIdentifier: "showInfo", sender: self)
|
|
}
|
|
|
|
@IBAction func showTimelapseAction(_ sender: Any) {
|
|
NSApplication.shared.keyWindow?.contentViewController?.performSegue(withIdentifier: "showTimelapse", sender: self)
|
|
}
|
|
|
|
func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
|
// Show timelapse and show info buttons
|
|
if(item.tag == 67 || item.tag == 68) {
|
|
return NSApplication.shared.keyWindow != nil
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
@IBAction func exportAction(_ sender: Any) {
|
|
let document = NSApplication.shared.keyWindow?.windowController?.document as? Document;
|
|
|
|
let savePanel = NSSavePanel()
|
|
savePanel.title = "Save"
|
|
savePanel.allowedFileTypes = ["public.png"]
|
|
savePanel.begin { (result) in
|
|
if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
|
|
let canvas = document?.makeComposite()
|
|
let canvasTiff = canvas?.tiffRepresentation
|
|
let bitmapImage = NSBitmapImageRep(data: canvasTiff!)
|
|
let canvasPng = bitmapImage!.representation(using: .png, properties: [:])
|
|
|
|
try? canvasPng?.write(to: savePanel.url!)
|
|
}
|
|
}
|
|
}
|
|
|
|
@IBAction func exportThumbnailAction(_ sender: Any) {
|
|
let document = NSApplication.shared.keyWindow?.windowController?.document as? Document;
|
|
|
|
let savePanel = NSSavePanel()
|
|
savePanel.title = "Save Thumbnail"
|
|
savePanel.allowedFileTypes = ["public.png"]
|
|
savePanel.begin { (result) in
|
|
if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
|
|
let canvas = document?.makeThumbnail()
|
|
let canvasTiff = canvas?.tiffRepresentation
|
|
let bitmapImage = NSBitmapImageRep(data: canvasTiff!)
|
|
let canvasPng = bitmapImage!.representation(using: .png, properties: [:])
|
|
|
|
try? canvasPng?.write(to: savePanel.url!)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|