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

29
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -34,7 +34,7 @@ class NotesPopover: NSViewController {
@IBOutlet var remindersButton: NSButton!
@IBOutlet var timeFormatControl: NSSegmentedControl!
@IBOutlet var timeFormatControl: NSPopUpButton!
@IBOutlet var notesTextView: TextViewWithPlaceholder!
@ -66,6 +66,29 @@ class NotesPopover: NSViewController {
alertPopupButton.addItems(withTitles: titles)
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
customLabel.setAccessibilityIdentifier("CustomLabel")
saveButton.setAccessibilityIdentifier("SaveButton")
@ -212,7 +235,7 @@ class NotesPopover: NSViewController {
updateLabel()
dataObject?.note = notesTextView.string
dataObject?.setShouldOverrideGlobalTimeFormat(timeFormatControl.selectedSegment)
dataObject?.setShouldOverrideGlobalTimeFormat(timeFormatControl.indexOfSelectedItem)
insertTimezoneInDefaultPreferences()
if setReminderCheckbox.state == .on {
@ -452,7 +475,7 @@ extension NotesPopover {
private func updateTimeFormat() {
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="scriptExecutionIndicator" destination="zMZ-FX-ZI4" id="me0-n8-iEV"/>
<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="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<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"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
@ -185,22 +185,22 @@
<customView translatesAutoresizingMaskIntoConstraints="NO" id="Rxa-0J-YeW">
<rect key="frame" x="0.0" y="77" width="300" height="60"/>
<subviews>
<segmentedControl verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="seL-7y-MOc">
<rect key="frame" x="18" y="11" width="265" height="24"/>
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="Low-Q8-K5h">
<font key="font" size="12" name="Avenir-Book"/>
<segments>
<segment label="12-hour" width="86"/>
<segment label="24-hour" width="86" tag="1"/>
<segment label="Global" width="85" selected="YES"/>
</segments>
</segmentedCell>
<connections>
<action selector="customizeTimeFormat:" target="-2" id="JhC-hY-JhY"/>
</connections>
</segmentedControl>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Wqz-cF-lhm">
<rect key="frame" x="18" y="36" width="274" height="16"/>
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="wso-Nb-JHM">
<rect key="frame" x="17" y="6" width="267" height="25"/>
<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">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<menu key="menu" id="cw0-En-hDs">
<items>
<menuItem title="Item 1" state="on" id="8qk-GL-4hW"/>
<menuItem title="Item 2" id="99r-M6-BPe"/>
<menuItem title="Item 3" id="Ehy-gO-9z5"/>
</items>
</menu>
</popUpButtonCell>
</popUpButton>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Wqz-cF-lhm">
<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">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
@ -209,13 +209,12 @@
</textField>
</subviews>
<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 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="seL-7y-MOc" secondAttribute="trailing" constant="19" id="Ysa-Xl-mPa"/>
<constraint firstAttribute="bottom" secondItem="seL-7y-MOc" secondAttribute="bottom" constant="12" id="cjQ-Yb-gta"/>
<constraint firstItem="seL-7y-MOc" firstAttribute="top" secondItem="Wqz-cF-lhm" secondAttribute="bottom" constant="2" id="eNO-El-GVH"/>
<constraint firstAttribute="trailing" secondItem="wso-Nb-JHM" secondAttribute="trailing" constant="20" symbolic="YES" id="a7H-jo-4dw"/>
<constraint firstAttribute="bottom" secondItem="wso-Nb-JHM" secondAttribute="bottom" constant="10" id="uXh-0D-6O0"/>
<constraint firstAttribute="width" constant="300" id="xeM-Ue-etB"/>
</constraints>
</customView>

Loading…
Cancel
Save