From 7b82ef7d91a60e862fde692570e3d0409d523c36 Mon Sep 17 00:00:00 2001 From: James Stout Date: Sat, 6 Mar 2021 09:19:38 +0800 Subject: [PATCH] when clicking sort column header, alternate btwn ASC and DESC --- .../MainViewControllers/SPCustomQuery.m | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/Source/Controllers/MainViewControllers/SPCustomQuery.m b/Source/Controllers/MainViewControllers/SPCustomQuery.m index 3e1fa9f16..aaa44306b 100644 --- a/Source/Controllers/MainViewControllers/SPCustomQuery.m +++ b/Source/Controllers/MainViewControllers/SPCustomQuery.m @@ -107,6 +107,8 @@ - (void)queryFavoritesHaveBeenUpdated:(NSNotification *)notification; - (void)historyItemsHaveBeenUpdated:(NSNotification *)notification; - (void)helpWindowClosedByUser:(NSNotification *)notification; +@property (readwrite, strong) NSMutableDictionary *sortCount; + @end @implementation SPCustomQuery @@ -114,6 +116,7 @@ @implementation SPCustomQuery @synthesize runAllButton; @synthesize textViewWasChanged; @synthesize bracketHighlighter; +@synthesize sortCount; #pragma mark IBAction methods @@ -171,8 +174,8 @@ - (IBAction)runAllQueries:(id)sender // Re-init sort order isDesc = NO; sortColumn = nil; - - + [sortCount removeAllObjects]; + // Retrieve the custom query string and split it into separate SQL queries queryParser = [[SPSQLParser alloc] initWithString:[textView string]]; [queryParser setDelimiterSupport:YES]; @@ -211,6 +214,7 @@ - (IBAction)runSelectedQueries:(id)sender // Re-init sort order isDesc = NO; sortColumn = nil; + [sortCount removeAllObjects]; // If the current selection is a single caret position, run the current query. @@ -2255,16 +2259,33 @@ - (void)tableView:(NSTableView*)tableView didClickTableColumn:(NSTableColumn *)t // Sets column order as tri-state descending, ascending, no sort, descending, ascending etc. order if the same // header is clicked several times + // JCS - i dont think this is tri-state - i don't see a no sort option. + // so re-wrote this as desc or asc. if (sortField && [[tableColumn identifier] integerValue] == [sortField integerValue]) { BOOL invert = NO; if (modifierFlags & NSEventModifierFlagShift) { invert = YES; } - - // this is the same as saying (isDesc && !invert) || (!isDesc && invert) - if (isDesc == invert) { - isDesc = !isDesc; + + NSNumber *count = [sortCount objectForKey:sortField]; + + if(count == nil){ + count = @(0); } + + count = @([count intValue] + 1); + + [sortCount setObject:count forKey:sortField]; + + if(((count.integerValue % 2) != 0)){ + isDesc = (invert == NO) ? YES : NO; + SPLog(@"it's odd, set to desc, unless modifier key pressed. isDesc = %hhd", isDesc); + } + else{ + isDesc = (invert == NO) ? NO : YES; + SPLog(@"it's even, set to asc, unless modifier key pressed. isDesc = %hhd", isDesc); + } + } else { // When the column is not sorted, allow to sort in reverse order using Shift+click if (modifierFlags & NSEventModifierFlagShift) { @@ -3265,6 +3286,8 @@ - (instancetype)init tableRowsSelectable = YES; selectionIndexToRestore = nil; selectionViewportToRestore = NSZeroRect; + + sortCount = [[NSMutableDictionary alloc] init]; // init tableView's data source resultData = [[SPDataStorage alloc] init];