@@ -144,6 +144,7 @@ - (id)init
144144 selectionToRestore = nil ;
145145 selectionViewportToRestore = NSZeroRect ;
146146 filtersToRestore = nil ;
147+ activeFilterToRestore = SPTableContentFilterSourceNone;
147148 tableRowsSelectable = YES ;
148149 isFirstChangeInView = YES ;
149150
@@ -477,9 +478,6 @@ - (void) setTableDetails:(NSDictionary *)tableDetails
477478#ifndef SP_CODA
478479 // Remove existing columns from the filter table
479480 [filterTableController setColumns: nil ];
480- // TODO code smell
481- // ...but keep it, if the rule filter is the active one
482- if (activeFilter != SPTableContentFilterSourceRuleFilter) activeFilter = SPTableContentFilterSourceNone;
483481#endif
484482
485483 // 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
639637 [filterControllerInstance setColumns: dataColumns];
640638 // Restore preserved filter settings if appropriate and valid
641639 [filterControllerInstance restoreSerializedFilters: filtersToRestore];
642- // if we did restore some filters, set filtering enabled
643- if (![filterControllerInstance isEmpty ] ) {
640+ // 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)
641+ if (showFilterRuleEditor ) {
644642 [self setRuleEditorVisible: YES animate: NO ];
645643 [toggleRuleFilterButton setState: NSOnState ];
646644 }
647645 else {
648- [self setRuleEditorVisible: NO animate: NO ]; // immediately hide the filter editor when switching tables
646+ [self setRuleEditorVisible: NO animate: NO ];
649647 [toggleRuleFilterButton setState: NSOffState ];
650648 }
651649 [filterControllerInstance setEnabled: enableInteraction];
652650 [toggleRuleFilterButton setEnabled: enableInteraction];
651+ // restore the filter to the previously choosen one for the table
652+ activeFilter = activeFilterToRestore;
653653
654654 // Restore page number if limiting is set
655655 if ([prefs boolForKey: SPLimitResults]) contentPage = pageToRestore;
@@ -915,8 +915,8 @@ - (void) loadTableValues
915915 // Filter task came from filter table
916916 else if (activeFilter == SPTableContentFilterSourceTableFilter) {
917917 [[filterTableController onMainThread ] setFilterError: [mySQLConnection lastErrorID ]
918- message: [mySQLConnection lastErrorMessage ]
919- sqlstate: [mySQLConnection lastSqlstate ]];
918+ message: [mySQLConnection lastErrorMessage ]
919+ sqlstate: [mySQLConnection lastSqlstate ]];
920920 }
921921 }
922922#endif
@@ -1239,22 +1239,25 @@ - (IBAction)filterTable:(id)sender
12391239
12401240#ifndef SP_CODA
12411241
1242+ BOOL resetPaging = NO ; // if filtering was triggered by pressing the "Filter" button, reset to page 1
1243+
12421244 // If the filter table is being used - the advanced filter - switch type
12431245 if (sender == filterTableController) {
12441246 activeFilter = SPTableContentFilterSourceTableFilter;
1247+ resetPaging = YES ;
12451248 }
1246-
12471249 // If a string was supplied, use a custom query from that URL scheme
12481250 else if ([sender isKindOfClass: [NSString class ]] && [(NSString *)sender length ]) {
12491251 if (schemeFilter) SPClear (schemeFilter);
12501252 schemeFilter = [sender retain ];
12511253 activeFilter = SPTableContentFilterSourceURLScheme;
1254+ resetPaging = YES ;
12521255 }
1253-
12541256 // If a button other than the pagination buttons was used, set the active filter type to
12551257 // the standard filter field.
1256- else if (!senderIsPaginationButton ) {
1258+ else if (sender == filterControllerInstance ) {
12571259 activeFilter = SPTableContentFilterSourceRuleFilter;
1260+ resetPaging = YES ;
12581261 }
12591262#endif
12601263
@@ -1280,16 +1283,17 @@ - (IBAction)filterTable:(id)sender
12801283
12811284 // Select the correct pagination value.
12821285 // If the filter button was used, or if pagination is disabled, reset to page one
1283- if (!senderIsPaginationButton && ([sender isKindOfClass: [ NSButton class ]] || [sender isKindOfClass: [ NSTextField class ]] || ![prefs boolForKey: SPLimitResults] || [paginationPageField integerValue ] <= 0 ))
1286+ if (resetPaging || ![prefs boolForKey: SPLimitResults] || [paginationPageField integerValue ] <= 0 ) {
12841287 contentPage = 1 ;
1285-
1288+ }
12861289 // If the current page is out of bounds, move it within bounds
1287- else if (([paginationPageField integerValue ] - 1 ) * [prefs integerForKey: SPLimitResultsValue] >= maxNumRows)
1288- contentPage = ceilf ((CGFloat)maxNumRows / [prefs floatForKey: SPLimitResultsValue]);
1289-
1290+ else if (([paginationPageField integerValue ] - 1 ) * [prefs integerForKey: SPLimitResultsValue] >= maxNumRows) {
1291+ contentPage = ceilf ((CGFloat) maxNumRows / [prefs floatForKey: SPLimitResultsValue]);
1292+ }
12901293 // Otherwise, use the pagination value
1291- else
1294+ else {
12921295 contentPage = [paginationPageField integerValue ];
1296+ }
12931297
12941298 if ([self tableFilterString ]) {
12951299 taskString = NSLocalizedString(@" Filtering table..." , @" Filtering table task description" );
@@ -1332,7 +1336,12 @@ - (void)filterTableTask
13321336
13331337- (IBAction )toggleRuleEditorVisible:(id )sender
13341338{
1335- [self setRuleEditorVisible: !showFilterRuleEditor animate: YES ];
1339+ BOOL shouldShow = !showFilterRuleEditor;
1340+ [self setRuleEditorVisible: shouldShow animate: YES ];
1341+ // if this was the active filter before, it no longer can be the active filter when it is hidden
1342+ if (activeFilter == SPTableContentFilterSourceRuleFilter && !shouldShow) {
1343+ activeFilter = SPTableContentFilterSourceNone;
1344+ }
13361345}
13371346
13381347- (void )setRuleEditorVisible:(BOOL )show animate:(BOOL )animate
@@ -2387,17 +2396,19 @@ - (void)clickLinkArrowTask:(SPTextAndLinkCell *)theArrowCell
23872396 SPMainQSync (^{
23882397 [filterControllerInstance restoreSerializedFilters: filterSettings];
23892398 [self setRuleEditorVisible: YES animate: YES ];
2399+ activeFilter = SPTableContentFilterSourceRuleFilter;
23902400 });
23912401 tableFilterRequired = YES ;
23922402 }
23932403 else {
23942404 SPMainQSync (^{
23952405 [self setFiltersToRestore: filterSettings];
2396-
2406+ [ self setActiveFilterToRestore: SPTableContentFilterSourceRuleFilter];
23972407 // Attempt to switch to the target table
23982408 if (![tablesListInstance selectItemWithName: [refDictionary objectForKey: @" table" ]]) {
23992409 NSBeep ();
24002410 [self setFiltersToRestore: nil ];
2411+ [self setActiveFilterToRestore: SPTableContentFilterSourceNone];
24012412 }
24022413 });
24032414 }
@@ -3388,6 +3399,7 @@ - (void) storeCurrentDetailsForRestoration
33883399 [self setSelectionToRestore: [self selectionDetailsAllowingIndexSelection: YES ]];
33893400 [self setViewportToRestore: [self viewport ]];
33903401 [self setFiltersToRestore: [self filterSettings ]];
3402+ [self setActiveFilterToRestore: activeFilter];
33913403}
33923404
33933405/* *
@@ -3400,6 +3412,7 @@ - (void) clearDetailsToRestore
34003412 [self setSelectionToRestore: nil ];
34013413 [self setViewportToRestore: NSZeroRect ];
34023414 [self setFiltersToRestore: nil ];
3415+ [self setActiveFilterToRestore: SPTableContentFilterSourceNone];
34033416}
34043417
34053418- (NSData *) filterTableData
@@ -3412,6 +3425,16 @@ - (void)setFilterTableData:(NSData *)arcData;
34123425 [filterTableController setFilterTableData: arcData];
34133426}
34143427
3428+ - (SPTableContentFilterSource)activeFilter
3429+ {
3430+ return activeFilter;
3431+ }
3432+
3433+ - (void )setActiveFilterToRestore:(SPTableContentFilterSource)filter
3434+ {
3435+ activeFilterToRestore = filter;
3436+ }
3437+
34153438#pragma mark -
34163439#pragma mark Table drawing and editing
34173440
@@ -3469,12 +3492,16 @@ - (void)updateFilterRuleEditorSize:(CGFloat)requestedHeight animate:(BOOL)animat
34693492
34703493- (void )filterRuleEditorPreferredSizeChanged:(NSNotification *)notification
34713494{
3472- [self updateFilterRuleEditorSize: [filterControllerInstance preferredHeight ] animate: YES ];
3495+ if (showFilterRuleEditor) {
3496+ [self updateFilterRuleEditorSize: [filterControllerInstance preferredHeight ] animate: YES ];
3497+ }
34733498}
34743499
34753500- (void )contentViewSizeChanged:(NSNotification *)notification
34763501{
3477- [self updateFilterRuleEditorSize: [filterControllerInstance preferredHeight ] animate: NO ];
3502+ if (showFilterRuleEditor) {
3503+ [self updateFilterRuleEditorSize: [filterControllerInstance preferredHeight ] animate: NO ];
3504+ }
34783505}
34793506
34803507/* *
0 commit comments