Segue partially working. Commit existing changes

This commit is contained in:
Gregory John Casamento 2020-07-04 13:01:26 -04:00
parent 486ab5bd5b
commit 7d92caca6f
5 changed files with 84 additions and 41 deletions

View file

@ -207,7 +207,6 @@ static NSArray *XmlBoolDefaultYes = nil;
@"NSWindowTemplate", @"window",
@"NSView", @"tableCellView",
@"IBUserDefinedRuntimeAttribute5", @"userDefinedRuntimeAttribute",
@"NSStoryboardSegue", @"segue",
@"NSURL", @"url",
nil];
RETAIN(XmlTagToObjectClassMap);

View file

@ -42,6 +42,7 @@
#import "GNUstepGUI/GSModelLoaderFactory.h"
static NSStoryboard *mainStoryboard = nil;
static NSStoryboard *currentStoryboard = nil;
// The storyboard needs to set this information on controllers...
@interface NSWindowController (__StoryboardPrivate__)
@ -218,8 +219,8 @@ static NSStoryboard *mainStoryboard = nil;
- (IBAction) doAction: (id)sender
{
[sender performSegueWithIdentifier: _identifier
sender: _sender];
[_sender performSegueWithIdentifier: _identifier
sender: _sender];
}
- (id) copyWithZone: (NSZone *)z
@ -562,6 +563,9 @@ static NSStoryboard *mainStoryboard = nil;
if ([[obj name] isEqualToString: @"segue"])
{
// get the information from the segue.
id segue_parent_parent = [[obj parent] parent];
id segue_parent = [obj parent];
NSString *segue_parent_parent_name = [segue_parent_parent name];
NSXMLNode *attr = [obj attributeForName: @"destination"];
NSString *dst = [attr stringValue];
attr = [obj attributeForName: @"kind"];
@ -586,15 +590,16 @@ static NSStoryboard *mainStoryboard = nil;
NSXMLNode *ptarget
= [NSXMLNode attributeWithName: @"target"
stringValue: dst];
NSString *pident_value = [[NSUUID UUID] UUIDString];
NSXMLNode *pident
= [NSXMLNode attributeWithName: @"id"
stringValue: uid];
stringValue: pident_value];
NSXMLNode *psegueIdent
= [NSXMLNode attributeWithName: @"identifier"
stringValue: identifier];
NSXMLNode *psender
= [NSXMLNode attributeWithName: @"sender"
stringValue: dst];
stringValue: src];
NSXMLNode *pkind
= [NSXMLNode attributeWithName: @"kind"
stringValue: kind];
@ -608,25 +613,28 @@ static NSStoryboard *mainStoryboard = nil;
NSUInteger count = [[objects children] count];
[objects insertChild: sbproxy
atIndex: count - 1];
// Create action...
NSXMLElement *conns = [NSXMLElement elementWithName: @"connections"];
NSXMLElement *action = [NSXMLElement elementWithName: @"action"];
NSXMLNode *selector
= [NSXMLNode attributeWithName: @"selector"
stringValue: @"doAction:"];
NSXMLNode *target
= [NSXMLNode attributeWithName: @"target"
stringValue: dst];
NSXMLNode *ident
= [NSXMLNode attributeWithName: @"id"
stringValue: uid];
[action addAttribute: selector];
[action addAttribute: target];
[action addAttribute: ident];
[conns addChild: action]; // add to parent..
[sbproxy addChild: conns];
// add action to parent ONLY if it is NOT a controller..
if (![segue_parent_parent_name isEqualToString: @"windowController"] &&
![segue_parent_parent_name isEqualToString: @"viewController"])
{
// Create action...
NSXMLElement *action = [NSXMLElement elementWithName: @"action"];
NSXMLNode *selector
= [NSXMLNode attributeWithName: @"selector"
stringValue: @"doAction:"];
NSXMLNode *target
= [NSXMLNode attributeWithName: @"target"
stringValue: pident_value];
NSXMLNode *ident
= [NSXMLNode attributeWithName: @"id"
stringValue: uid];
[action addAttribute: selector];
[action addAttribute: target];
[action addAttribute: ident];
[segue_parent addChild: action];
}
// Create the segue...
NSStoryboardSegue *ss = [[NSStoryboardSegue alloc] initWithIdentifier: identifier
source: src
@ -666,7 +674,7 @@ static NSStoryboard *mainStoryboard = nil;
// Class methods...
+ (void) setMainStoryboard: (NSStoryboard *)storyboard // private, only called from NSApplicationMain()
{
mainStoryboard = storyboard;
ASSIGN(mainStoryboard, storyboard);
}
+ (NSStoryboard *) mainStoryboard // 10.13
@ -772,7 +780,8 @@ static NSStoryboard *mainStoryboard = nil;
if ([o isKindOfClass: [NSStoryboardSeguePerformAction class]])
{
NSStoryboardSeguePerformAction *ssa = (NSStoryboardSeguePerformAction *)o;
if ([[ssa kind] isEqualToString: @"relationship"])
[ssa setSender: controller]; // resolve controller here...
if ([[ssa kind] isEqualToString: @"relationship"]) // if it is a relationship, perform immediately
{
[seguesToPerform addObject: ssa];
}
@ -790,7 +799,7 @@ static NSStoryboard *mainStoryboard = nil;
}
else
{
NSLog(@"Couldn't load initial controller scene");
NSLog(@"Couldn't load controller scene id = %@", sceneId);
}
return controller;

View file

@ -28,6 +28,7 @@
#import "AppKit/NSWindowController.h"
#import "AppKit/NSViewController.h"
#import "AppKit/NSWindow.h"
#import "AppKit/NSApplication.h"
@implementation NSStoryboardSegue
@ -51,6 +52,16 @@
ASSIGN(_handler, handler);
}
- (void) _setDestinationController: (id)controller
{
_destinationController = controller;
}
- (void) _setSourceController: (id)controller
{
_sourceController = controller;
}
+ (instancetype)segueWithIdentifier: (NSStoryboardSegueIdentifier)identifier
source: (id)sourceController
destination: (id)destinationController
@ -101,11 +112,35 @@
}
else if ([_kind isEqualToString: @"modal"])
{
NSLog(@"modal");
NSInteger code = NSRunContinuesResponse;
NSWindow *w = nil;
if ([_destinationController isKindOfClass: [NSWindowController class]])
{
w = [_destinationController window];
}
else
{
w = [NSWindow windowWithContentViewController: _destinationController];
}
RETAIN(w);
code = [NSApp runModalForWindow: w];
if (code != NSRunContinuesResponse)
{
NSLog(@"Modal returned error response.");
}
RELEASE(w);
}
else if ([_kind isEqualToString: @"show"])
{
NSLog(@"show");
if ([_destinationController isKindOfClass: [NSWindowController class]])
{
[_destinationController showWindow: _sourceController];
}
else
{
NSWindow *w = [NSWindow windowWithContentViewController: _destinationController];
[w orderFrontRegardless];
}
}
if (_handler != nil)

View file

@ -36,6 +36,12 @@
#import "AppKit/NSView.h"
#import "AppKit/NSViewController.h"
#import "AppKit/NSStoryboardSegue.h"
#import "AppKit/NSStoryboard.h"
@interface NSStoryboardSegue (__ViewControllerPrivate__)
- (void) _setDestinationController: (id)controller;
- (void) _setSourceController: (id)controller;
@end
@implementation NSViewController
@ -184,6 +190,7 @@
}
}
// NSSeguePerforming methods...
- (void)performSegueWithIdentifier: (NSStoryboardSegueIdentifier)identifier
sender: (id)sender
@ -194,6 +201,12 @@
if (should)
{
NSStoryboardSegue *segue = [_segueMap objectForKey: identifier];
NSStoryboard *ms = [NSStoryboard mainStoryboard];
NSString *destId = [segue destinationController];
id destCon = [ms instantiateControllerWithIdentifier: destId];
[segue _setSourceController: self];
[segue _setDestinationController: destCon]; // replace with actual controller...
[self prepareForSegue: segue
sender: sender];
[segue perform];

View file

@ -49,19 +49,6 @@
- (void) _setSourceController: (id)controller;
@end
@implementation NSStoryboardSegue (__WindowControllerPrivate__)
- (void) _setDestinationController: (id)controller
{
_destinationController = controller;
}
- (void) _setSourceController: (id)controller
{
_sourceController = controller;
}
@end
@implementation NSWindowController
+ (void) initialize