diff options
author | Max <dmoagx@users.noreply.github.com> | 2018-05-11 00:38:35 +0200 |
---|---|---|
committer | Max <dmoagx@users.noreply.github.com> | 2018-05-11 00:38:35 +0200 |
commit | 1ac52c38f1b819fa28610c74661a5fd4dbab21f9 (patch) | |
tree | 65e669d3e812b7804b4db4bc16dcc35f971db67e /Source | |
parent | 1318bce4cd58d8aaa31c6c386c6b709713e1dde9 (diff) | |
download | sequelpro-1ac52c38f1b819fa28610c74661a5fd4dbab21f9.tar.gz sequelpro-1ac52c38f1b819fa28610c74661a5fd4dbab21f9.tar.bz2 sequelpro-1ac52c38f1b819fa28610c74661a5fd4dbab21f9.zip |
#63: Move some UI around and add proper icon
Clarify some variable names
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPAppController.m | 2 | ||||
-rw-r--r-- | Source/SPTableContent.h | 2 | ||||
-rw-r--r-- | Source/SPTableContent.m | 57 | ||||
-rw-r--r-- | Source/SPTableContentFilterController.h | 6 | ||||
-rw-r--r-- | Source/SPTableContentFilterController.m | 25 |
5 files changed, 64 insertions, 28 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m index 2e62725f..c9523bc7 100644 --- a/Source/SPAppController.m +++ b/Source/SPAppController.m @@ -2368,7 +2368,7 @@ */ - (BOOL)application:(NSApplication *)sender delegateHandlesKey:(NSString *)key { - NSLog(@"Not yet implemented."); + NSLog(@"Not yet implemented: %@", key); return NO; } diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h index a670c69a..bd14cbdf 100644 --- a/Source/SPTableContent.h +++ b/Source/SPTableContent.h @@ -69,7 +69,6 @@ typedef NS_ENUM(NSInteger, SPTableContentFilterSource) { IBOutlet SPCopyTable *tableContentView; - IBOutlet NSButton *filterButton; IBOutlet NSButton *toggleRuleFilterButton; IBOutlet id addButton; IBOutlet id duplicateButton; @@ -170,7 +169,6 @@ typedef NS_ENUM(NSInteger, SPTableContentFilterSource) { } #ifdef SP_CODA /* glue */ -@property (assign) id filterButton; @property (assign) NSButton* addButton; @property (assign) NSButton* duplicateButton; @property (assign) NSButton* removeButton; diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 40133b71..0bc3cc26 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -92,7 +92,6 @@ static void *TableContentKVOContext = &TableContentKVOContext; #ifdef SP_CODA @synthesize addButton; @synthesize duplicateButton; -@synthesize filterButton; @synthesize paginationNextButton; @synthesize paginationPageField; @synthesize paginationPreviousButton; @@ -360,7 +359,6 @@ static void *TableContentKVOContext = &TableContentKVOContext; // Empty and disable filter options [self setRuleEditorVisible:NO animate:NO]; - [filterButton setEnabled:NO]; [toggleRuleFilterButton setEnabled:NO]; [toggleRuleFilterButton setState:NSOffState]; [filterControllerInstance setColumns:nil]; @@ -650,7 +648,7 @@ static void *TableContentKVOContext = &TableContentKVOContext; [self setRuleEditorVisible:NO animate:NO]; //immediately hide the filter editor when switching tables [toggleRuleFilterButton setState:NSOffState]; } - [filterButton setEnabled:enableInteraction]; + [filterControllerInstance setEnabled:enableInteraction]; [toggleRuleFilterButton setEnabled:enableInteraction]; // Restore page number if limiting is set @@ -1304,11 +1302,15 @@ static void *TableContentKVOContext = &TableContentKVOContext; [tableDocumentInstance startTaskWithDescription:taskString]; if ([NSThread isMainThread]) { - [NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent filter table task", tableDocumentInstance) target:self selector:@selector(filterTableTask) object:nil]; + [NSThread detachNewThreadWithName:SPCtxt(@"SPTableContent filter table task", tableDocumentInstance) + target:self + selector:@selector(filterTableTask) + object:nil]; } else { [self filterTableTask]; } } + - (void)filterTableTask { @autoreleasepool { @@ -1349,7 +1351,6 @@ static void *TableContentKVOContext = &TableContentKVOContext; [self updateFilterRuleEditorSize:0.0 animate:animate]; } showFilterRuleEditor = show; - [filterButton setHidden:!show]; } - (void)setUsedQuery:(NSString *)query @@ -3416,39 +3417,49 @@ static void *TableContentKVOContext = &TableContentKVOContext; - (void)updateFilterRuleEditorSize:(CGFloat)requestedHeight animate:(BOOL)animate { - NSRect contentViewRect = [contentAreaContainer frame]; - CGFloat availableHeight = contentViewRect.size.height; + NSRect contentAreaRect = [contentAreaContainer frame]; + CGFloat availableHeight = contentAreaRect.size.height; + + NSRect ruleEditorRect = [[[filterControllerInstance view] enclosingScrollView] frame]; + + //adjust for the UI elements below the rule editor, but only if the view height should not be 0 (ie. hidden) + CGFloat containerRequestedHeight = requestedHeight ? requestedHeight + ruleEditorRect.origin.y : 0; + //the rule editor can ask for about one-third of the available space before we have it use it's scrollbar - CGFloat givenHeight = MIN(requestedHeight + 1,(availableHeight / 3)); // +1 is the SPFillView at the bottom - + CGFloat topContainerGivenHeight = MIN(containerRequestedHeight,(availableHeight / 3)); + // abort if the size didn't really change - NSRect ruleEditorRect = [filterRuleEditorContainer frame]; - if(givenHeight == ruleEditorRect.size.height) return; + NSRect topContainerRect = [filterRuleEditorContainer frame]; + if(topContainerGivenHeight == topContainerRect.size.height) return; - CGFloat newTableContentHeight = availableHeight - givenHeight; + CGFloat newBottomContainerHeight = availableHeight - topContainerGivenHeight; - NSRect tableContentRect = [tableContentContainer frame]; - tableContentRect.size.height = newTableContentHeight; + NSRect bottomContainerRect = [tableContentContainer frame]; + bottomContainerRect.size.height = newBottomContainerHeight; + topContainerRect.origin.y = newBottomContainerHeight; + topContainerRect.size.height = topContainerGivenHeight; - ruleEditorRect.origin.y = newTableContentHeight; - ruleEditorRect.size.height = givenHeight; + // this one should be inferable from the IB layout IMHO, but the OS gets it wrong + ruleEditorRect.size.height = topContainerGivenHeight - ruleEditorRect.origin.y; if(animate) { [NSAnimationContext beginGrouping]; - [[tableContentContainer animator] setFrame:tableContentRect]; - [[filterRuleEditorContainer animator] setFrame:ruleEditorRect]; + [[tableContentContainer animator] setFrame:bottomContainerRect]; + [[filterRuleEditorContainer animator] setFrame:topContainerRect]; + [[[[filterControllerInstance view] enclosingScrollView] animator] setFrame:ruleEditorRect]; [NSAnimationContext endGrouping]; } else { - [tableContentContainer setFrameSize:tableContentRect.size]; - [filterRuleEditorContainer setFrame:ruleEditorRect]; + [tableContentContainer setFrameSize:bottomContainerRect.size]; + [filterRuleEditorContainer setFrame:topContainerRect]; + [[[filterControllerInstance view] enclosingScrollView] setFrame:ruleEditorRect]; } //disable rubberband scrolling as long as there is nothing to scroll if(scrollViewHasRubberbandScrolling) { NSScrollView *filterControllerScroller = [[filterControllerInstance view] enclosingScrollView]; - if (givenHeight > requestedHeight) { // note that givenHeight + 1 == requestedHeight in order to avoid scroll + if (ruleEditorRect.size.height >= requestedHeight) { [filterControllerScroller setVerticalScrollElasticity:NSScrollElasticityNone]; } else { [filterControllerScroller setVerticalScrollElasticity:NSScrollElasticityAutomatic]; @@ -3586,7 +3597,7 @@ static void *TableContentKVOContext = &TableContentKVOContext; [removeButton setEnabled:NO]; [duplicateButton setEnabled:NO]; [reloadButton setEnabled:NO]; - [filterButton setEnabled:NO]; + [filterControllerInstance setEnabled:NO]; [toggleRuleFilterButton setEnabled:NO]; tableRowsSelectable = NO; [paginationPreviousButton setEnabled:NO]; @@ -3622,7 +3633,7 @@ static void *TableContentKVOContext = &TableContentKVOContext; } } - [filterButton setEnabled:(!![selectedTable length])]; + [filterControllerInstance setEnabled:(!![selectedTable length])]; [toggleRuleFilterButton setEnabled:(!![selectedTable length])]; tableRowsSelectable = YES; } diff --git a/Source/SPTableContentFilterController.h b/Source/SPTableContentFilterController.h index 32aeec00..3fe5e8ea 100644 --- a/Source/SPTableContentFilterController.h +++ b/Source/SPTableContentFilterController.h @@ -41,6 +41,7 @@ NSString * const SPTableContentFilterHeightChangedNotification; IBOutlet SPDatabaseDocument *tableDocumentInstance; IBOutlet SPTablesList *tablesListInstance; IBOutlet NSView *tableContentViewBelow; + IBOutlet NSButton *filterButton; NSMutableArray *columns; NSMutableDictionary *contentFilters; @@ -54,6 +55,8 @@ NSString * const SPTableContentFilterHeightChangedNotification; id target; SEL action; + + BOOL enabled; } /** @@ -154,4 +157,7 @@ NSString * const SPTableContentFilterHeightChangedNotification; @property (assign, nonatomic) id target; @property (assign, nonatomic) SEL action; +- (BOOL)isEnabled; +- (void)setEnabled:(BOOL)enabled; + @end diff --git a/Source/SPTableContentFilterController.m b/Source/SPTableContentFilterController.m index c8efa952..a2d6b2d2 100644 --- a/Source/SPTableContentFilterController.m +++ b/Source/SPTableContentFilterController.m @@ -186,6 +186,7 @@ static void _addIfNotNil(NSMutableArray *array, id toAdd); - (BOOL)_focusOnFieldInSubtree:(NSDictionary *)dict; - (void)_resize; - (void)openContentFilterManagerForFilterType:(NSString *)filterType; +- (IBAction)filterTable:(id)sender; @end @@ -305,6 +306,9 @@ static void _addIfNotNil(NSMutableArray *array, id toAdd); // make the rule editor reload the criteria [filterRuleEditor reloadCriteria]; + + // disable UI if no criteria exist + [self setEnabled:([columns count] != 0)]; } - (NSInteger)ruleEditor:(NSRuleEditor *)editor numberOfChildrenForCriterion:(nullable id)criterion withRowType:(NSRuleEditorRowType)rowType @@ -472,10 +476,15 @@ static void _addIfNotNil(NSMutableArray *array, id toAdd); // if the action was caused by pressing return or enter, trigger filtering NSEvent *event = [NSApp currentEvent]; if(event && [event type] == NSKeyDown && ([event keyCode] == 36 || [event keyCode] == 76)) { - if(target && action) [target performSelector:action withObject:self]; + [self filterTable:nil]; } } +- (IBAction)filterTable:(id)sender +{ + if(target && action) [target performSelector:action withObject:self]; +} + - (void)_resize { // The situation with the sizing is a bit f'ed up: @@ -740,6 +749,18 @@ static void _addIfNotNil(NSMutableArray *array, id toAdd); return filterRuleEditor; } +- (BOOL)isEnabled +{ + return enabled; +} + +- (void)setEnabled:(BOOL)_enabled +{ + enabled = _enabled; + [filterButton setEnabled:_enabled]; + [filterRuleEditor setEnabled:_enabled]; +} + - (NSString *)sqlWhereExpressionWithBinary:(BOOL)isBINARY error:(NSError **)err { NSMutableString *filterString = [[NSMutableString alloc] init]; @@ -926,7 +947,7 @@ void _addIfNotNil(NSMutableArray *array, id toAdd) NSString *curFilterType = [[op settings] objectForKey:@"filterType"]; NSString *serFilterType = [serialized objectForKey:SerFilterExprType]; // this is optional if(serFilterType && ![curFilterType isEqualToString:serFilterType]) { - SPLog(@"mistmatch in filter types for operator %@: current=%@, serialized=%@",op,curFilterType,serFilterType); + SPLog(@"mismatch in filter types for operator %@: current=%@, serialized=%@",op,curFilterType,serFilterType); goto fail; } |