Browse Source

Migrating Notes Popover..

pull/92/head
Abhishek 4 years ago
parent
commit
37fd903205
  1. 27
      Clocker/Panel/Data Layer/TimezoneData.swift
  2. 29
      Clocker/Panel/Notes Popover/NotesPopover.swift
  3. 45
      Clocker/Panel/Notes Popover/NotesPopover.xib

27
Clocker/Panel/Data Layer/TimezoneData.swift

@ -27,12 +27,18 @@ class TimezoneData: NSObject, NSCoding {
} }
enum TimezoneOverride: Int { enum TimezoneOverride: Int {
case globalFormat = 0
case twelveHourFormat case twelveHourFormat
case twentyFourFormat case twentyFourFormat
case globalFormat case twelveHourWithSeconds
case twentyHourWithSeconds
case twelveHourPrecedingZero
case twelveHourPrecedingZeroSeconds
case twelveHourWithoutSuffix
case twelveHourWithoutSuffixAndSeconds
} }
let values = [ static let values = [
NSNumber(integerLiteral: 0): DateFormat.twelveHour, NSNumber(integerLiteral: 0): DateFormat.twelveHour,
NSNumber(integerLiteral: 1): DateFormat.twelveHourWithSeconds, NSNumber(integerLiteral: 1): DateFormat.twelveHourWithSeconds,
NSNumber(integerLiteral: 2): DateFormat.twentyFourHour, NSNumber(integerLiteral: 2): DateFormat.twentyFourHour,
@ -237,12 +243,16 @@ class TimezoneData: NSObject, NSCoding {
let newTimezone = TimezoneData(with: oldModel) let newTimezone = TimezoneData(with: oldModel)
newModels.append(newTimezone) newModels.append(newTimezone)
} else if let newModel = old as? TimezoneData { } else if let newModel = old as? TimezoneData {
if UserDefaults.standard.object(forKey: "migrateOverrideFormat") == nil {
print("Resetting Global Format")
newModel.setShouldOverrideGlobalTimeFormat(0)
}
newModels.append(newModel) newModels.append(newModel)
} }
} }
if UserDefaults.standard.object(forKey: "shouldOverrideSecondsFormatBug") == nil { if UserDefaults.standard.object(forKey: "migrateOverrideFormat") == nil {
UserDefaults.standard.set("YES", forKey: "shouldOverrideSecondsFormatBug") UserDefaults.standard.set("YES", forKey: "migrateOverrideFormat")
} }
// Do the serialization // Do the serialization
@ -317,7 +327,7 @@ class TimezoneData: NSObject, NSCoding {
func setShouldOverrideGlobalTimeFormat(_ shouldOverride: Int) { func setShouldOverrideGlobalTimeFormat(_ shouldOverride: Int) {
if shouldOverride == 0 { if shouldOverride == 0 {
overrideFormat = .twelveHourFormat overrideFormat = .globalFormat
} else if shouldOverride == 1 { } else if shouldOverride == 1 {
overrideFormat = .twentyFourFormat overrideFormat = .twentyFourFormat
} else { } else {
@ -351,8 +361,7 @@ class TimezoneData: NSObject, NSCoding {
func timezoneFormat() -> String { func timezoneFormat() -> String {
let chosenDefault = DataStore.shared().timezoneFormat() let chosenDefault = DataStore.shared().timezoneFormat()
return TimezoneData.values[chosenDefault] ?? DateFormat.twelveHour
return values[chosenDefault] ?? DateFormat.twelveHour
// var timeFormat = DateFormat.twentyFourHour // var timeFormat = DateFormat.twentyFourHour
// //
@ -380,11 +389,11 @@ class TimezoneData: NSObject, NSCoding {
func shouldShowSeconds() -> Bool { func shouldShowSeconds() -> Bool {
if overrideFormat == .globalFormat { if overrideFormat == .globalFormat {
let currentFormat = DataStore.shared().timezoneFormat() let currentFormat = DataStore.shared().timezoneFormat()
let formatInString = values[currentFormat] ?? DateFormat.twelveHour let formatInString = TimezoneData.values[currentFormat] ?? DateFormat.twelveHour
return formatInString.contains("ss") return formatInString.contains("ss")
} }
let formatInString = values[NSNumber(integerLiteral: overrideFormat.rawValue)] ?? DateFormat.twelveHour let formatInString = TimezoneData.values[NSNumber(integerLiteral: overrideFormat.rawValue)] ?? DateFormat.twelveHour
return formatInString.contains("ss") return formatInString.contains("ss")
} }

29
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -34,7 +34,7 @@ class NotesPopover: NSViewController {
@IBOutlet var remindersButton: NSButton! @IBOutlet var remindersButton: NSButton!
@IBOutlet var timeFormatControl: NSSegmentedControl! @IBOutlet var timeFormatControl: NSPopUpButton!
@IBOutlet var notesTextView: TextViewWithPlaceholder! @IBOutlet var notesTextView: TextViewWithPlaceholder!
@ -66,6 +66,29 @@ class NotesPopover: NSViewController {
alertPopupButton.addItems(withTitles: titles) alertPopupButton.addItems(withTitles: titles)
alertPopupButton.selectItem(at: 1) alertPopupButton.selectItem(at: 1)
// Set up time control
let chosenFormat: Int = dataObject?.overrideFormat.rawValue ?? 0
let supportedTimeFormats = ["Respect Global Preference",
"h:mm a (7:08 PM)",
"HH:mm (19:08)",
"-- With Seconds --",
"h:mm:ss a (7:08:09 PM)",
"HH:mm:ss (19:08:09)",
"-- 12 Hour with Preceding 0 --",
"hh:mm a (07:08 PM)",
"hh:mm:ss a (07:08:09 PM)",
"-- 12 Hour w/o AM/PM --",
"hh:mm (07:08)",
"hh:mm:ss (07:08:09)"]
timeFormatControl.removeAllItems()
timeFormatControl.addItems(withTitles: supportedTimeFormats)
timeFormatControl.item(at: 3)?.isEnabled = false
timeFormatControl.item(at: 6)?.isEnabled = false
timeFormatControl.item(at: 9)?.isEnabled = false
timeFormatControl.autoenablesItems = false
timeFormatControl.selectItem(at: chosenFormat)
// Set Accessibility Identifiers for UI tests // Set Accessibility Identifiers for UI tests
customLabel.setAccessibilityIdentifier("CustomLabel") customLabel.setAccessibilityIdentifier("CustomLabel")
saveButton.setAccessibilityIdentifier("SaveButton") saveButton.setAccessibilityIdentifier("SaveButton")
@ -212,7 +235,7 @@ class NotesPopover: NSViewController {
updateLabel() updateLabel()
dataObject?.note = notesTextView.string dataObject?.note = notesTextView.string
dataObject?.setShouldOverrideGlobalTimeFormat(timeFormatControl.selectedSegment) dataObject?.setShouldOverrideGlobalTimeFormat(timeFormatControl.indexOfSelectedItem)
insertTimezoneInDefaultPreferences() insertTimezoneInDefaultPreferences()
if setReminderCheckbox.state == .on { if setReminderCheckbox.state == .on {
@ -452,7 +475,7 @@ extension NotesPopover {
private func updateTimeFormat() { private func updateTimeFormat() {
if let overrideFormat = dataObject?.overrideFormat.rawValue { if let overrideFormat = dataObject?.overrideFormat.rawValue {
timeFormatControl.setSelected(true, forSegment: overrideFormat) timeFormatControl.selectItem(at: overrideFormat)
} }
} }

45
Clocker/Panel/Notes Popover/NotesPopover.xib

@ -17,14 +17,14 @@
<outlet property="saveButton" destination="qgx-Yf-bP8" id="fAe-wb-MiA"/> <outlet property="saveButton" destination="qgx-Yf-bP8" id="fAe-wb-MiA"/>
<outlet property="scriptExecutionIndicator" destination="zMZ-FX-ZI4" id="me0-n8-iEV"/> <outlet property="scriptExecutionIndicator" destination="zMZ-FX-ZI4" id="me0-n8-iEV"/>
<outlet property="setReminderCheckbox" destination="4qH-g6-DPb" id="ToC-jq-tfe"/> <outlet property="setReminderCheckbox" destination="4qH-g6-DPb" id="ToC-jq-tfe"/>
<outlet property="timeFormatControl" destination="seL-7y-MOc" id="mfh-v1-uhs"/> <outlet property="timeFormatControl" destination="wso-Nb-JHM" id="jjg-6C-iOG"/>
<outlet property="timeFormatTweakingView" destination="Rxa-0J-YeW" id="1hi-JL-Xcx"/> <outlet property="timeFormatTweakingView" destination="Rxa-0J-YeW" id="1hi-JL-Xcx"/>
<outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/> <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections> </connections>
</customObject> </customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/> <customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView wantsLayer="YES" misplaced="YES" id="Hz6-mo-xeY"> <customView wantsLayer="YES" id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="300" height="297"/> <rect key="frame" x="0.0" y="0.0" width="300" height="297"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews> <subviews>
@ -185,22 +185,22 @@
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Rxa-0J-YeW"> <customView translatesAutoresizingMaskIntoConstraints="NO" id="Rxa-0J-YeW">
<rect key="frame" x="0.0" y="77" width="300" height="60"/> <rect key="frame" x="0.0" y="77" width="300" height="60"/>
<subviews> <subviews>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="seL-7y-MOc"> <popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="wso-Nb-JHM">
<rect key="frame" x="18" y="11" width="265" height="24"/> <rect key="frame" x="17" y="6" width="267" height="25"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="Low-Q8-K5h"> <popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="8qk-GL-4hW" id="fxb-yT-8r3">
<font key="font" size="12" name="Avenir-Book"/> <behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<segments> <font key="font" metaFont="menu"/>
<segment label="12-hour" width="86"/> <menu key="menu" id="cw0-En-hDs">
<segment label="24-hour" width="86" tag="1"/> <items>
<segment label="Global" width="85" selected="YES"/> <menuItem title="Item 1" state="on" id="8qk-GL-4hW"/>
</segments> <menuItem title="Item 2" id="99r-M6-BPe"/>
</segmentedCell> <menuItem title="Item 3" id="Ehy-gO-9z5"/>
<connections> </items>
<action selector="customizeTimeFormat:" target="-2" id="JhC-hY-JhY"/> </menu>
</connections> </popUpButtonCell>
</segmentedControl> </popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Wqz-cF-lhm"> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Wqz-cF-lhm">
<rect key="frame" x="18" y="36" width="274" height="16"/> <rect key="frame" x="18" y="38" width="274" height="16"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="left" title="Timezone Format" id="JnF-g8-GLM"> <textFieldCell key="cell" lineBreakMode="clipping" alignment="left" title="Timezone Format" id="JnF-g8-GLM">
<font key="font" usesAppearanceFont="YES"/> <font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
@ -209,13 +209,12 @@
</textField> </textField>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstItem="Wqz-cF-lhm" firstAttribute="leading" secondItem="seL-7y-MOc" secondAttribute="leading" id="19h-CF-DBW"/> <constraint firstItem="wso-Nb-JHM" firstAttribute="leading" secondItem="Rxa-0J-YeW" secondAttribute="leading" constant="20" symbolic="YES" id="0Mg-3s-Gt9"/>
<constraint firstItem="Wqz-cF-lhm" firstAttribute="leading" secondItem="wso-Nb-JHM" secondAttribute="leading" id="6Nz-Pg-AjP"/>
<constraint firstAttribute="height" constant="60" id="6tP-1d-ufg"/> <constraint firstAttribute="height" constant="60" id="6tP-1d-ufg"/>
<constraint firstItem="seL-7y-MOc" firstAttribute="leading" secondItem="Rxa-0J-YeW" secondAttribute="leading" constant="20" id="9RJ-d9-2KM"/>
<constraint firstAttribute="trailing" secondItem="Wqz-cF-lhm" secondAttribute="trailing" constant="10" id="G6S-5h-12V"/> <constraint firstAttribute="trailing" secondItem="Wqz-cF-lhm" secondAttribute="trailing" constant="10" id="G6S-5h-12V"/>
<constraint firstAttribute="trailing" secondItem="seL-7y-MOc" secondAttribute="trailing" constant="19" id="Ysa-Xl-mPa"/> <constraint firstAttribute="trailing" secondItem="wso-Nb-JHM" secondAttribute="trailing" constant="20" symbolic="YES" id="a7H-jo-4dw"/>
<constraint firstAttribute="bottom" secondItem="seL-7y-MOc" secondAttribute="bottom" constant="12" id="cjQ-Yb-gta"/> <constraint firstAttribute="bottom" secondItem="wso-Nb-JHM" secondAttribute="bottom" constant="10" id="uXh-0D-6O0"/>
<constraint firstItem="seL-7y-MOc" firstAttribute="top" secondItem="Wqz-cF-lhm" secondAttribute="bottom" constant="2" id="eNO-El-GVH"/>
<constraint firstAttribute="width" constant="300" id="xeM-Ue-etB"/> <constraint firstAttribute="width" constant="300" id="xeM-Ue-etB"/>
</constraints> </constraints>
</customView> </customView>

Loading…
Cancel
Save