Skip to content

Commit

Permalink
Fix issues with storyboards and segues
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasa committed Oct 11, 2023
1 parent 8619fe3 commit f59c7ed
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 61 deletions.
115 changes: 69 additions & 46 deletions Source/GSStoryboardTransform.m
Original file line number Diff line number Diff line change
Expand Up @@ -727,18 +727,26 @@ - (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];
[sbproxy addAttribute: pident];
[sbproxy addAttribute: psegueIdent];
[sbproxy addAttribute: psender];
[sbproxy addAttribute: pkind];
[sbproxy addAttribute: panchorview];

if (panchorview != nil)
{
[sbproxy addAttribute: panchorview];
}

return sbproxy;
}

Expand Down Expand Up @@ -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:"
Expand Down Expand Up @@ -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...
Expand All @@ -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];
Expand Down
13 changes: 7 additions & 6 deletions Source/NSPopover.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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];
Expand All @@ -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;

Expand All @@ -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;
}
Expand Down
17 changes: 8 additions & 9 deletions Source/NSStoryboardSegue.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,23 @@ - (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
{
if ([_popover behavior] == NSPopoverBehaviorTransient)
{
[_destinationController dismissController: nil];
[_popover close];
RELEASE(_popover);
_popover = nil;
DESTROY(_popover);
}
}
}
Expand Down

0 comments on commit f59c7ed

Please sign in to comment.