1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
silica-viewer/SilicaViewer/AppDelegate.swift

60 lines
2.3 KiB
Swift
Raw Normal View History

2020-03-10 14:23:54 -04:00
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
@IBAction func showInfoAction(_ sender: Any) {
NSApplication.shared.keyWindow?.contentViewController?.performSegue(withIdentifier: "showInfo", sender: self)
}
2021-05-09 21:44:04 -04:00
@IBAction func showTimelapseAction(_ sender: Any) {
NSApplication.shared.keyWindow?.contentViewController?.performSegue(withIdentifier: "showTimelapse", sender: self)
}
func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
2021-05-09 21:44:04 -04:00
// Show timelapse and show info buttons
if(item.tag == 67 || item.tag == 68) {
2020-03-11 22:15:05 -04:00
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!)
}
}
}
2020-03-10 14:23:54 -04:00
}