From 5b8b9395e638b1e9857ca9bfb3597b1ccc85db74 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 20 Sep 2021 14:13:58 -0400 Subject: [PATCH] Add document name, author name, and stroke count properties --- Shared/Shared.swift | 3 + SilicaViewer/Base.lproj/Main.storyboard | 78 ++++++++++++++++++------- SilicaViewer/Document.swift | 23 ++++++++ SilicaViewer/InfoViewController.swift | 15 ++++- 4 files changed, 97 insertions(+), 22 deletions(-) diff --git a/Shared/Shared.swift b/Shared/Shared.swift index 3b38b3d..f3711b6 100644 --- a/Shared/Shared.swift +++ b/Shared/Shared.swift @@ -16,6 +16,9 @@ let SizeKey = "size" let OrientationKey = "orientation" let FlippedHorizontallyKey = "flippedHorizontally" let FlippedVerticallyKey = "flippedVertically" +let NameKey = "name" +let AuthorNameKey = "authorName" +let StrokeCountKey = "strokeCount" let LayerClassName = "SilicaLayer" diff --git a/SilicaViewer/Base.lproj/Main.storyboard b/SilicaViewer/Base.lproj/Main.storyboard index 74f8375..64d5ca5 100644 --- a/SilicaViewer/Base.lproj/Main.storyboard +++ b/SilicaViewer/Base.lproj/Main.storyboard @@ -183,30 +183,43 @@ - + - - - + + + - - - + + + + + + + + + + + + + + + + + + + - -Dk51bWJlciBvZiBMYXllcnM6A - + + + + + +Dk51bWJlciBvZiBMYXllcnM + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + - + + + - + diff --git a/SilicaViewer/Document.swift b/SilicaViewer/Document.swift index fa48fbf..b24c51c 100644 --- a/SilicaViewer/Document.swift +++ b/SilicaViewer/Document.swift @@ -26,6 +26,9 @@ struct SilicaDocument { var orientation: Int = 0 var flippedHorizontally: Bool = false var flippedVertically: Bool = false + var name: String = "" + var authorName: String = "" + var strokeCount: Int = 0 var width: Int = 0 var height: Int = 0 @@ -232,6 +235,26 @@ class Document: NSDocument { info.orientation = (dict[OrientationKey] as! NSNumber).intValue info.flippedHorizontally = (dict[FlippedHorizontallyKey] as! NSNumber).boolValue info.flippedVertically = (dict[FlippedVerticallyKey] as! NSNumber).boolValue + + let strokeClassKey = dict[StrokeCountKey] + let strokeClassID = getClassID(id: strokeClassKey) + let strokeCount = objectsArray[strokeClassID] as! NSNumber + + info.strokeCount = Int(strokeCount) + + let nameClassKey = dict[NameKey] + let nameClassID = getClassID(id: nameClassKey) + let nameString = objectsArray[nameClassID] as! String + + info.name = nameString + + let authorClassKey = dict[AuthorNameKey] + let authorClassID = getClassID(id: authorClassKey) + let authorString = objectsArray[authorClassID] as! String + + if authorString != "$null" { + info.authorName = authorString + } let sizeClassKey = dict[SizeKey] let sizeClassID = getClassID(id: sizeClassKey) diff --git a/SilicaViewer/InfoViewController.swift b/SilicaViewer/InfoViewController.swift index 4ca2d68..c0349b0 100644 --- a/SilicaViewer/InfoViewController.swift +++ b/SilicaViewer/InfoViewController.swift @@ -4,19 +4,32 @@ import Cocoa class InfoViewController: NSViewController { var document: Document? + @IBOutlet weak var nameLabel: NSTextField! + @IBOutlet weak var authorNameField: NSTextField! @IBOutlet weak var timeSpentLabel: NSTextField! + @IBOutlet weak var strokeCountField: NSTextField! @IBOutlet weak var layerCountLabel: NSTextField! override func viewWillAppear() { super.viewDidAppear() + nameLabel.stringValue = "Name: " + document!.info.name + + if document!.info.authorName.isEmpty { + authorNameField.stringValue = "Author name is not set." + } else { + authorNameField.stringValue = "Author name: " + document!.info.authorName + } + + strokeCountField.stringValue = "Number of strokes: " + String(document!.info.strokeCount) + let formatter = DateComponentsFormatter() formatter.allowedUnits = [.hour, .minute, .second] formatter.unitsStyle = .full let formattedString = formatter.string(from: TimeInterval(document!.info.trackedTime))! - timeSpentLabel.stringValue = "Time Spent: " + formattedString + timeSpentLabel.stringValue = "Time spent: " + formattedString layerCountLabel.stringValue = "Number of layers: " + String(document!.info.layers.count) }