1
Fork 0

Add document name, author name, and stroke count properties

This commit is contained in:
Joshua Goins 2021-09-20 14:13:58 -04:00
parent 7ceb0e76b6
commit 5b8b9395e6
4 changed files with 97 additions and 22 deletions

View file

@ -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"

View file

@ -183,30 +183,43 @@
<objects>
<viewController showSeguePresentationStyle="single" id="wda-Mt-beD" customClass="InfoViewController" customModule="Silica_Viewer" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="3vu-Kd-l73">
<rect key="frame" x="0.0" y="0.0" width="480" height="109"/>
<rect key="frame" x="0.0" y="0.0" width="480" height="179"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="u9u-el-oA4">
<rect key="frame" x="18" y="73" width="444" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" placeholderString="Time Spent" id="UBd-vS-gNL">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="u9u-el-oA4" userLabel="Stroke Count Label">
<rect key="frame" x="18" y="95" width="444" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" placeholderString="Stroke Count" id="UBd-vS-gNL">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8HM-na-o1E">
<rect key="frame" x="18" y="49" width="444" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" id="cl0-u1-l9k">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9y5-gZ-hbp" userLabel="Time Spent Field">
<rect key="frame" x="18" y="71" width="444" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" placeholderString="Time Spent" id="bdX-Xe-WL8">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Ajp-l6-F9d" userLabel="Name Field">
<rect key="frame" x="18" y="143" width="444" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" placeholderString="Name" id="T1W-9x-AN3">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="f9O-TT-yx8" userLabel="Author Name Field">
<rect key="frame" x="18" y="119" width="444" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" placeholderString="Author Name" id="ijW-Lb-cAj">
<font key="font" usesAppearanceFont="YES"/>
<string key="placeholderString" base64-UTF8="YES">
Dk51bWJlciBvZiBMYXllcnM6A
</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="2oe-to-Rcz">
<rect key="frame" x="414" y="14" width="53" height="32"/>
<rect key="frame" x="414" y="12" width="53" height="32"/>
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="BnS-yc-3ej">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
@ -218,26 +231,49 @@ DQ
<action selector="dismissController:" target="wda-Mt-beD" id="LJb-SK-4qT"/>
</connections>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="8HM-na-o1E">
<rect key="frame" x="18" y="47" width="444" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" id="cl0-u1-l9k">
<font key="font" usesAppearanceFont="YES"/>
<string key="placeholderString" base64-UTF8="YES">
Dk51bWJlciBvZiBMYXllcnM
</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="8HM-na-o1E" firstAttribute="top" secondItem="u9u-el-oA4" secondAttribute="bottom" constant="8" symbolic="YES" id="CA1-bq-4Dc"/>
<constraint firstItem="u9u-el-oA4" firstAttribute="trailing" secondItem="8HM-na-o1E" secondAttribute="trailing" id="ILX-8S-pOI"/>
<constraint firstItem="u9u-el-oA4" firstAttribute="top" secondItem="3vu-Kd-l73" secondAttribute="top" constant="20" symbolic="YES" id="IQj-on-T5L"/>
<constraint firstItem="u9u-el-oA4" firstAttribute="leading" secondItem="8HM-na-o1E" secondAttribute="leading" id="KJd-X5-kxh"/>
<constraint firstAttribute="trailing" secondItem="u9u-el-oA4" secondAttribute="trailing" constant="20" symbolic="YES" id="PlA-zS-FpK"/>
<constraint firstItem="u9u-el-oA4" firstAttribute="leading" secondItem="3vu-Kd-l73" secondAttribute="leading" constant="20" symbolic="YES" id="Xzy-ZR-1ha"/>
<constraint firstItem="2oe-to-Rcz" firstAttribute="top" secondItem="8HM-na-o1E" secondAttribute="bottom" constant="8" symbolic="YES" id="ZQM-5m-wzY"/>
<constraint firstItem="2oe-to-Rcz" firstAttribute="trailing" secondItem="8HM-na-o1E" secondAttribute="trailing" id="oGX-cy-Uhv"/>
<constraint firstItem="u9u-el-oA4" firstAttribute="leading" secondItem="f9O-TT-yx8" secondAttribute="leading" id="8Z2-tT-vjI"/>
<constraint firstItem="9y5-gZ-hbp" firstAttribute="leading" secondItem="u9u-el-oA4" secondAttribute="leading" id="BMo-LP-6ZH"/>
<constraint firstItem="Ajp-l6-F9d" firstAttribute="leading" secondItem="f9O-TT-yx8" secondAttribute="leading" id="CVY-Yu-32J"/>
<constraint firstItem="u9u-el-oA4" firstAttribute="trailing" secondItem="f9O-TT-yx8" secondAttribute="trailing" id="Fvt-kq-Ewy"/>
<constraint firstItem="Ajp-l6-F9d" firstAttribute="top" secondItem="3vu-Kd-l73" secondAttribute="top" constant="20" symbolic="YES" id="Hht-ZK-a5D"/>
<constraint firstItem="8HM-na-o1E" firstAttribute="top" secondItem="9y5-gZ-hbp" secondAttribute="bottom" constant="8" symbolic="YES" id="Hi9-Lg-dRP"/>
<constraint firstAttribute="trailing" secondItem="u9u-el-oA4" secondAttribute="trailing" constant="20" symbolic="YES" id="MBp-KE-oM6"/>
<constraint firstItem="u9u-el-oA4" firstAttribute="leading" secondItem="3vu-Kd-l73" secondAttribute="leading" constant="20" symbolic="YES" id="Rn1-TV-WPu"/>
<constraint firstItem="8HM-na-o1E" firstAttribute="leading" secondItem="9y5-gZ-hbp" secondAttribute="leading" id="Tnf-NR-8Y8"/>
<constraint firstItem="f9O-TT-yx8" firstAttribute="top" secondItem="Ajp-l6-F9d" secondAttribute="bottom" constant="8" symbolic="YES" id="XS7-fP-oar"/>
<constraint firstItem="2oe-to-Rcz" firstAttribute="top" secondItem="8HM-na-o1E" secondAttribute="bottom" constant="8" symbolic="YES" id="XTm-WM-fg5"/>
<constraint firstItem="2oe-to-Rcz" firstAttribute="trailing" secondItem="8HM-na-o1E" secondAttribute="trailing" id="YM1-dg-H0g"/>
<constraint firstItem="u9u-el-oA4" firstAttribute="top" secondItem="f9O-TT-yx8" secondAttribute="bottom" constant="8" symbolic="YES" id="aU4-bb-tP4"/>
<constraint firstItem="9y5-gZ-hbp" firstAttribute="trailing" secondItem="u9u-el-oA4" secondAttribute="trailing" id="gJU-p0-IO5"/>
<constraint firstItem="Ajp-l6-F9d" firstAttribute="trailing" secondItem="f9O-TT-yx8" secondAttribute="trailing" id="oal-r9-bhZ"/>
<constraint firstItem="8HM-na-o1E" firstAttribute="trailing" secondItem="9y5-gZ-hbp" secondAttribute="trailing" id="q2q-zH-EkW"/>
<constraint firstItem="9y5-gZ-hbp" firstAttribute="top" secondItem="u9u-el-oA4" secondAttribute="bottom" constant="8" symbolic="YES" id="xgw-NM-ndc"/>
</constraints>
</view>
<connections>
<outlet property="authorNameField" destination="f9O-TT-yx8" id="XCg-yz-XdZ"/>
<outlet property="layerCountLabel" destination="8HM-na-o1E" id="Vnq-ev-JGx"/>
<outlet property="timeSpentLabel" destination="u9u-el-oA4" id="LeI-31-Z8r"/>
<outlet property="nameLabel" destination="Ajp-l6-F9d" id="uk2-IQ-k3Z"/>
<outlet property="strokeCountField" destination="u9u-el-oA4" id="l7p-6j-I44"/>
<outlet property="timeSpentLabel" destination="9y5-gZ-hbp" id="t4r-rz-EtY"/>
</connections>
</viewController>
<customObject id="Tam-yi-Bux" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="786" y="298.5"/>
<point key="canvasLocation" x="786" y="333.5"/>
</scene>
<!--Window Controller-->
<scene sceneID="IIQ-mF-530">

View file

@ -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
@ -233,6 +236,26 @@ class Document: NSDocument {
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)
let sizeString = objectsArray[sizeClassID] as! String

View file

@ -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)
}