Revision: 15423 http://sourceforge.net/p/skim-app/code/15423 Author: hofman Date: 2025-06-10 15:59:04 +0000 (Tue, 10 Jun 2025) Log Message: ----------- setup widget registration implicitly when applying widget values
Modified Paths: -------------- trunk/SKMainWindowController.m Modified: trunk/SKMainWindowController.m =================================================================== --- trunk/SKMainWindowController.m 2025-06-10 15:55:47 UTC (rev 15422) +++ trunk/SKMainWindowController.m 2025-06-10 15:59:04 UTC (rev 15423) @@ -898,14 +898,6 @@ [widgetValues setObject:[annotation objectValue] forKey:annotation]; } -- (void)makeWidgets { - widgets = [[NSMutableArray alloc] init]; - widgetValues = [NSMapTable strongToStrongObjectsMapTable]; - NSArray *array = [[self pdfDocument] detectedWidgets]; - if ([array count]) - [self registerWidgets:array]; -} - - (void)document:(PDFDocument *)document didDetectWidgets:(NSArray *)newWidgets onPage:(PDFPage *)page { if ([newWidgets count] && widgets && [widgets containsObject:[newWidgets firstObject]] == NO) [self registerWidgets:newWidgets]; @@ -920,21 +912,30 @@ } - (void)changeWidgetsFromDictionaries:(NSArray *)widgetDicts { - PDFDocument *pdfDoc = [pdfView document]; - for (NSDictionary *dict in widgetDicts) { - NSRect bounds = NSIntegralRect(NSRectFromString([dict objectForKey:SKNPDFAnnotationBoundsKey])); - NSUInteger pageIndex = [[dict objectForKey:SKNPDFAnnotationPageIndexKey] unsignedIntegerValue]; - SKNPDFWidgetType widgetType = [[dict objectForKey:SKNPDFAnnotationWidgetTypeKey] integerValue]; - NSString *fieldName = [dict objectForKey:SKNPDFAnnotationFieldNameKey] ?: @""; - for (PDFAnnotation *annotation in [[pdfDoc pageAtIndex:pageIndex] annotations]) { - if ([annotation isWidget] && - [annotation widgetType] == widgetType && - [([annotation fieldName] ?: @"") isEqualToString:fieldName] && - NSEqualRects(NSIntegralRect([annotation bounds]), bounds)) { - id value = [dict objectForKey:widgetType == kSKNPDFWidgetTypeButton ? SKNPDFAnnotationStateKey : SKNPDFAnnotationStringValueKey]; - if ([([annotation objectValue] ?: @"") isEqual:(value ?: @"")] == NO) - [annotation setObjectValue:value]; - break; + if (widgets == nil) { + widgets = [[NSMutableArray alloc] init]; + widgetValues = [NSMapTable strongToStrongObjectsMapTable]; + NSArray *array = [[self pdfDocument] detectedWidgets]; + if ([array count]) + [self registerWidgets:array]; + } + if ([widgetDicts count]) { + PDFDocument *pdfDoc = [pdfView document]; + for (NSDictionary *dict in widgetDicts) { + NSRect bounds = NSIntegralRect(NSRectFromString([dict objectForKey:SKNPDFAnnotationBoundsKey])); + NSUInteger pageIndex = [[dict objectForKey:SKNPDFAnnotationPageIndexKey] unsignedIntegerValue]; + SKNPDFWidgetType widgetType = [[dict objectForKey:SKNPDFAnnotationWidgetTypeKey] integerValue]; + NSString *fieldName = [dict objectForKey:SKNPDFAnnotationFieldNameKey] ?: @""; + for (PDFAnnotation *annotation in [[pdfDoc pageAtIndex:pageIndex] annotations]) { + if ([annotation isWidget] && + [annotation widgetType] == widgetType && + [([annotation fieldName] ?: @"") isEqualToString:fieldName] && + NSEqualRects(NSIntegralRect([annotation bounds]), bounds)) { + id value = [dict objectForKey:widgetType == kSKNPDFWidgetTypeButton ? SKNPDFAnnotationStateKey : SKNPDFAnnotationStringValueKey]; + if ([([annotation objectValue] ?: @"") isEqual:(value ?: @"")] == NO) + [annotation setObjectValue:value]; + break; + } } } } @@ -1181,13 +1182,10 @@ [toolbarController updateMinMaxScale]; - if ([pdfDocument isLocked]) { + if ([pdfDocument isLocked]) placeholderWidgetProperties = [widgetProperties count] ? [widgetProperties copy] : nil; - } else { - [self makeWidgets]; - if ([widgetProperties count]) - [self changeWidgetsFromDictionaries:widgetProperties]; - } + else + [self changeWidgetsFromDictionaries:widgetProperties]; [self updatePageLabelsAndOutlineForExpansionState:openState]; [self updateNoteSelection]; @@ -2164,14 +2162,10 @@ } } - if (widgets == nil) - [self makeWidgets]; - if (placeholderWidgetProperties) { - [[[self document] undoManager] disableUndoRegistration]; - [self changeWidgetsFromDictionaries:placeholderWidgetProperties]; - [[[self document] undoManager] enableUndoRegistration]; - placeholderWidgetProperties = nil; - } + [[[self document] undoManager] disableUndoRegistration]; + [self changeWidgetsFromDictionaries:placeholderWidgetProperties]; + [[[self document] undoManager] enableUndoRegistration]; + placeholderWidgetProperties = nil; if (wasLocked) { [self updatePageLabelsAndOutlineForExpansionState:nil]; 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