aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPHistoryController.m5
-rw-r--r--Source/SPTableContent.h3
-rw-r--r--Source/SPTableContent.m69
3 files changed, 56 insertions, 21 deletions
diff --git a/Source/SPHistoryController.m b/Source/SPHistoryController.m
index 8a0554fe..31db15ee 100644
--- a/Source/SPHistoryController.m
+++ b/Source/SPHistoryController.m
@@ -251,6 +251,7 @@
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 @@
[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 @@
[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 @@
[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 @@ abort_entry_load:
[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 -
diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h
index bd14cbdf..831950fb 100644
--- a/Source/SPTableContent.h
+++ b/Source/SPTableContent.h
@@ -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;
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 0bc3cc26..a5a1e5be 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -144,6 +144,7 @@ static void *TableContentKVOContext = &TableContentKVOContext;
selectionToRestore = nil;
selectionViewportToRestore = NSZeroRect;
filtersToRestore = nil;
+ activeFilterToRestore = SPTableContentFilterSourceNone;
tableRowsSelectable = YES;
isFirstChangeInView = YES;
@@ -477,9 +478,6 @@ static void *TableContentKVOContext = &TableContentKVOContext;
#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 @@ static void *TableContentKVOContext = &TableContentKVOContext;
[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 @@ static void *TableContentKVOContext = &TableContentKVOContext;
// 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 @@ static void *TableContentKVOContext = &TableContentKVOContext;
#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 @@ static void *TableContentKVOContext = &TableContentKVOContext;
// 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 @@ static void *TableContentKVOContext = &TableContentKVOContext;
- (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 @@ static void *TableContentKVOContext = &TableContentKVOContext;
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 @@ static void *TableContentKVOContext = &TableContentKVOContext;
[self setSelectionToRestore:[self selectionDetailsAllowingIndexSelection:YES]];
[self setViewportToRestore:[self viewport]];
[self setFiltersToRestore:[self filterSettings]];
+ [self setActiveFilterToRestore:activeFilter];
}
/**
@@ -3400,6 +3412,7 @@ static void *TableContentKVOContext = &TableContentKVOContext;
[self setSelectionToRestore:nil];
[self setViewportToRestore:NSZeroRect];
[self setFiltersToRestore:nil];
+ [self setActiveFilterToRestore:SPTableContentFilterSourceNone];
}
- (NSData*) filterTableData
@@ -3412,6 +3425,16 @@ static void *TableContentKVOContext = &TableContentKVOContext;
[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 @@ static void *TableContentKVOContext = &TableContentKVOContext;
- (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];
+ }
}
/**