From baac84383bb0c597f0f50689c0c9784921182ec1 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 28 Feb 2022 12:03:08 -0400 Subject: [PATCH] Handle document names better Now it's possible for the document title to be null, just like an author name. Also, the document title is used for the default filename when exporting. --- SilicaViewer/AppDelegate.swift | 2 ++ SilicaViewer/Document.swift | 8 ++++++++ SilicaViewer/InfoViewController.swift | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/SilicaViewer/AppDelegate.swift b/SilicaViewer/AppDelegate.swift index a14717b..0fd0032 100644 --- a/SilicaViewer/AppDelegate.swift +++ b/SilicaViewer/AppDelegate.swift @@ -71,6 +71,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { let savePanel = NSSavePanel() savePanel.title = "Save Timelapse" savePanel.allowedFileTypes = ["public.mpeg-4"] + savePanel.nameFieldStringValue = (document?.getIdealFilename())! + savePanel.begin { (result) in if result.rawValue == NSApplication.ModalResponse.OK.rawValue { guard let archive = Archive(data: (document?.data)!, accessMode: Archive.AccessMode.read) else { diff --git a/SilicaViewer/Document.swift b/SilicaViewer/Document.swift index a7d3a60..0b1c89d 100644 --- a/SilicaViewer/Document.swift +++ b/SilicaViewer/Document.swift @@ -113,6 +113,14 @@ class Document: NSDocument { return ofType == "com.procreate" } + func getIdealFilename() -> String { + if (!(info.name.isEmpty)) { + return info.name + } else { + return fileURL!.deletingPathExtension().lastPathComponent + } + } + /* Pass in an object from the $object array, which always contains a $class key. */ diff --git a/SilicaViewer/InfoViewController.swift b/SilicaViewer/InfoViewController.swift index c0349b0..afe8e31 100644 --- a/SilicaViewer/InfoViewController.swift +++ b/SilicaViewer/InfoViewController.swift @@ -13,7 +13,11 @@ class InfoViewController: NSViewController { override func viewWillAppear() { super.viewDidAppear() - nameLabel.stringValue = "Name: " + document!.info.name + if document!.info.authorName.isEmpty { + nameLabel.stringValue = "Name is not set." + } else { + nameLabel.stringValue = "Name: " + document!.info.name + } if document!.info.authorName.isEmpty { authorNameField.stringValue = "Author name is not set."