Revision: 15059 http://sourceforge.net/p/skim-app/code/15059 Author: hofman Date: 2025-03-31 15:24:55 +0000 (Mon, 31 Mar 2025) Log Message: ----------- Don't override binding of fontName and fontSizein SKFontWell. Instead, ignore result of KVO while updating these bindings, to avoid resetting partially updated fonts.
Modified Paths: -------------- trunk/SKFontWell.h trunk/SKFontWell.m Modified: trunk/SKFontWell.h =================================================================== --- trunk/SKFontWell.h 2025-03-31 14:52:02 UTC (rev 15058) +++ trunk/SKFontWell.h 2025-03-31 15:24:55 UTC (rev 15059) @@ -43,8 +43,7 @@ @interface SKFontWell : NSButton { id target; SEL action; - - NSMutableDictionary *bindingInfo; + NSString *updatedBinding; } @property (nonatomic, getter=isActive) BOOL active; Modified: trunk/SKFontWell.m =================================================================== --- trunk/SKFontWell.m 2025-03-31 14:52:02 UTC (rev 15058) +++ trunk/SKFontWell.m 2025-03-31 15:24:55 UTC (rev 15059) @@ -56,10 +56,7 @@ #define ACTION_KEY @"action" #define TARGET_KEY @"target" -static char SKFontWellFontNameObservationContext; -static char SKFontWellFontSizeObservationContext; - @interface SKFontWell (SKPrivate) - (void)changeActive:(id)sender; - (void)fontChanged; @@ -99,7 +96,6 @@ [[self cell] setShowsStateBy:NSNoCellMask]; [super setAction:@selector(changeActive:)]; [super setTarget:self]; - bindingInfo = [[NSMutableDictionary alloc] init]; [self registerForDraggedTypes:@[SKNSFontPanelDescriptorsPboardType, SKNSFontPanelFamiliesPboardType, NSPasteboardTypeColor]]; } @@ -227,6 +223,12 @@ NSAccessibilityPostNotification([self cell], NSAccessibilityValueChangedNotification); } +- (void)propagateValue:(id)value forBinding:(NSString *)binding { + updatedBinding = binding; + [super propagateValue:value forBinding:binding]; + updatedBinding = nil; +} + #pragma mark Accessors - (SEL)action { return action; } @@ -242,6 +244,10 @@ } - (void)setFont:(NSFont *)newFont { + // updating the fontName or fontSize binding triggers setFont: from KVO + // which can set a partially updated font as it uses both bindings to build the font + if ([updatedBinding isEqualToString:FONTNAME_KEY] || [updatedBinding isEqualToString:FONTSIZE_KEY]) + return; BOOL didChange = [[self font] isEqual:newFont] == NO; [super setFont:newFont]; if (didChange) @@ -273,6 +279,8 @@ } - (void)setTextColor:(NSColor *)newTextColor { + if ([updatedBinding isEqualToString:TEXTCOLOR_KEY]) + return; BOOL didChange = [[self textColor] isEqual:newTextColor] == NO; [[self cell] setTextColor:newTextColor]; if (didChange) @@ -290,63 +298,6 @@ } } -#pragma mark Binding support - -- (void)bind:(NSString *)bindingName toObject:(id)observableController withKeyPath:(NSString *)keyPath options:(NSDictionary *)options { - if ([bindingName isEqualToString:FONTNAME_KEY] || [bindingName isEqualToString:FONTSIZE_KEY]) { - - if ([bindingInfo objectForKey:bindingName]) - [self unbind:bindingName]; - - NSDictionary *bindingsData = [NSDictionary dictionaryWithObjectsAndKeys:observableController, NSObservedObjectKey, [keyPath copy], NSObservedKeyPathKey, [options copy], NSOptionsKey, nil]; - [bindingInfo setObject:bindingsData forKey:bindingName]; - - void *context = NULL; - if ([bindingName isEqualToString:FONTNAME_KEY]) - context = &SKFontWellFontNameObservationContext; - else if ([bindingName isEqualToString:FONTSIZE_KEY]) - context = &SKFontWellFontSizeObservationContext; - - [observableController addObserver:self forKeyPath:keyPath options:NSKeyValueObservingOptionInitial context:context]; - } else { - [super bind:bindingName toObject:observableController withKeyPath:keyPath options:options]; - } - [self setNeedsDisplay:YES]; -} - -- (void)unbind:(NSString *)bindingName { - if ([bindingName isEqualToString:FONTNAME_KEY] || [bindingName isEqualToString:FONTSIZE_KEY]) { - - NSDictionary *info = [self infoForBinding:bindingName]; - [[info objectForKey:NSObservedObjectKey] removeObserver:self forKeyPath:[info objectForKey:NSObservedKeyPathKey] context:[bindingName isEqualToString:FONTNAME_KEY] ? &SKFontWellFontNameObservationContext : &SKFontWellFontSizeObservationContext]; - [bindingInfo removeObjectForKey:bindingName]; - } else { - [super unbind:bindingName]; - } - [self setNeedsDisplay:YES]; -} - -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - NSString *key = nil; - if (context == &SKFontWellFontNameObservationContext) - key = FONTNAME_KEY; - else if (context == &SKFontWellFontSizeObservationContext) - key = FONTSIZE_KEY; - - if (key) { - NSDictionary *info = [self infoForBinding:key]; - id value = [[info objectForKey:NSObservedObjectKey] valueForKeyPath:[info objectForKey:NSObservedKeyPathKey]]; - if (NSIsControllerMarker(value) == NO) - [self setValue:value forKey:key]; - } else { - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; - } -} - -- (NSDictionary *)infoForBinding:(NSString *)bindingName { - return [bindingInfo objectForKey:bindingName] ?: [super infoForBinding:bindingName]; -} - #pragma mark NSDraggingDestination protocol - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit