11/*******************************************************************************
22 * The MIT License (MIT)
3- *
4- * Copyright (c) 2018 Jean-David Gadina - www.imazing.com
5- *
3+ *
4+ * Copyright (c) 2022, DigiDNA
5+ *
66 * Permission is hereby granted, free of charge, to any person obtaining a copy
7- * of this software and associated documentation files (the " Software" ), to deal
7+ * of this software and associated documentation files (the Software), to deal
88 * in the Software without restriction, including without limitation the rights
99 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1010 * copies of the Software, and to permit persons to whom the Software is
1111 * furnished to do so, subject to the following conditions:
12- *
12+ *
1313 * The above copyright notice and this permission notice shall be included in
1414 * all copies or substantial portions of the Software.
15- *
16- * THE SOFTWARE IS PROVIDED " AS IS" , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+ *
16+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1717 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1818 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1919 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
@@ -30,7 +30,7 @@ class ApplicationDelegate: NSResponder, NSApplicationDelegate
3030{
3131 private var controllers = [ NSWindowController ] ( )
3232 private var aboutWindowController : NSWindowController ?
33-
33+
3434 func applicationDidFinishLaunching( _ notification: Notification )
3535 {
3636 DispatchQueue . main. asyncAfter ( deadline: . now( ) + . milliseconds( 500 ) )
@@ -40,134 +40,142 @@ class ApplicationDelegate: NSResponder, NSApplicationDelegate
4040 self . newDocument ( nil )
4141 }
4242 }
43-
44- NotificationCenter . default. addObserver ( self , selector: #selector( windowWillClose ( _: ) ) , name: NSWindow . willCloseNotification, object: nil )
45-
43+
44+ NotificationCenter . default. addObserver ( self , selector: #selector( self . windowWillClose ( _: ) ) , name: NSWindow . willCloseNotification, object: nil )
45+
4646 #if DEBUG
47- UserDefaults . standard. register ( defaults: [ " NSApplicationCrashOnExceptions " : true ] )
47+ UserDefaults . standard. register ( defaults: [ " NSApplicationCrashOnExceptions " : true ] )
4848 #endif
4949 }
5050
5151 func applicationWillTerminate( _ notification: Notification )
5252 { }
53-
54- @IBAction public func newDocument( _ sender: Any ? )
53+
54+ @IBAction
55+ public func newDocument( _ sender: Any ? )
5556 {
5657 let controller = MainWindowController ( )
57-
58+
5859 controller. window? . center ( )
5960 controller. window? . makeKeyAndOrderFront ( sender )
60-
61+
6162 self . controllers. append ( controller )
6263 }
63-
64- @IBAction public func showAboutWindow( _ sender: Any ? )
64+
65+ @IBAction
66+ public func showAboutWindow( _ sender: Any ? )
6567 {
66- if ( self . aboutWindowController == nil )
68+ if self . aboutWindowController == nil
6769 {
6870 self . aboutWindowController = AboutWindowController ( )
69-
71+
7072 self . aboutWindowController? . window? . layoutIfNeeded ( )
7173 self . aboutWindowController? . window? . center ( )
7274 }
73-
75+
7476 self . aboutWindowController? . window? . makeKeyAndOrderFront ( sender )
7577 }
76-
78+
7779 func application( _ sender: NSApplication , openFile filename: String ) -> Bool
7880 {
7981 return self . open ( url: URL ( fileURLWithPath: filename ) )
8082 }
81-
82- @IBAction public func openDocument( _ sender: Any ? )
83+
84+ @IBAction
85+ public func openDocument( _ sender: Any ? )
8386 {
8487 let panel = NSOpenPanel ( )
85-
88+
8689 panel. canChooseDirectories = false
8790 panel. canChooseFiles = true
8891 panel. canCreateDirectories = false
8992 panel. allowsMultipleSelection = false
9093 panel. allowedFileTypes = [ " colorset " ]
91-
94+
9295 let r = panel. runModal ( )
93-
94- if ( r != . OK )
96+
97+ if r != . OK
9598 {
9699 return
97100 }
98-
99- guard let url = panel. url else
101+
102+ guard let url = panel. url
103+ else
100104 {
101105 return
102106 }
103-
104- let _ = self . open ( url: url )
107+
108+ _ = self . open ( url: url )
105109 }
106-
110+
107111 private func open( url: URL ) -> Bool
108112 {
109- guard let set = ColorSet ( url: url ) else
113+ guard let set = ColorSet ( url: url )
114+ else
110115 {
111116 let alert = NSAlert ( )
112117 alert. messageText = " Load error "
113118 alert. informativeText = " Invalid data format "
114-
119+
115120 alert. runModal ( )
116-
121+
117122 return false
118123 }
119-
124+
120125 var colors = [ ColorItem ] ( )
121-
126+
122127 for p in set. colors
123128 {
124- guard let color = p. value. color else
129+ guard let color = p. value. color
130+ else
125131 {
126132 continue
127133 }
128-
134+
129135 let item = ColorItem ( )
130136 item. name = p. key
131137 item. color = color
132138 item. variant = p. value. variant
133-
139+
134140 for lp in p. value. lightnesses
135141 {
136142 let lightness = LightnessPairItem ( base: item )
137-
143+
138144 lightness. lightness1. lightness = lp. lightness1. lightness
139145 lightness. lightness1. name = lp. lightness1. name
140146 lightness. lightness2. lightness = lp. lightness2. lightness
141147 lightness. lightness2. name = lp. lightness2. name
142-
148+
143149 item. lightnessPairs. append ( lightness )
144150 }
145-
151+
146152 colors. append ( item )
147153 }
148-
154+
149155 let controller = MainWindowController ( colors: colors, format: set. format )
150156 controller. url = url
151-
157+
152158 controller. window? . center ( )
153159 controller. window? . makeKeyAndOrderFront ( nil )
154-
160+
155161 self . controllers. append ( controller )
156-
162+
157163 return true
158164 }
159-
160- @objc private func windowWillClose( _ notification: Notification )
165+
166+ @objc
167+ private func windowWillClose( _ notification: Notification )
161168 {
162169 self . controllers. removeAll
163170 {
164171 c in
165-
166- guard let window = notification. object as? NSWindow else
172+
173+ guard let window = notification. object as? NSWindow
174+ else
167175 {
168176 return false
169177 }
170-
178+
171179 return c. window == window
172180 }
173181 }
0 commit comments