Archived
1
This repository has been archived on 2020-06-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tagtunes/TagTunes/SaveTableCellView.swift
Kim Wittenburg 0a485ff42a Stuff…
2019-02-01 22:59:01 +01:00

63 lines
2.2 KiB
Swift
Executable File

//
// SaveTableCellView.swift
// TagTunes
//
// Created by Kim Wittenburg on 08.04.16.
// Copyright © 2016 Kim Wittenburg. All rights reserved.
//
import AppKitPlus
// TODO: Generalize for AppKitPlus
class SaveTableCellView: AdvancedTableCellView {
let progressIndicator: NSProgressIndicator = {
let indicator = NSProgressIndicator()
indicator.style = .SpinningStyle
indicator.controlSize = .SmallControlSize
indicator.minValue = 0
indicator.maxValue = 1
indicator.translatesAutoresizingMaskIntoConstraints = false
return indicator
}()
let cancelButton: NSButton = {
let button = NSButton()
button.setButtonType(.MomentaryChangeButton)
button.bezelStyle = .ShadowlessSquareBezelStyle
button.bordered = false
button.imagePosition = .ImageOnly
button.image = NSImage(named: NSImageNameStopProgressFreestandingTemplate)
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()
dynamic var progress: NSProgress?
override func setupView() {
style = .Subtitle
cancelButton.target = self
cancelButton.action = #selector(SaveTableCellView.cancel(_:))
let stackView = NSStackView(views: [progressIndicator, cancelButton])
stackView.orientation = .Horizontal
rightAccessoryView = stackView
// Setup bindings
primaryTextField?.bind(NSValueBinding, toObject: self, withKeyPath: "progress.localizedDescription", options: nil)
secondaryTextField?.bind(NSValueBinding, toObject: self, withKeyPath: "progress.localizedAdditionalDescription", options: nil)
cancelButton.bind(NSEnabledBinding, toObject: self, withKeyPath: "progress.cancellable", options: nil)
progressIndicator.bind(NSValueBinding, toObject: self, withKeyPath: "progress.fractionCompleted", options: nil)
progressIndicator.bind(NSIsIndeterminateBinding, toObject: self, withKeyPath: "progress.indeterminate", options: nil)
progressIndicator.bind(NSAnimateBinding, toObject: self, withKeyPath: "progress.indeterminate", options: nil)
super.setupView()
}
func cancel(sender: AnyObject?) {
progress?.cancel()
}
}