Revision: 28359
http://sourceforge.net/p/bibdesk/svn/28359
Author: hofman
Date: 2023-09-20 09:30:18 +0000 (Wed, 20 Sep 2023)
Log Message:
-----------
no need to invalidate cached dates for conditions, as parameters cannot be
changed when the condition is in use
Modified Paths:
--------------
trunk/bibdesk/BDSKCondition.m
Modified: trunk/bibdesk/BDSKCondition.m
===================================================================
--- trunk/bibdesk/BDSKCondition.m 2023-09-18 23:22:47 UTC (rev 28358)
+++ trunk/bibdesk/BDSKCondition.m 2023-09-20 09:30:18 UTC (rev 28359)
@@ -51,8 +51,8 @@
@interface BDSKCondition ()
- (BOOL)item:(BibItem *)item isContainedInGroupForField:(NSString *)field;
-- (void)invalidateCachedDates;
-- (void)getCachedDatesIfNeeded;
+- (void)getCachedDates;
+- (void)startCacheTimer;
@end
@implementation BDSKCondition
@@ -220,7 +220,8 @@
return YES; // empty condition matches anything
if ([self isDateCondition]) {
- [self getCachedDatesIfNeeded];
+ if (cachedStartDate == nil && cachedEndDate == nil && group)
+ [self getCachedDates];
NSDate *date = nil;
if ([key isEqualToString:BDSKDateAddedString])
@@ -394,11 +395,8 @@
- (void)setKey:(NSString *)newKey {
// we never want the key to be nil. It is set to nil sometimes by the
binding mechanism
if (key != newKey) {
- BOOL wasDateCondition = [self isDateCondition];
[key release];
key = [(newKey ?: @"") copy];
- if ([self isDateCondition] != wasDateCondition)
- [self invalidateCachedDates]; // remove the cached date and stop
the timer
}
}
@@ -524,64 +522,8 @@
}
}
-#pragma mark | count (linked files/URLs)
+#pragma mark Other
-#pragma mark | dates
-
-- (void)setDateComparison:(BDSKDateComparison)newComparison {
- if (dateComparison != newComparison) {
- dateComparison = newComparison;
- [self invalidateCachedDates];
- }
-}
-
-- (void)setNumberValue:(NSInteger)newNumber {
- if (numberValue != newNumber) {
- numberValue = newNumber;
- [self invalidateCachedDates];
- }
-}
-
-- (void)setAndNumberValue:(NSInteger)newNumber {
- if (andNumberValue != newNumber) {
- andNumberValue = newNumber;
- [self invalidateCachedDates];
- }
-}
-
-- (void)setPeriodValue:(BDSKPeriod)newPeriod {
- if (periodValue != newPeriod) {
- periodValue = newPeriod;
- [self invalidateCachedDates];
- }
-}
-
-- (NSDate *)dateValue {
- return [[dateValue retain] autorelease];
-}
-
-- (void)setDateValue:(NSDate *)newDate {
- if (dateValue != newDate) {
- [dateValue release];
- dateValue = [newDate retain];
- [self invalidateCachedDates];
- }
-}
-
-- (NSDate *)toDateValue {
- return [[toDateValue retain] autorelease];
-}
-
-- (void)setToDateValue:(NSDate *)newDate {
- if (toDateValue != newDate) {
- [toDateValue release];
- toDateValue = [newDate retain];
- [self invalidateCachedDates];
- }
-}
-
-#pragma mark Other
-
- (BOOL)isDateCondition {
return [key fieldType] == BDSKDateField;
}
@@ -643,8 +585,12 @@
- (void)setGroup:(id<BDSKSmartGroup>)newGroup {
if (group != newGroup) {
group = newGroup;
- if ([self isDateCondition])
- [self invalidateCachedDates];
+ if ([self isDateCondition] && group == nil) {
+ [cacheTimer invalidate];
+ BDSKDESTROY(cacheTimer);
+ BDSKDESTROY(cachedStartDate);
+ BDSKDESTROY(cachedEndDate);
+ }
}
}
@@ -719,13 +665,6 @@
}
}
-- (void)invalidateCachedDates {
- [cacheTimer invalidate];
- BDSKDESTROY(cacheTimer);
- BDSKDESTROY(cachedStartDate);
- BDSKDESTROY(cachedEndDate);
-}
-
static BOOL differentDates(NSDate *date1, NSDate *date2) {
if (date1 == nil)
return date2 != nil;
@@ -752,34 +691,31 @@
changed = YES;
}
- NSDate *fireDate = [[NSDate date] startOfPeriod:periodValue byAdding:1
atHour:0 minute:0 second:1];
[cacheTimer invalidate];
BDSKDESTROY(cacheTimer);
- cacheTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.0
target:self selector:@selector(refreshCachedDates:) userInfo:NULL repeats:NO];
- [[NSRunLoop currentRunLoop] addTimer:cacheTimer
forMode:NSDefaultRunLoopMode];
+ [self startCacheTimer];
- if (changed && group) {
+ if (changed && group)
[[NSNotificationCenter defaultCenter]
postNotificationName:BDSKFilterChangedNotification object:group];
- }
}
-- (void)getCachedDatesIfNeeded {
- if ([self isDateCondition] == NO || group == nil || cachedStartDate ||
cachedEndDate)
- return;
-
+- (void)startCacheTimer {
+ // we fire 1 second past midnight after the end of the current period,
because the condition changes at midnight
+ NSDate *fireDate = [[NSDate date] startOfPeriod:periodValue byAdding:1
atHour:0 minute:0 second:1];
+ cacheTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.0
target:self selector:@selector(refreshCachedDates:) userInfo:NULL repeats:NO];
+ [[NSRunLoop currentRunLoop] addTimer:cacheTimer
forMode:NSDefaultRunLoopMode];
+}
+
+- (void)getCachedDates {
NSDate *startDate = nil;
NSDate *endDate = nil;
[self getStartDate:&startDate endDate:&endDate];
- if (dateComparison < BDSKDate && (startDate || endDate)) {
- // we fire 1 second past midnight after the end of the current period,
because the condition changes at midnight
- NSDate *fireDate = [[NSDate date] startOfPeriod:periodValue byAdding:1
atHour:0 minute:0 second:1];
- cacheTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.0
target:self selector:@selector(refreshCachedDates:) userInfo:NULL repeats:NO];
- [[NSRunLoop currentRunLoop] addTimer:cacheTimer
forMode:NSDefaultRunLoopMode];
- }
-
cachedStartDate = [startDate retain];
cachedEndDate = [endDate retain];
+
+ if (dateComparison < BDSKDate && (startDate || endDate))
+ [self startCacheTimer];
}
@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit