From f59c7edfb69f99b3f433e2035142ffe240ce252c Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 9 Oct 2023 04:53:54 -0400 Subject: [PATCH] Fix issues with storyboards and segues --- Source/GSStoryboardTransform.m | 115 ++++++++++++++++++++------------- Source/NSPopover.m | 13 ++-- Source/NSStoryboardSegue.m | 17 +++-- 3 files changed, 84 insertions(+), 61 deletions(-) diff --git a/Source/GSStoryboardTransform.m b/Source/GSStoryboardTransform.m index befb07aa31..7c1de9de08 100644 --- a/Source/GSStoryboardTransform.m +++ b/Source/GSStoryboardTransform.m @@ -727,9 +727,13 @@ - (NSXMLElement *) createStoryboardProxyElementWithSelector: (NSString *)selecto NSXMLNode *pkind = [NSXMLNode attributeWithName: @"kind" stringValue: kind]; - NSXMLNode *panchorview - = [NSXMLNode attributeWithName: @"popoverAnchorView" - stringValue: anchorView]; + + NSXMLNode *panchorview = nil; + if (anchorView != nil) + { + panchorview = [NSXMLNode attributeWithName: @"popoverAnchorView" + stringValue: anchorView]; + } [sbproxy addAttribute: pselector]; [sbproxy addAttribute: ptarget]; @@ -737,8 +741,12 @@ - (NSXMLElement *) createStoryboardProxyElementWithSelector: (NSString *)selecto [sbproxy addAttribute: psegueIdent]; [sbproxy addAttribute: psender]; [sbproxy addAttribute: pkind]; - [sbproxy addAttribute: panchorview]; + if (panchorview != nil) + { + [sbproxy addAttribute: panchorview]; + } + return sbproxy; } @@ -774,43 +782,48 @@ - (NSMapTable *) processConnections: (NSArray *)connectionsArray ident = [[NSUUID UUID] UUIDString]; } attr = [obj attributeForName: @"popoverAnchorView"]; - NSString *av = [attr stringValue]; - attr = [obj attributeForName: @"popoverBehavior"]; - NSString *pb = [attr stringValue]; - NSPopoverBehavior behavior = NSPopoverBehaviorApplicationDefined; - if ([pb isEqualToString: @"a"]) - { - behavior = NSPopoverBehaviorApplicationDefined; - } - else if ([pb isEqualToString: @"t"]) - { - behavior = NSPopoverBehaviorTransient; - } - else if ([pb isEqualToString: @"s"]) - { - behavior = NSPopoverBehaviorSemitransient; - } - - attr = [obj attributeForName: @"preferredEdge"]; - NSString *pe = [attr stringValue]; - NSRectEdge edge = NSMinXEdge; - if ([pe isEqualToString: @"maxY"]) - { - edge = NSMaxYEdge; - } - else if ([pe isEqualToString: @"minY"]) - { - edge = NSMinYEdge; - } - else if ([pe isEqualToString: @"maxX"]) - { - edge = NSMaxXEdge; - } - else if ([pe isEqualToString: @"minX"]) - { - edge = NSMinXEdge; - } - [obj detach]; // segue can't be in the archive since it doesn't conform to NSCoding + + NSString *av = [attr stringValue]; + NSPopoverBehavior behavior = NSNotFound; + NSRectEdge edge = NSNotFound; + + if (av != nil) + { + attr = [obj attributeForName: @"popoverBehavior"]; + NSString *pb = [attr stringValue]; + if ([pb isEqualToString: @"a"]) + { + behavior = NSPopoverBehaviorApplicationDefined; + } + else if ([pb isEqualToString: @"t"]) + { + behavior = NSPopoverBehaviorTransient; + } + else if ([pb isEqualToString: @"s"]) + { + behavior = NSPopoverBehaviorSemitransient; + } + + attr = [obj attributeForName: @"preferredEdge"]; + NSString *pe = [attr stringValue]; + if ([pe isEqualToString: @"maxY"]) + { + edge = NSMaxYEdge; + } + else if ([pe isEqualToString: @"minY"]) + { + edge = NSMinYEdge; + } + else if ([pe isEqualToString: @"maxX"]) + { + edge = NSMaxXEdge; + } + else if ([pe isEqualToString: @"minX"]) + { + edge = NSMinXEdge; + } + } + [obj detach]; // segue can't be in the archive since it doesn't conform to NSCoding // Create proxy object to invoke methods on the window controller NSXMLElement *sbproxy = [self createStoryboardProxyElementWithSelector: @"doAction:" @@ -838,11 +851,13 @@ - (NSMapTable *) processConnections: (NSArray *)connectionsArray stringValue: [[sbproxy attributeForName: @"id"] stringValue]]; NSXMLNode *controller_ident = [NSXMLNode attributeWithName: @"id" - stringValue: uid]; + stringValue: uid]; + [action addAttribute: selector]; [action addAttribute: target]; [action addAttribute: controller_ident]; - [segue_parent addChild: action]; + + [segue_parent addChild: action]; } // Create the segue... @@ -851,9 +866,17 @@ - (NSMapTable *) processConnections: (NSArray *)connectionsArray destination: dst]; [ss _setKind: kind]; [ss _setRelationship: rel]; - [ss _setPopoverBehavior: behavior]; - [ss _setPreferredEdge: edge]; - + + if (behavior != NSNotFound) + { + [ss _setPopoverBehavior: behavior]; + } + + if (edge != NSNotFound) + { + [ss _setPreferredEdge: edge]; + } + // Add to maptable... [mapTable setObject: ss forKey: ident]; diff --git a/Source/NSPopover.m b/Source/NSPopover.m index 5d36a9f4ea..a2eb05a9c8 100644 --- a/Source/NSPopover.m +++ b/Source/NSPopover.m @@ -249,10 +249,12 @@ - (void) showRelativeToRect: (NSRect)positioningRect NSRect screenRect; NSRect windowFrame; NSRect viewFrame; - + NSWindow *window = nil; + [_contentViewController loadView]; view = [_contentViewController view]; - viewFrame = [view frame]; + window = [view window]; + viewFrame = [view frame]; // [window convertRectToScreen: [view frame]]; if (!_realPanel) { @@ -261,7 +263,6 @@ - (void) showRelativeToRect: (NSRect)positioningRect backing: NSBackingStoreRetained defer: NO]; - [_realPanel setBackgroundColor: [NSColor darkGrayColor]]; [_realPanel setReleasedWhenClosed: YES]; [_realPanel setExcludedFromWindowsMenu: YES]; [_realPanel setLevel: NSPopUpMenuWindowLevel]; @@ -270,7 +271,7 @@ - (void) showRelativeToRect: (NSRect)positioningRect [_realPanel setContentView: view]; } - screenRect = [[positioningView window] convertRectToScreen:positioningRect]; + screenRect = [[positioningView window] convertRectToScreen: positioningRect]; windowFrame = [_realPanel frame]; windowFrame.origin = screenRect.origin; @@ -294,8 +295,8 @@ - (void) showRelativeToRect: (NSRect)positioningRect [_realPanel setFrame: windowFrame display: YES]; [_realPanel makeKeyAndOrderFront:self]; - NSDebugLog(@"Showing relative to in window %@",NSStringFromRect(positioningRect)); - NSDebugLog(@"Showing relative to in screen %@",NSStringFromRect(screenRect)); + NSLog(@"Showing relative to in window %@",NSStringFromRect(positioningRect)); + NSLog(@"Showing relative to in screen %@",NSStringFromRect(screenRect)); _shown = YES; } diff --git a/Source/NSStoryboardSegue.m b/Source/NSStoryboardSegue.m index b5b6ff466e..4fee76363c 100644 --- a/Source/NSStoryboardSegue.m +++ b/Source/NSStoryboardSegue.m @@ -174,15 +174,15 @@ - (void) perform { if (_popover == nil) { - NSPopover *po = [[NSPopover alloc] init]; NSRect rect = [_popoverAnchorView frame]; - _popover = po; // weak... since we manually release... - [po setBehavior: _popoverBehavior]; - [po setContentViewController: _destinationController]; - [po showRelativeToRect: rect - ofView: _popoverAnchorView - preferredEdge: _preferredEdge]; + NSLog(@"anchor view = %@", _popoverAnchorView); + _popover = [[NSPopover alloc] init]; // manually release when closed... + [_popover setBehavior: _popoverBehavior]; + [_popover setContentViewController: _destinationController]; + [_popover showRelativeToRect: rect + ofView: _popoverAnchorView + preferredEdge: _preferredEdge]; } else { @@ -190,8 +190,7 @@ - (void) perform { [_destinationController dismissController: nil]; [_popover close]; - RELEASE(_popover); - _popover = nil; + DESTROY(_popover); } } }