diff --git a/Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate b/Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate index fa8478f..891288c 100644 Binary files a/Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate and b/Clocker.xcodeproj/project.xcworkspace/xcuserdata/abhishekbanthia.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Clocker/Preferences/CLPreferencesViewController.m b/Clocker/Preferences/CLPreferencesViewController.m index bba1f45..4bc7d2a 100644 --- a/Clocker/Preferences/CLPreferencesViewController.m +++ b/Clocker/Preferences/CLPreferencesViewController.m @@ -694,56 +694,61 @@ NSString *const CLTryAgainMessage = @"Try again, maybe?"; -(void)tableView:(NSTableView *)tableView didClickTableColumn:(NSTableColumn *)tableColumn { - static NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | NSForcedOrderingSearch | NSWidthInsensitiveSearch; - [self.selectedTimeZones sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2){ + if (tableView == self.timezoneTableView) + { + static NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch | NSNumericSearch | NSForcedOrderingSearch | NSWidthInsensitiveSearch; - CLTimezoneData *object1 = [CLTimezoneData getCustomObject:obj1]; - CLTimezoneData *object2 = [CLTimezoneData getCustomObject:obj2]; + [self.selectedTimeZones sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2){ + + CLTimezoneData *object1 = [CLTimezoneData getCustomObject:obj1]; + CLTimezoneData *object2 = [CLTimezoneData getCustomObject:obj2]; + + NSString *formattedAddress1, *formattedAddress2; + + if ([tableColumn.identifier isEqualToString:CLPreferencesTimezoneNameIdentifier]) { + formattedAddress1 = object1.formattedAddress.length > 0 ? object1.formattedAddress : object1.timezoneID; + formattedAddress2 = object2.formattedAddress.length > 0 ? object2.formattedAddress : object2.timezoneID; + } + else + { + formattedAddress1 = object1.customLabel.length > 0 ? object1.customLabel : object1.formattedAddress.length > 0 ? object1.formattedAddress : object1.timezoneID; + formattedAddress2 = object2.customLabel.length > 0 ? object2.customLabel : object2.formattedAddress.length > 0 ? object2.formattedAddress : object2.timezoneID; + } + + NSRange string1Range = NSMakeRange(0, [formattedAddress1 length]); + + if (!self.arePlacesSortedInAscendingOrder) { + return [formattedAddress1 compare:formattedAddress2 + options:comparisonOptions + range:string1Range + locale:[NSLocale localeWithLocaleIdentifier:@"en_us"]]; + + } + else + { + return -[formattedAddress1 compare:formattedAddress2 + options:comparisonOptions + range:string1Range + locale:[NSLocale localeWithLocaleIdentifier:@"en_us"]]; + } + + + }]; - NSString *formattedAddress1, *formattedAddress2; + self.arePlacesSortedInAscendingOrder ? [self.timezoneTableView setIndicatorImage:[NSImage imageNamed:@"NSDescendingSortIndicator"] inTableColumn:tableColumn] : [self.timezoneTableView setIndicatorImage:[NSImage imageNamed:@"NSAscendingSortIndicator"] inTableColumn:tableColumn]; - if ([tableColumn.identifier isEqualToString:CLPreferencesTimezoneNameIdentifier]) { - formattedAddress1 = object1.formattedAddress.length > 0 ? object1.formattedAddress : object1.timezoneID; - formattedAddress2 = object2.formattedAddress.length > 0 ? object2.formattedAddress : object2.timezoneID; - } - else - { - formattedAddress1 = object1.customLabel.length > 0 ? object1.customLabel : object1.formattedAddress.length > 0 ? object1.formattedAddress : object1.timezoneID; - formattedAddress2 = object2.customLabel.length > 0 ? object2.customLabel : object2.formattedAddress.length > 0 ? object2.formattedAddress : object2.timezoneID; - } + self.arePlacesSortedInAscendingOrder = !self.arePlacesSortedInAscendingOrder; - NSRange string1Range = NSMakeRange(0, [formattedAddress1 length]); + NSMutableArray *newDefaults = [[NSMutableArray alloc] initWithArray:self.selectedTimeZones]; - if (!self.arePlacesSortedInAscendingOrder) { - return [formattedAddress1 compare:formattedAddress2 - options:comparisonOptions - range:string1Range - locale:[NSLocale localeWithLocaleIdentifier:@"en_us"]]; - - } - else - { - return -[formattedAddress1 compare:formattedAddress2 - options:comparisonOptions - range:string1Range - locale:[NSLocale localeWithLocaleIdentifier:@"en_us"]]; - } + [[NSUserDefaults standardUserDefaults] setObject:newDefaults forKey:CLDefaultPreferenceKey]; + [self.timezoneTableView reloadData]; - }]; - - self.arePlacesSortedInAscendingOrder ? [self.timezoneTableView setIndicatorImage:[NSImage imageNamed:@"NSDescendingSortIndicator"] inTableColumn:tableColumn] : [self.timezoneTableView setIndicatorImage:[NSImage imageNamed:@"NSAscendingSortIndicator"] inTableColumn:tableColumn]; - - self.arePlacesSortedInAscendingOrder = !self.arePlacesSortedInAscendingOrder; - - NSMutableArray *newDefaults = [[NSMutableArray alloc] initWithArray:self.selectedTimeZones]; - - [[NSUserDefaults standardUserDefaults] setObject:newDefaults forKey:CLDefaultPreferenceKey]; - - [self.timezoneTableView reloadData]; - - [self refreshMainTableview]; + [self refreshMainTableview]; + + } } #pragma mark Other Methods