Browse Source

Allowing users to disable place in menubar!

pull/92/head
Abhishek 4 years ago
parent
commit
a3547cb24d
  1. 4
      Clocker/Menu Bar/StatusContainerView.swift
  2. 8
      Clocker/Menu Bar/StatusItemView.swift
  3. 31
      Clocker/Panel/Data Layer/TimezoneDataOperations.swift
  4. 9
      Clocker/Preferences/Appearance/AppearanceViewController.swift

4
Clocker/Menu Bar/StatusContainerView.swift

@ -77,7 +77,7 @@ class StatusContainerView: NSView {
if let timezoneObject = TimezoneData.customObject(from: timezone) {
let precalculatedWidth = Double(compactWidth(for: timezoneObject))
let operationObject = TimezoneDataOperations(with: timezoneObject)
let calculatedSize = compactModeTimeFont.size(operationObject.compactMenuHeader(), precalculatedWidth, attributes: timeAttributes)
let calculatedSize = compactModeTimeFont.size(operationObject.compactMenuSubtitle(), precalculatedWidth, attributes: timeAttributes)
return result + calculatedSize.width + bufferWidth
}
@ -115,7 +115,7 @@ class StatusContainerView: NSView {
private func bestWidth(for timezone: TimezoneData) -> Int {
let operation = TimezoneDataOperations(with: timezone)
let bestSize = compactModeTimeFont.size(operation.compactMenuHeader(), Double(compactWidth(for: timezone)), attributes: timeAttributes)
let bestSize = compactModeTimeFont.size(operation.compactMenuSubtitle(), Double(compactWidth(for: timezone)), attributes: timeAttributes)
return Int(bestSize.width + bufferWidth)
}

8
Clocker/Menu Bar/StatusItemView.swift

@ -82,13 +82,13 @@ class StatusItemView: NSView {
}
func updateTimeInMenubar() {
locationView.attributedStringValue = NSAttributedString(string: dataObject.formattedTimezoneLabel(), attributes: textFontAttributes)
timeView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuHeader(), attributes: timeAttributes)
locationView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuTitle(), attributes: textFontAttributes)
timeView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuSubtitle(), attributes: timeAttributes)
}
private func initialSetup() {
locationView.attributedStringValue = NSAttributedString(string: dataObject.formattedTimezoneLabel(), attributes: textFontAttributes)
timeView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuHeader(), attributes: timeAttributes)
locationView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuTitle(), attributes: textFontAttributes)
timeView.attributedStringValue = NSAttributedString(string: operationsObject.compactMenuSubtitle(), attributes: timeAttributes)
}
required init?(coder _: NSCoder) {

31
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -33,24 +33,41 @@ extension TimezoneDataOperations {
return dateFormatter.string(from: newDate)
}
func compactMenuHeader() -> String {
func compactMenuTitle() -> String {
var subtitle = CLEmptyString
let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar()
let shouldLabelBeShownAlongWithTime = !DataStore.shared().shouldDisplay(.placeInMenubar)
if shouldDayBeShown {
if shouldDayBeShown, shouldLabelBeShownAlongWithTime {
let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay)
subtitle.append(substring)
}
let shouldDateBeShown = DataStore.shared().shouldShowDateInMenubar()
if shouldDateBeShown {
if shouldDateBeShown, shouldLabelBeShownAlongWithTime {
let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone())
if subtitle.isEmpty == false {
subtitle.append(" \(date)")
} else {
subtitle.append("\(date)")
subtitle.isEmpty ? subtitle.append("\(date)") : subtitle.append(" \(date)")
}
return subtitle.isEmpty ? dataObject.formattedTimezoneLabel() : subtitle
}
func compactMenuSubtitle() -> String {
var subtitle = CLEmptyString
let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar()
let shouldLabelsNotBeShownAlongWithTime = DataStore.shared().shouldDisplay(.placeInMenubar)
if shouldDayBeShown, shouldLabelsNotBeShownAlongWithTime {
let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay)
subtitle.append(substring)
}
let shouldDateBeShown = DataStore.shared().shouldShowDateInMenubar()
if shouldDateBeShown, shouldLabelsNotBeShownAlongWithTime {
let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone())
subtitle.isEmpty ? subtitle.append("\(date)") : subtitle.append(" \(date)")
}
subtitle.isEmpty ? subtitle.append(time(with: 0)) : subtitle.append(" \(time(with: 0))")

9
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -102,7 +102,6 @@ class AppearanceViewController: ParentViewController {
let shouldDisplayCompact = DataStore.shared().shouldDisplay(.menubarCompactMode)
menubarMode.setSelected(true, forSegment: shouldDisplayCompact ? 0 : 1)
updateMenubarControls(!shouldDisplayCompact)
}
@IBOutlet var timeFormatLabel: NSTextField!
@ -311,8 +310,6 @@ class AppearanceViewController: ParentViewController {
}
@IBAction func menubarModeChanged(_ sender: NSSegmentedControl) {
updateMenubarControls(sender.selectedSegment == 1)
guard let statusItem = (NSApplication.shared.delegate as? AppDelegate)?.statusItemForPanel() else {
return
}
@ -326,12 +323,6 @@ class AppearanceViewController: ParentViewController {
}
}
// We don't support showing day or date in the menubar for compact mode yet.
// Disable those options to let the user know.
private func updateMenubarControls(_ isEnabled: Bool) {
[includePlaceNameControl].forEach { $0?.isEnabled = isEnabled }
}
@IBAction func fontSliderChanged(_: Any) {
previewPanelTableView.reloadData()
}

Loading…
Cancel
Save