|
|
@ -13,6 +13,10 @@ struct PanelConstants { |
|
|
|
|
|
|
|
|
|
|
|
class ParentPanelController: NSWindowController { |
|
|
|
class ParentPanelController: NSWindowController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var futureSliderObserver: NSKeyValueObservation? |
|
|
|
|
|
|
|
private var userFontSizeSelectionObserver: NSKeyValueObservation? |
|
|
|
|
|
|
|
private var futureSliderRangeObserver: NSKeyValueObservation? |
|
|
|
|
|
|
|
|
|
|
|
private var eventStoreChangedNotification: NSObjectProtocol? |
|
|
|
private var eventStoreChangedNotification: NSObjectProtocol? |
|
|
|
|
|
|
|
|
|
|
|
var dateFormatter = DateFormatter() |
|
|
|
var dateFormatter = DateFormatter() |
|
|
@ -87,6 +91,32 @@ class ParentPanelController: NSWindowController { |
|
|
|
if let eventStoreNotif = eventStoreChangedNotification { |
|
|
|
if let eventStoreNotif = eventStoreChangedNotification { |
|
|
|
NotificationCenter.default.removeObserver(eventStoreNotif) |
|
|
|
NotificationCenter.default.removeObserver(eventStoreNotif) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[futureSliderObserver, userFontSizeSelectionObserver, futureSliderRangeObserver].forEach { |
|
|
|
|
|
|
|
$0?.invalidate() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func setupObservers() { |
|
|
|
|
|
|
|
futureSliderObserver = UserDefaults.standard.observe(\.displayFutureSlider, options: [.new]) { (_, change) in |
|
|
|
|
|
|
|
if let changedValue = change.newValue { |
|
|
|
|
|
|
|
self.futureSliderView.isHidden = changedValue == 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userFontSizeSelectionObserver = UserDefaults.standard.observe(\.userFontSize, options: [.new]) { (_, change) in |
|
|
|
|
|
|
|
if let newFontSize = change.newValue { |
|
|
|
|
|
|
|
Logger.log(object: ["FontSize": newFontSize], for: "User Font Size Preference") |
|
|
|
|
|
|
|
self.mainTableView.reloadData() |
|
|
|
|
|
|
|
self.setScrollViewConstraint() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
futureSliderRangeObserver = UserDefaults.standard.observe(\.sliderDayRange, options: [.new]) { (_, change) in |
|
|
|
|
|
|
|
if change.newValue != nil { |
|
|
|
|
|
|
|
self.adjustFutureSliderBasedOnPreferences() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override func awakeFromNib() { |
|
|
|
override func awakeFromNib() { |
|
|
@ -107,13 +137,7 @@ class ParentPanelController: NSWindowController { |
|
|
|
mainTableView.selectionHighlightStyle = .none |
|
|
|
mainTableView.selectionHighlightStyle = .none |
|
|
|
mainTableView.enclosingScrollView?.hasVerticalScroller = false |
|
|
|
mainTableView.enclosingScrollView?.hasVerticalScroller = false |
|
|
|
|
|
|
|
|
|
|
|
[CLDisplayFutureSliderKey, CLUserFontSizePreference, CLThemeKey, CLFutureSliderRange].forEach { key in |
|
|
|
setupObservers() |
|
|
|
|
|
|
|
|
|
|
|
UserDefaults.standard.addObserver(self, |
|
|
|
|
|
|
|
forKeyPath: key, |
|
|
|
|
|
|
|
options: .new, |
|
|
|
|
|
|
|
context: nil) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateReviewViewFontColor() |
|
|
|
updateReviewViewFontColor() |
|
|
|
|
|
|
|
|
|
|
@ -281,6 +305,8 @@ class ParentPanelController: NSWindowController { |
|
|
|
sharingButton.image = sharedThemer.sharingImage() |
|
|
|
sharingButton.image = sharedThemer.sharingImage() |
|
|
|
|
|
|
|
|
|
|
|
sliderDatePicker.textColor = sharedThemer.mainTextColor() |
|
|
|
sliderDatePicker.textColor = sharedThemer.mainTextColor() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateReviewViewFontColor() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override func windowDidLoad() { |
|
|
|
override func windowDidLoad() { |
|
|
@ -302,25 +328,6 @@ class ParentPanelController: NSWindowController { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override func observeValue(forKeyPath keyPath: String?, of _: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) { |
|
|
|
|
|
|
|
if keyPath == CLDisplayFutureSliderKey, let changes = change, let new = changes[NSKeyValueChangeKey.newKey] as? NSNumber { |
|
|
|
|
|
|
|
futureSliderView.isHidden = new.isEqual(to: NSNumber(value: 1)) |
|
|
|
|
|
|
|
} else if keyPath == CLUserFontSizePreference, let userFontSize = DataStore.shared().retrieve(key: CLUserFontSizePreference) as? NSNumber { |
|
|
|
|
|
|
|
Logger.log(object: ["FontSize": userFontSize], for: "User Font Size Preference") |
|
|
|
|
|
|
|
mainTableView.reloadData() |
|
|
|
|
|
|
|
setScrollViewConstraint() |
|
|
|
|
|
|
|
} else if keyPath == CLThemeKey { |
|
|
|
|
|
|
|
updateReviewViewFontColor() |
|
|
|
|
|
|
|
} else if keyPath == CLFutureSliderRange { |
|
|
|
|
|
|
|
adjustFutureSliderBasedOnPreferences() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
super.observeValue(forKeyPath: keyPath, |
|
|
|
|
|
|
|
of: keyPath, |
|
|
|
|
|
|
|
change: change, |
|
|
|
|
|
|
|
context: context) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func screenHeight() -> CGFloat { |
|
|
|
func screenHeight() -> CGFloat { |
|
|
|
guard let main = NSScreen.main else { return 100 } |
|
|
|
guard let main = NSScreen.main else { return 100 } |
|
|
|
|
|
|
|
|
|
|
@ -343,38 +350,42 @@ class ParentPanelController: NSWindowController { |
|
|
|
parentTimer = nil |
|
|
|
parentTimer = nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setScrollViewConstraint() { |
|
|
|
private func getAdjustedRowHeight(for object: TimezoneData?, _ currentHeight: CGFloat) -> CGFloat { |
|
|
|
var totalHeight: CGFloat = 0.0 |
|
|
|
var newHeight = currentHeight |
|
|
|
let preferences = defaultPreferences |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for cellIndex in 0 ..< preferences.count { |
|
|
|
if newHeight <= 68.0 { |
|
|
|
let currentObject = TimezoneData.customObject(from: preferences[cellIndex]) |
|
|
|
newHeight = 69.0 |
|
|
|
let rowRect = mainTableView.rect(ofRow: cellIndex) |
|
|
|
|
|
|
|
var height: CGFloat = rowRect.size.height |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if height <= 68.0 { |
|
|
|
|
|
|
|
height = 69.0 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if height >= 68.0 { |
|
|
|
if newHeight >= 68.0 { |
|
|
|
height = 75.0 |
|
|
|
newHeight = 75.0 |
|
|
|
if let note = currentObject?.note, note.isEmpty == false { |
|
|
|
if let note = object?.note, note.isEmpty == false { |
|
|
|
height += 30 |
|
|
|
newHeight += 30 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if height >= 88.0 { |
|
|
|
if newHeight >= 88.0 { |
|
|
|
// Set it to 95 expicity in case the row height is calculated be higher. |
|
|
|
// Set it to 95 expicity in case the row height is calculated be higher. |
|
|
|
height = 95.0 |
|
|
|
newHeight = 95.0 |
|
|
|
|
|
|
|
|
|
|
|
if let note = currentObject?.note, note.isEmpty { |
|
|
|
if let note = object?.note, note.isEmpty { |
|
|
|
height -= 30.0 |
|
|
|
newHeight -= 30.0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
height += mainTableView.intercellSpacing.height |
|
|
|
newHeight += mainTableView.intercellSpacing.height |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return newHeight |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setScrollViewConstraint() { |
|
|
|
|
|
|
|
var totalHeight: CGFloat = 0.0 |
|
|
|
|
|
|
|
let preferences = defaultPreferences |
|
|
|
|
|
|
|
|
|
|
|
totalHeight += height |
|
|
|
for cellIndex in 0 ..< preferences.count { |
|
|
|
|
|
|
|
let currentObject = TimezoneData.customObject(from: preferences[cellIndex]) |
|
|
|
|
|
|
|
let rowRect = mainTableView.rect(ofRow: cellIndex) |
|
|
|
|
|
|
|
totalHeight += getAdjustedRowHeight(for: currentObject, rowRect.size.height) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// This is for the Add Cell View case |
|
|
|
// This is for the Add Cell View case |
|
|
@ -828,17 +839,23 @@ class ParentPanelController: NSWindowController { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NSAnimationContext.runAnimationGroup({ context in |
|
|
|
NSAnimationContext.runAnimationGroup({ (context) in |
|
|
|
context.duration = 1 |
|
|
|
context.duration = 1 |
|
|
|
context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) |
|
|
|
context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) |
|
|
|
leftButton.animator().alphaValue = 0.0 |
|
|
|
leftButton.animator().alphaValue = 0.0 |
|
|
|
rightButton.animator().alphaValue = 0.0 |
|
|
|
rightButton.animator().alphaValue = 0.0 |
|
|
|
}) { |
|
|
|
}, completionHandler: { |
|
|
|
field.stringValue = title |
|
|
|
field.stringValue = title |
|
|
|
|
|
|
|
|
|
|
|
NSAnimationContext.runAnimationGroup({ context in |
|
|
|
NSAnimationContext.runAnimationGroup({ (context) in |
|
|
|
context.duration = 1 |
|
|
|
context.duration = 1 |
|
|
|
context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) |
|
|
|
context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) |
|
|
|
|
|
|
|
self.runAnimationCompletionBlock(leftTitle, rightTitle) |
|
|
|
|
|
|
|
}, completionHandler: {}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func runAnimationCompletionBlock(_ leftButtonTitle: String, _ rightButtonTitle: String) { |
|
|
|
self.leftButton.animator().alphaValue = 1.0 |
|
|
|
self.leftButton.animator().alphaValue = 1.0 |
|
|
|
self.rightButton.animator().alphaValue = 1.0 |
|
|
|
self.rightButton.animator().alphaValue = 1.0 |
|
|
|
|
|
|
|
|
|
|
@ -858,11 +875,8 @@ class ParentPanelController: NSWindowController { |
|
|
|
self.rightButton.animator().attributedTitle = NSAttributedString(string: "Yes, sure", attributes: styleAttributes) |
|
|
|
self.rightButton.animator().attributedTitle = NSAttributedString(string: "Yes, sure", attributes: styleAttributes) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.leftButton.animator().attributedTitle = NSAttributedString(string: leftTitle, attributes: styleAttributes) |
|
|
|
self.leftButton.animator().attributedTitle = NSAttributedString(string: leftButtonTitle, attributes: styleAttributes) |
|
|
|
self.rightButton.animator().attributedTitle = NSAttributedString(string: rightTitle, attributes: styleAttributes) |
|
|
|
self.rightButton.animator().attributedTitle = NSAttributedString(string: rightButtonTitle, attributes: styleAttributes) |
|
|
|
|
|
|
|
|
|
|
|
}) {} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MARK: Date Picker + Slider |
|
|
|
// MARK: Date Picker + Slider |
|
|
|