Permalink
Browse files

#63: Behaviour changes

* Filter editor visibility state is now preserved when switching tables
* The previously active filter is reenabled when returning to a table
  • Loading branch information...
dmoagx committed May 12, 2018
1 parent 1ac52c3 commit 375faa0de3189a380cc03b8f70df232ec8df7346
Showing with 56 additions and 21 deletions.
  1. +5 −0 Source/SPHistoryController.m
  2. +3 −0 Source/SPTableContent.h
  3. +48 −21 Source/SPTableContent.m
@@ -251,6 +251,7 @@ - (void) updateHistoryEntries
NSRect contentViewport = [[tableContentInstance onMainThread] viewport];
NSDictionary *contentFilter = [[tableContentInstance onMainThread] filterSettings];
NSData *filterTableData = [[tableContentInstance onMainThread] filterTableData];
SPTableContentFilterSource activeFilter = [[tableContentInstance onMainThread] activeFilter];
if (!theDatabase) return;
// If a table is selected, save state information
@@ -261,6 +262,7 @@ - (void) updateHistoryEntries
[NSNumber numberWithUnsignedInteger:contentPageNumber], @"page",
[NSValue valueWithRect:contentViewport], @"viewport",
[NSNumber numberWithBool:contentSortColIsAsc], @"sortIsAsc",
@(activeFilter), @"activeFilter",
nil];
if (contentSortCol) [contentState setObject:contentSortCol forKey:@"sortCol"];
if (contentSelectedRows) [contentState setObject:contentSelectedRows forKey:@"selection"];
@@ -329,6 +331,7 @@ - (void) updateHistoryEntries
[NSNumber numberWithBool:contentSortColIsAsc], @"contentSortColIsAsc",
[NSNumber numberWithInteger:contentPageNumber], @"contentPageNumber",
[NSValue valueWithRect:contentViewport], @"contentViewport",
@(activeFilter), @"activeFilter",
nil];
if (contentSortCol) [newEntry setObject:contentSortCol forKey:@"contentSortCol"];
if (contentSelectedRows) [newEntry setObject:contentSelectedRows forKey:@"contentSelection"];
@@ -387,6 +390,7 @@ - (void) loadEntryTaskWithPosition:(NSNumber *)positionNumber
[tableContentInstance setSelectionToRestore:[historyEntry objectForKey:@"contentSelection"]];
[tableContentInstance setViewportToRestore:[[historyEntry objectForKey:@"contentViewport"] rectValue]];
[tableContentInstance setFiltersToRestore:[historyEntry objectForKey:@"contentFilterV2"]];
[tableContentInstance setActiveFilterToRestore:(SPTableContentFilterSource)[[historyEntry objectForKey:@"activeFilter"] integerValue]];
// If the database, table, and view are the same and content - just trigger a table reload (filters)
if (
@@ -503,6 +507,7 @@ - (void) restoreViewStates
[tableContentInstance setSelectionToRestore:[contentState objectForKey:@"selection"]];
[tableContentInstance setViewportToRestore:[[contentState objectForKey:@"viewport"] rectValue]];
[tableContentInstance setFiltersToRestore:[contentState objectForKey:@"filterV2"]];
[tableContentInstance setActiveFilterToRestore:(SPTableContentFilterSource)[[contentState objectForKey:@"activeFilter"] integerValue]];
}
#pragma mark -
@@ -126,6 +126,7 @@ typedef NS_ENUM(NSInteger, SPTableContentFilterSource) {
#ifndef SP_CODA
SPTableContentFilterSource activeFilter;
SPTableContentFilterSource activeFilterToRestore;
NSString *schemeFilter;
#endif
@@ -266,6 +267,8 @@ typedef NS_ENUM(NSInteger, SPTableContentFilterSource) {
- (void)setFiltersToRestore:(NSDictionary *)filterSettings;
- (void)storeCurrentDetailsForRestoration;
- (void)clearDetailsToRestore;
- (void)setActiveFilterToRestore:(SPTableContentFilterSource)filter;
- (SPTableContentFilterSource)activeFilter;
- (void)setFilterTableData:(NSData *)arcData;
- (NSData *)filterTableData;
@@ -144,6 +144,7 @@ - (id)init
selectionToRestore = nil;
selectionViewportToRestore = NSZeroRect;
filtersToRestore = nil;
activeFilterToRestore = SPTableContentFilterSourceNone;
tableRowsSelectable = YES;
isFirstChangeInView = YES;
@@ -477,9 +478,6 @@ - (void) setTableDetails:(NSDictionary *)tableDetails
#ifndef SP_CODA
// Remove existing columns from the filter table
[filterTableController setColumns:nil];
// TODO code smell
//...but keep it, if the rule filter is the active one
if(activeFilter != SPTableContentFilterSourceRuleFilter) activeFilter = SPTableContentFilterSourceNone;
#endif
// Retrieve the field names and types for this table from the data cache. This is used when requesting all data as part
@@ -639,17 +637,19 @@ - (void) setTableDetails:(NSDictionary *)tableDetails
[filterControllerInstance setColumns:dataColumns];
// Restore preserved filter settings if appropriate and valid
[filterControllerInstance restoreSerializedFilters:filtersToRestore];
//if we did restore some filters, set filtering enabled
if(![filterControllerInstance isEmpty]) {
// hide/show the rule filter editor, based on its previous state (so that it says visible when switching tables, if someone has enabled it and vice versa)
if(showFilterRuleEditor) {
[self setRuleEditorVisible:YES animate:NO];
[toggleRuleFilterButton setState:NSOnState];
}
else {
[self setRuleEditorVisible:NO animate:NO]; //immediately hide the filter editor when switching tables
[self setRuleEditorVisible:NO animate:NO];
[toggleRuleFilterButton setState:NSOffState];
}
[filterControllerInstance setEnabled:enableInteraction];
[toggleRuleFilterButton setEnabled:enableInteraction];
// restore the filter to the previously choosen one for the table
activeFilter = activeFilterToRestore;
// Restore page number if limiting is set
if ([prefs boolForKey:SPLimitResults]) contentPage = pageToRestore;
@@ -915,8 +915,8 @@ - (void) loadTableValues
// Filter task came from filter table
else if(activeFilter == SPTableContentFilterSourceTableFilter) {
[[filterTableController onMainThread] setFilterError:[mySQLConnection lastErrorID]
message:[mySQLConnection lastErrorMessage]
sqlstate:[mySQLConnection lastSqlstate]];
message:[mySQLConnection lastErrorMessage]
sqlstate:[mySQLConnection lastSqlstate]];
}
}
#endif
@@ -1239,22 +1239,25 @@ - (IBAction)filterTable:(id)sender
#ifndef SP_CODA
BOOL resetPaging = NO; // if filtering was triggered by pressing the "Filter" button, reset to page 1
// If the filter table is being used - the advanced filter - switch type
if(sender == filterTableController) {
activeFilter = SPTableContentFilterSourceTableFilter;
resetPaging = YES;
}
// If a string was supplied, use a custom query from that URL scheme
else if([sender isKindOfClass:[NSString class]] && [(NSString *)sender length]) {
if(schemeFilter) SPClear(schemeFilter);
schemeFilter = [sender retain];
activeFilter = SPTableContentFilterSourceURLScheme;
resetPaging = YES;
}
// If a button other than the pagination buttons was used, set the active filter type to
// the standard filter field.
else if (!senderIsPaginationButton) {
else if (sender == filterControllerInstance) {
activeFilter = SPTableContentFilterSourceRuleFilter;
resetPaging = YES;
}
#endif
@@ -1280,16 +1283,17 @@ - (IBAction)filterTable:(id)sender
// Select the correct pagination value.
// If the filter button was used, or if pagination is disabled, reset to page one
if (!senderIsPaginationButton && ([sender isKindOfClass:[NSButton class]] || [sender isKindOfClass:[NSTextField class]] || ![prefs boolForKey:SPLimitResults] || [paginationPageField integerValue] <= 0))
if (resetPaging || ![prefs boolForKey:SPLimitResults] || [paginationPageField integerValue] <= 0) {
contentPage = 1;
}
// If the current page is out of bounds, move it within bounds
else if (([paginationPageField integerValue] - 1) * [prefs integerForKey:SPLimitResultsValue] >= maxNumRows)
contentPage = ceilf((CGFloat)maxNumRows / [prefs floatForKey:SPLimitResultsValue]);
else if (([paginationPageField integerValue] - 1) * [prefs integerForKey:SPLimitResultsValue] >= maxNumRows) {
contentPage = ceilf((CGFloat) maxNumRows / [prefs floatForKey:SPLimitResultsValue]);
}
// Otherwise, use the pagination value
else
else {
contentPage = [paginationPageField integerValue];
}
if ([self tableFilterString]) {
taskString = NSLocalizedString(@"Filtering table...", @"Filtering table task description");
@@ -1332,7 +1336,12 @@ - (void)filterTableTask
- (IBAction)toggleRuleEditorVisible:(id)sender
{
[self setRuleEditorVisible:!showFilterRuleEditor animate:YES];
BOOL shouldShow = !showFilterRuleEditor;
[self setRuleEditorVisible:shouldShow animate:YES];
// if this was the active filter before, it no longer can be the active filter when it is hidden
if(activeFilter == SPTableContentFilterSourceRuleFilter && !shouldShow) {
activeFilter = SPTableContentFilterSourceNone;
}
}
- (void)setRuleEditorVisible:(BOOL)show animate:(BOOL)animate
@@ -2387,17 +2396,19 @@ - (void)clickLinkArrowTask:(SPTextAndLinkCell *)theArrowCell
SPMainQSync(^{
[filterControllerInstance restoreSerializedFilters:filterSettings];
[self setRuleEditorVisible:YES animate:YES];
activeFilter = SPTableContentFilterSourceRuleFilter;
});
tableFilterRequired = YES;
}
else {
SPMainQSync(^{
[self setFiltersToRestore:filterSettings];
[self setActiveFilterToRestore:SPTableContentFilterSourceRuleFilter];
// Attempt to switch to the target table
if (![tablesListInstance selectItemWithName:[refDictionary objectForKey:@"table"]]) {
NSBeep();
[self setFiltersToRestore:nil];
[self setActiveFilterToRestore:SPTableContentFilterSourceNone];
}
});
}
@@ -3388,6 +3399,7 @@ - (void) storeCurrentDetailsForRestoration
[self setSelectionToRestore:[self selectionDetailsAllowingIndexSelection:YES]];
[self setViewportToRestore:[self viewport]];
[self setFiltersToRestore:[self filterSettings]];
[self setActiveFilterToRestore:activeFilter];
}
/**
@@ -3400,6 +3412,7 @@ - (void) clearDetailsToRestore
[self setSelectionToRestore:nil];
[self setViewportToRestore:NSZeroRect];
[self setFiltersToRestore:nil];
[self setActiveFilterToRestore:SPTableContentFilterSourceNone];
}
- (NSData*) filterTableData
@@ -3412,6 +3425,16 @@ - (void)setFilterTableData:(NSData *)arcData;
[filterTableController setFilterTableData:arcData];
}
- (SPTableContentFilterSource)activeFilter
{
return activeFilter;
}
- (void)setActiveFilterToRestore:(SPTableContentFilterSource)filter
{
activeFilterToRestore = filter;
}
#pragma mark -
#pragma mark Table drawing and editing
@@ -3469,12 +3492,16 @@ - (void)updateFilterRuleEditorSize:(CGFloat)requestedHeight animate:(BOOL)animat
- (void)filterRuleEditorPreferredSizeChanged:(NSNotification *)notification
{
[self updateFilterRuleEditorSize:[filterControllerInstance preferredHeight] animate:YES];
if(showFilterRuleEditor) {
[self updateFilterRuleEditorSize:[filterControllerInstance preferredHeight] animate:YES];
}
}
- (void)contentViewSizeChanged:(NSNotification *)notification
{
[self updateFilterRuleEditorSize:[filterControllerInstance preferredHeight] animate:NO];
if(showFilterRuleEditor) {
[self updateFilterRuleEditorSize:[filterControllerInstance preferredHeight] animate:NO];
}
}
/**

0 comments on commit 375faa0

Please sign in to comment.