2016-09-18 21:49:42 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
protocol WorkspaceToolDelegate: class {
|
|
|
|
|
2016-09-25 18:50:33 +03:00
|
|
|
func toggle(_ tool: WorkspaceTool)
|
2016-09-18 21:49:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class WorkspaceTool {
|
|
|
|
|
2016-09-25 01:44:10 +03:00
|
|
|
// MARK: - API
|
2016-09-18 21:49:42 +03:00
|
|
|
let title: String
|
|
|
|
let view: NSView
|
|
|
|
let button: WorkspaceToolButton
|
|
|
|
var location = WorkspaceBarLocation.left {
|
|
|
|
didSet {
|
|
|
|
self.button.location = self.location
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var isSelected = false {
|
|
|
|
didSet {
|
|
|
|
if self.isSelected {
|
|
|
|
self.button.highlight()
|
|
|
|
} else {
|
|
|
|
self.button.dehighlight()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
weak var delegate: WorkspaceToolDelegate?
|
|
|
|
|
2016-10-03 10:45:38 +03:00
|
|
|
let minimumDimension: CGFloat
|
|
|
|
var dimension: CGFloat
|
2016-09-18 21:49:42 +03:00
|
|
|
|
2016-10-03 10:45:38 +03:00
|
|
|
init(title: String, view: NSView, minimumDimension: CGFloat = 50) {
|
2016-09-18 21:49:42 +03:00
|
|
|
self.title = title
|
|
|
|
self.view = view
|
2016-10-03 10:45:38 +03:00
|
|
|
self.minimumDimension = minimumDimension
|
|
|
|
self.dimension = minimumDimension
|
2016-09-18 21:49:42 +03:00
|
|
|
self.button = WorkspaceToolButton(title: title)
|
|
|
|
|
|
|
|
self.button.tool = self
|
|
|
|
}
|
|
|
|
|
|
|
|
func toggle() {
|
2016-09-25 18:50:33 +03:00
|
|
|
self.delegate?.toggle(self)
|
2016-09-18 21:49:42 +03:00
|
|
|
self.isSelected = !self.isSelected
|
|
|
|
}
|
|
|
|
}
|