Browse Source

Allowing users to disable place in menubar!

pull/92/head
Abhishek 5 years ago
parent
commit
a3547cb24d
  1. 4
      Clocker/Menu Bar/StatusContainerView.swift
  2. 8
      Clocker/Menu Bar/StatusItemView.swift
  3. 33
      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) { if let timezoneObject = TimezoneData.customObject(from: timezone) {
let precalculatedWidth = Double(compactWidth(for: timezoneObject)) let precalculatedWidth = Double(compactWidth(for: timezoneObject))
let operationObject = TimezoneDataOperations(with: 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 return result + calculatedSize.width + bufferWidth
} }
@ -115,7 +115,7 @@ class StatusContainerView: NSView {
private func bestWidth(for timezone: TimezoneData) -> Int { private func bestWidth(for timezone: TimezoneData) -> Int {
let operation = TimezoneDataOperations(with: timezone) 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) return Int(bestSize.width + bufferWidth)
} }

8
Clocker/Menu Bar/StatusItemView.swift

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

33
Clocker/Panel/Data Layer/TimezoneDataOperations.swift

@ -33,24 +33,41 @@ extension TimezoneDataOperations {
return dateFormatter.string(from: newDate) return dateFormatter.string(from: newDate)
} }
func compactMenuHeader() -> String { func compactMenuTitle() -> String {
var subtitle = CLEmptyString var subtitle = CLEmptyString
let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar() let shouldDayBeShown = DataStore.shared().shouldShowDayInMenubar()
let shouldLabelBeShownAlongWithTime = !DataStore.shared().shouldDisplay(.placeInMenubar)
if shouldDayBeShown { if shouldDayBeShown, shouldLabelBeShownAlongWithTime {
let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay) let substring = date(with: 0, displayType: CLDateDisplayType.menuDisplay)
subtitle.append(substring) subtitle.append(substring)
} }
let shouldDateBeShown = DataStore.shared().shouldShowDateInMenubar() let shouldDateBeShown = DataStore.shared().shouldShowDateInMenubar()
if shouldDateBeShown { if shouldDateBeShown, shouldLabelBeShownAlongWithTime {
let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone()) let date = Date().formatter(with: "MMM d", timeZone: dataObject.timezone())
if subtitle.isEmpty == false { subtitle.isEmpty ? subtitle.append("\(date)") : subtitle.append(" \(date)")
subtitle.append(" \(date)") }
} else {
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))") 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) let shouldDisplayCompact = DataStore.shared().shouldDisplay(.menubarCompactMode)
menubarMode.setSelected(true, forSegment: shouldDisplayCompact ? 0 : 1) menubarMode.setSelected(true, forSegment: shouldDisplayCompact ? 0 : 1)
updateMenubarControls(!shouldDisplayCompact)
} }
@IBOutlet var timeFormatLabel: NSTextField! @IBOutlet var timeFormatLabel: NSTextField!
@ -311,8 +310,6 @@ class AppearanceViewController: ParentViewController {
} }
@IBAction func menubarModeChanged(_ sender: NSSegmentedControl) { @IBAction func menubarModeChanged(_ sender: NSSegmentedControl) {
updateMenubarControls(sender.selectedSegment == 1)
guard let statusItem = (NSApplication.shared.delegate as? AppDelegate)?.statusItemForPanel() else { guard let statusItem = (NSApplication.shared.delegate as? AppDelegate)?.statusItemForPanel() else {
return 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) { @IBAction func fontSliderChanged(_: Any) {
previewPanelTableView.reloadData() previewPanelTableView.reloadData()
} }

Loading…
Cancel
Save