From a3547cb24d00ec53cb6d41536152ec38954aed5b Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 17 Jun 2020 10:56:40 -0500 Subject: [PATCH] Allowing users to disable place in menubar! --- Clocker/Menu Bar/StatusContainerView.swift | 4 +-- Clocker/Menu Bar/StatusItemView.swift | 8 ++--- .../Data Layer/TimezoneDataOperations.swift | 33 ++++++++++++++----- .../Appearance/AppearanceViewController.swift | 9 ----- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Clocker/Menu Bar/StatusContainerView.swift b/Clocker/Menu Bar/StatusContainerView.swift index 9aa1fd3..63bbb27 100644 --- a/Clocker/Menu Bar/StatusContainerView.swift +++ b/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) } diff --git a/Clocker/Menu Bar/StatusItemView.swift b/Clocker/Menu Bar/StatusItemView.swift index d3f14f4..56a4efb 100644 --- a/Clocker/Menu Bar/StatusItemView.swift +++ b/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) { diff --git a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift b/Clocker/Panel/Data Layer/TimezoneDataOperations.swift index 6fa3466..ee70ba7 100644 --- a/Clocker/Panel/Data Layer/TimezoneDataOperations.swift +++ b/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))") diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index 3ee4a57..afa8eac 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/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() }