diff --git a/SilicaViewer/AppDelegate.swift b/SilicaViewer/AppDelegate.swift index 7519fca..03608c2 100644 --- a/SilicaViewer/AppDelegate.swift +++ b/SilicaViewer/AppDelegate.swift @@ -18,5 +18,42 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { 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!) + } + } + } + } diff --git a/SilicaViewer/Base.lproj/Main.storyboard b/SilicaViewer/Base.lproj/Main.storyboard index 4fa5758..74f8375 100644 --- a/SilicaViewer/Base.lproj/Main.storyboard +++ b/SilicaViewer/Base.lproj/Main.storyboard @@ -79,8 +79,16 @@ - - + + + + + + + + + + diff --git a/SilicaViewer/SilicaViewer.entitlements b/SilicaViewer/SilicaViewer.entitlements index 18aff0c..19afff1 100644 --- a/SilicaViewer/SilicaViewer.entitlements +++ b/SilicaViewer/SilicaViewer.entitlements @@ -4,7 +4,7 @@ com.apple.security.app-sandbox - com.apple.security.files.user-selected.read-only + com.apple.security.files.user-selected.read-write