1
Fork 0

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.
This commit is contained in:
Joshua Goins 2022-02-28 12:03:08 -04:00
parent e3b94dee42
commit baac84383b
3 changed files with 15 additions and 1 deletions

View file

@ -71,6 +71,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations {
let savePanel = NSSavePanel() let savePanel = NSSavePanel()
savePanel.title = "Save Timelapse" savePanel.title = "Save Timelapse"
savePanel.allowedFileTypes = ["public.mpeg-4"] savePanel.allowedFileTypes = ["public.mpeg-4"]
savePanel.nameFieldStringValue = (document?.getIdealFilename())!
savePanel.begin { (result) in savePanel.begin { (result) in
if result.rawValue == NSApplication.ModalResponse.OK.rawValue { if result.rawValue == NSApplication.ModalResponse.OK.rawValue {
guard let archive = Archive(data: (document?.data)!, accessMode: Archive.AccessMode.read) else { guard let archive = Archive(data: (document?.data)!, accessMode: Archive.AccessMode.read) else {

View file

@ -113,6 +113,14 @@ class Document: NSDocument {
return ofType == "com.procreate" 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. Pass in an object from the $object array, which always contains a $class key.
*/ */

View file

@ -13,7 +13,11 @@ class InfoViewController: NSViewController {
override func viewWillAppear() { override func viewWillAppear() {
super.viewDidAppear() super.viewDidAppear()
if document!.info.authorName.isEmpty {
nameLabel.stringValue = "Name is not set."
} else {
nameLabel.stringValue = "Name: " + document!.info.name nameLabel.stringValue = "Name: " + document!.info.name
}
if document!.info.authorName.isEmpty { if document!.info.authorName.isEmpty {
authorNameField.stringValue = "Author name is not set." authorNameField.stringValue = "Author name is not set."