Revision: 28338
http://sourceforge.net/p/bibdesk/svn/28338
Author: hofman
Date: 2023-09-13 14:15:40 +0000 (Wed, 13 Sep 2023)
Log Message:
-----------
Don't set default comparison and value in setKey: for condition. Instead, set
them in controller when not undoing/redoing and type changes. Otherwise KVO and
binding gets confused, because primitiveKey did not trigger KVO for key.
Modified Paths:
--------------
trunk/bibdesk/BDSKCondition+Scripting.m
trunk/bibdesk/BDSKCondition.h
trunk/bibdesk/BDSKCondition.m
trunk/bibdesk/BDSKConditionController.m
Modified: trunk/bibdesk/BDSKCondition+Scripting.m
===================================================================
--- trunk/bibdesk/BDSKCondition+Scripting.m 2023-09-13 08:57:00 UTC (rev
28337)
+++ trunk/bibdesk/BDSKCondition+Scripting.m 2023-09-13 14:15:40 UTC (rev
28338)
@@ -91,6 +91,7 @@
NSNumber *comparisonNumber = [properties
objectForKey:@"scriptingComparison"];
if (comparisonNumber == nil) {
+ [self setDefaultComparison];
} else if ([self isDateCondition]) {
switch ([comparisonNumber unsignedIntValue]) {
case BDSKScriptingToday: [self
setDateComparison:BDSKToday]; break;
@@ -157,6 +158,7 @@
if ([newValue isEqual:[NSNull null]])
newValue = nil;
if (newValue == nil) {
+ [self setDefaultValue];
} else if ([self isDateCondition]) {
if ([newValue isKindOfClass:[NSDictionary class]]) {
id value;
Modified: trunk/bibdesk/BDSKCondition.h
===================================================================
--- trunk/bibdesk/BDSKCondition.h 2023-09-13 08:57:00 UTC (rev 28337)
+++ trunk/bibdesk/BDSKCondition.h 2023-09-13 14:15:40 UTC (rev 28338)
@@ -127,8 +127,6 @@
@property (nonatomic, retain) NSString *value;
@property (nonatomic) NSInteger comparison;
-@property (nonatomic, retain) NSString *primitiveKey;
-
// String accessors
@property (nonatomic) BDSKStringComparison stringComparison;
@property (nonatomic, retain) NSString *stringValue;
Modified: trunk/bibdesk/BDSKCondition.m
===================================================================
--- trunk/bibdesk/BDSKCondition.m 2023-09-13 08:57:00 UTC (rev 28337)
+++ trunk/bibdesk/BDSKCondition.m 2023-09-13 14:15:40 UTC (rev 28338)
@@ -58,7 +58,7 @@
@implementation BDSKCondition
@synthesize stringComparison, attachmentComparison, countValue,
dateComparison, numberValue, andNumberValue, periodValue, group;
-@dynamic dictionaryValue, key, value, comparison, primitiveKey, stringValue,
dateValue, toDateValue, dateCondition, attachmentCondition;
+@dynamic dictionaryValue, key, value, comparison, stringValue, dateValue,
toDateValue, dateCondition, attachmentCondition;
+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
@@ -386,19 +386,6 @@
}
- (void)setKey:(NSString *)newKey {
- BDSKFieldType oldFieldType = [key fieldType];
- [self setPrimitiveKey:newKey];
- if (oldFieldType != [key fieldType]) {
- [self setDefaultComparison];
- [self setDefaultValue];
- }
-}
-
-- (NSString *)primitiveKey {
- return [[key retain] autorelease];
-}
-
-- (void)setPrimitiveKey:(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];
Modified: trunk/bibdesk/BDSKConditionController.m
===================================================================
--- trunk/bibdesk/BDSKConditionController.m 2023-09-13 08:57:00 UTC (rev
28337)
+++ trunk/bibdesk/BDSKConditionController.m 2023-09-13 14:15:40 UTC (rev
28338)
@@ -273,15 +273,22 @@
id oldValue = [change objectForKey:NSKeyValueChangeOldKey];
if (oldValue == [NSNull null])
oldValue = nil;
- if ([keyPath isEqualToString:@"primitiveKey"]){
+ if ([keyPath isEqualToString:@"key"]){
NSString *newValue = [change
objectForKey:NSKeyValueChangeNewKey];
+ if ((id)newValue == [NSNull null])
+ newValue = nil;
BDSKFieldType oldFieldType = [oldValue fieldType];
BDSKFieldType newFieldType = [newValue fieldType];
if(MIN(oldFieldType, BDSKStringField) != MIN(newFieldType,
BDSKStringField))
[self layoutComparisonControls];
- if(oldFieldType != newFieldType)
+ if(oldFieldType != newFieldType) {
[self layoutValueControls];
- [[undoManager prepareWithInvocationTarget:condition]
setPrimitiveKey:oldValue];
+ if ([undoManager isUndoing] == NO && [undoManager
isRedoing] == NO) {
+ [object setDefaultComparison];
+ [object setDefaultValue];
+ }
+ }
+ [[undoManager prepareWithInvocationTarget:condition]
setKey:oldValue];
} else if ([keyPath isEqualToString:@"dateComparison"]) {
[self layoutValueControls];
[[undoManager prepareWithInvocationTarget:condition]
setDateComparison:[oldValue integerValue]];
@@ -316,7 +323,7 @@
if (isObserving == NO) {
BDSKCondition *condition = [self condition];
if (condition) {
- [condition addObserver:self forKeyPath:@"primitiveKey"
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:&BDSKConditionControllerObservationContext];
+ [condition addObserver:self forKeyPath:@"key"
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:&BDSKConditionControllerObservationContext];
for (NSString *key in [NSArray arrayWithObjects:@"dateComparison",
@"attachmentComparison", @"stringComparison", @"stringValue", @"countValue",
@"numberValue", @"andNumberValue", @"periodValue", @"dateValue",
@"toDateValue", nil])
[condition addObserver:self forKeyPath:key options:
NSKeyValueObservingOptionOld
context:&BDSKConditionControllerObservationContext];
isObserving = YES;
@@ -327,7 +334,7 @@
- (void)stopObserving {
if (isObserving) {
BDSKCondition *condition = [self condition];
- for (NSString *key in [NSArray arrayWithObjects:@"primitiveKey",
@"dateComparison", @"attachmentComparison", @"stringComparison",
@"stringValue", @"countValue", @"numberValue", @"andNumberValue",
@"periodValue", @"dateValue", @"toDateValue", nil])
+ for (NSString *key in [NSArray arrayWithObjects:@"key",
@"dateComparison", @"attachmentComparison", @"stringComparison",
@"stringValue", @"countValue", @"numberValue", @"andNumberValue",
@"periodValue", @"dateValue", @"toDateValue", nil])
[condition removeObserver:self forKeyPath:key
context:&BDSKConditionControllerObservationContext];
isObserving = NO;
}
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