Finish implementing storage of storyboard segue on action.

This commit is contained in:
Gregory John Casamento 2020-07-14 04:31:08 -04:00
parent 8e030e0fe5
commit a59f92357a
3 changed files with 30 additions and 27 deletions

View file

@ -73,7 +73,7 @@ extern "C" {
id _sender; id _sender;
NSString *_identifier; NSString *_identifier;
NSString *_kind; NSString *_kind;
NSDictionary *_identifierToSegueMap; NSStoryboardSegue *_storyboardSegue;
NSStoryboard *_storyboard; NSStoryboard *_storyboard;
} }
@ -95,12 +95,12 @@ extern "C" {
- (NSString *) kind; - (NSString *) kind;
- (void) setKind: (NSString *)kind; - (void) setKind: (NSString *)kind;
- (NSDictionary *) identifierToSegueMap;
- (void) setIdentifierToSegueMap: (NSDictionary *)table;
- (NSStoryboard *) storyboard; - (NSStoryboard *) storyboard;
- (void) setStoryboard: (NSStoryboard *)storyboard; - (void) setStoryboard: (NSStoryboard *)storyboard;
- (NSStoryboardSegue *) storyboardSegue;
- (void) setStoryboardSegue: (NSStoryboardSegue *)ss;
- (IBAction) doAction: (id)sender; - (IBAction) doAction: (id)sender;
@end @end

View file

@ -143,16 +143,6 @@
ASSIGN(_kind, kind); ASSIGN(_kind, kind);
} }
- (NSDictionary *) identifierToSegueMap
{
return _identifierToSegueMap;
}
- (void) setIdentifierToSegueMap: (NSDictionary *)table
{
ASSIGN(_identifierToSegueMap, table);
}
- (NSStoryboard *) storyboard - (NSStoryboard *) storyboard
{ {
return _storyboard; return _storyboard;
@ -163,6 +153,16 @@
ASSIGN(_storyboard, storyboard); ASSIGN(_storyboard, storyboard);
} }
- (NSStoryboardSegue *) storyboardSegue
{
return _storyboardSegue;
}
- (void) setStoryboardSegue: (NSStoryboardSegue *)ss
{
ASSIGN(_storyboardSegue, ss);
}
- (id) nibInstantiate - (id) nibInstantiate
{ {
return self; return self;
@ -171,10 +171,10 @@
- (void) dealloc - (void) dealloc
{ {
RELEASE(_storyboard); RELEASE(_storyboard);
RELEASE(_identifierToSegueMap);
RELEASE(_kind); RELEASE(_kind);
RELEASE(_identifier); RELEASE(_identifier);
RELEASE(_sender); RELEASE(_sender);
RELEASE(_storyboardSegue);
[super dealloc]; [super dealloc];
} }
@ -187,22 +187,20 @@
} }
else // This is a special case where there is no source controller and we don't ask "should" else // This is a special case where there is no source controller and we don't ask "should"
{ {
NSMapTable *mapTable = [_identifierToSegueMap objectForKey: APPLICATION];
NSStoryboardSegue *segue = [mapTable objectForKey: _identifier];
id destCon = nil; id destCon = nil;
if ([[segue destinationController] isKindOfClass: [NSViewController class]] || if ([[_storyboardSegue destinationController] isKindOfClass: [NSViewController class]] ||
[[segue destinationController] isKindOfClass: [NSWindowController class]]) [[_storyboardSegue destinationController] isKindOfClass: [NSWindowController class]])
{ {
destCon = [segue destinationController]; destCon = [_storyboardSegue destinationController];
} }
else else
{ {
NSString *destId = [segue destinationController]; NSString *destId = [_storyboardSegue destinationController];
destCon = [_storyboard instantiateControllerWithIdentifier: destId]; destCon = [_storyboard instantiateControllerWithIdentifier: destId];
} }
[segue _setSourceController: nil]; [_storyboardSegue _setSourceController: nil];
[segue _setDestinationController: destCon]; // replace with actual controller... [_storyboardSegue _setDestinationController: destCon]; // replace with actual controller...
[segue perform]; [_storyboardSegue perform];
} }
} }
@ -213,7 +211,7 @@
[pa setSelector: [self selector]]; [pa setSelector: [self selector]];
[pa setSender: _sender]; [pa setSender: _sender];
[pa setIdentifier: _identifier]; [pa setIdentifier: _identifier];
[pa setIdentifierToSegueMap: _identifierToSegueMap]; [pa setStoryboardSegue: _storyboardSegue];
[pa setStoryboard: _storyboard]; [pa setStoryboard: _storyboard];
return pa; return pa;
} }

View file

@ -31,6 +31,7 @@
#import <Foundation/NSDictionary.h> #import <Foundation/NSDictionary.h>
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSUUID.h> #import <Foundation/NSUUID.h>
#import <Foundation/NSException.h>
#import "AppKit/NSApplication.h" #import "AppKit/NSApplication.h"
#import "AppKit/NSNib.h" #import "AppKit/NSNib.h"
@ -227,8 +228,11 @@ static NSStoryboard *__mainStoryboard = nil;
if ([o isKindOfClass: [NSStoryboardSeguePerformAction class]]) if ([o isKindOfClass: [NSStoryboardSeguePerformAction class]])
{ {
NSStoryboardSeguePerformAction *ssa = (NSStoryboardSeguePerformAction *)o; NSStoryboardSeguePerformAction *ssa = (NSStoryboardSeguePerformAction *)o;
NSMapTable *mapTable = [[_transform identifierToSegueMap] objectForKey: identifier];
NSStoryboardSegue *ss = [mapTable objectForKey: [ssa identifier]];
[ssa setSender: result]; // resolve controller here... [ssa setSender: result]; // resolve controller here...
[ssa setIdentifierToSegueMap: [_transform identifierToSegueMap]]; [ssa setStoryboardSegue: ss];
[ssa setStoryboard: self]; [ssa setStoryboard: self];
if ([[ssa kind] isEqualToString: @"relationship"]) // if it is a relationship, perform immediately if ([[ssa kind] isEqualToString: @"relationship"]) // if it is a relationship, perform immediately
{ {
@ -262,7 +266,8 @@ static NSStoryboard *__mainStoryboard = nil;
} }
else else
{ {
NSLog(@"Couldn't load controller scene identifier = %@", identifier); [NSException raise: NSInternalInconsistencyException
format: @"Couldn't load controller scene identifier = %@", identifier];
} }
// Execute the block if it's set... // Execute the block if it's set...