From 4103cbacfbf810319e73dce8465d1f4d0a4598cc Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 16 Sep 2021 19:03:32 -0400 Subject: [PATCH] Increase entitlement, add save functionality --- SilicaViewer/AppDelegate.swift | 37 +++++++++++++++++++++++++ SilicaViewer/Base.lproj/Main.storyboard | 12 ++++++-- SilicaViewer/SilicaViewer.entitlements | 2 +- 3 files changed, 48 insertions(+), 3 deletions(-) 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