2016-11-18 20:54:14 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2016-11-19 15:29:18 +03:00
|
|
|
enum ToolIdentifier: String {
|
|
|
|
|
|
|
|
case fileBrowser = "com.qvacua.vimr.tool.file-browser"
|
|
|
|
|
|
|
|
static let all = [ fileBrowser ]
|
2016-11-18 20:54:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ToolPrefData: StandardPrefData {
|
2016-11-19 15:29:18 +03:00
|
|
|
|
2016-11-18 20:54:14 +03:00
|
|
|
fileprivate static let identifier = "identifier"
|
2016-11-19 15:29:18 +03:00
|
|
|
fileprivate static let location = "location"
|
|
|
|
fileprivate static let isVisible = "is-visible"
|
2016-11-18 20:54:14 +03:00
|
|
|
fileprivate static let dimension = "dimension"
|
2016-11-19 15:29:18 +03:00
|
|
|
|
|
|
|
static let defaults: [ToolIdentifier: ToolPrefData] = [
|
|
|
|
.fileBrowser: ToolPrefData(identifier: .fileBrowser, location: .left, isVisible: true, dimension: 200),
|
|
|
|
]
|
|
|
|
|
|
|
|
var identifier: ToolIdentifier
|
|
|
|
var location: WorkspaceBarLocation
|
|
|
|
var isVisible: Bool
|
|
|
|
var dimension: CGFloat
|
|
|
|
|
|
|
|
init(identifier: ToolIdentifier, location: WorkspaceBarLocation, isVisible: Bool, dimension: CGFloat) {
|
2016-11-18 20:54:14 +03:00
|
|
|
self.identifier = identifier
|
2016-11-19 15:29:18 +03:00
|
|
|
self.location = location
|
2016-11-18 20:54:14 +03:00
|
|
|
self.isVisible = isVisible
|
|
|
|
self.dimension = dimension
|
|
|
|
}
|
2016-11-19 15:29:18 +03:00
|
|
|
|
2016-11-18 20:54:14 +03:00
|
|
|
func dict() -> [String: Any] {
|
|
|
|
return [
|
2016-11-19 15:29:18 +03:00
|
|
|
ToolPrefData.identifier: self.identifier.rawValue,
|
2016-11-20 12:51:15 +03:00
|
|
|
ToolPrefData.location: PrefUtils.locationAsString(for: self.location),
|
2016-11-18 20:54:14 +03:00
|
|
|
ToolPrefData.isVisible: self.isVisible,
|
2016-11-19 15:29:18 +03:00
|
|
|
ToolPrefData.dimension: Float(self.dimension),
|
2016-11-18 20:54:14 +03:00
|
|
|
]
|
|
|
|
}
|
2016-11-19 15:29:18 +03:00
|
|
|
|
2016-11-18 20:54:14 +03:00
|
|
|
init?(dict: [String: Any]) {
|
2016-11-19 15:29:18 +03:00
|
|
|
guard let identifierRawValue = dict[ToolPrefData.identifier] as? String,
|
|
|
|
let locationRawValue = dict[ToolPrefData.location] as? String,
|
|
|
|
let isVisible = PrefUtils.bool(from: dict, for: ToolPrefData.isVisible),
|
|
|
|
let fDimension = PrefUtils.float(from: dict, for: ToolPrefData.dimension)
|
|
|
|
else {
|
|
|
|
return nil
|
2016-11-18 20:54:14 +03:00
|
|
|
}
|
2016-11-19 15:29:18 +03:00
|
|
|
|
|
|
|
guard let identifier = ToolIdentifier(rawValue: identifierRawValue),
|
2016-11-20 12:51:15 +03:00
|
|
|
let location = PrefUtils.location(from: locationRawValue)
|
2016-11-19 15:29:18 +03:00
|
|
|
else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
self.init(identifier: identifier, location: location, isVisible: isVisible, dimension: CGFloat(fDimension))
|
2016-11-18 20:54:14 +03:00
|
|
|
}
|
|
|
|
}
|