Centralize logic for resolution of destination controller

This commit is contained in:
Gregory John Casamento 2020-07-15 04:55:34 -04:00
parent c981f533df
commit f1a3e5dea6
5 changed files with 30 additions and 72 deletions

View file

@ -57,7 +57,6 @@ extern "C" {
- (NSData *) dataForIdentifier: (NSString *)identifier;
- (NSData *) dataForApplicationScene;
- (NSMapTable *) segueMapForIdentifier: (NSString *)identifier;
- (NSDictionary *) identifierToSegueMap;
- (void) processSegues: (NSXMLDocument *)xmlIn
forControllerId: (NSString *)identifier;

View file

@ -163,11 +163,6 @@
ASSIGN(_storyboardSegue, ss);
}
- (id) nibInstantiate
{
return self;
}
- (void) dealloc
{
RELEASE(_storyboard);
@ -180,12 +175,16 @@
- (IBAction) doAction: (id)sender
{
if (_sender != nil)
BOOL should = YES;
BOOL responds = [_sender respondsToSelector: @selector(shouldPerformSegueWithIdentifier:sender:)];
if (responds)
{
[_sender performSegueWithIdentifier: _identifier
sender: _sender];
should = [_sender shouldPerformSegueWithIdentifier: _identifier
sender: _sender];
}
else // This is a special case where there is no source controller and we don't ask "should"
if (should)
{
id destCon = nil;
if ([[_storyboardSegue destinationController] isKindOfClass: [NSViewController class]] ||
@ -198,9 +197,14 @@
NSString *destId = [_storyboardSegue destinationController];
destCon = [_storyboard instantiateControllerWithIdentifier: destId];
}
[_storyboardSegue _setSourceController: nil];
[_storyboardSegue _setSourceController: _sender];
[_storyboardSegue _setDestinationController: destCon]; // replace with actual controller...
[_storyboardSegue perform];
if (_sender != nil)
{
[_sender performSegueWithIdentifier: _identifier
sender: _sender];
}
}
}
@ -353,11 +357,6 @@
return [_identifierToSegueMap objectForKey: identifier];
}
- (NSDictionary *) identifierToSegueMap
{
return _identifierToSegueMap;
}
- (NSXMLElement *) createCustomObjectWithId: (NSString *)ident
userLabel: (NSString *)userLabel
customClass: (NSString *)className

View file

@ -228,7 +228,7 @@ static NSStoryboard *__mainStoryboard = nil;
if ([o isKindOfClass: [NSStoryboardSeguePerformAction class]])
{
NSStoryboardSeguePerformAction *ssa = (NSStoryboardSeguePerformAction *)o;
NSMapTable *mapTable = [[_transform identifierToSegueMap] objectForKey: identifier];
NSMapTable *mapTable = [_transform segueMapForIdentifier: identifier];
NSStoryboardSegue *ss = [mapTable objectForKey: [ssa identifier]];
[ssa setSender: result]; // resolve controller here...
@ -247,14 +247,6 @@ static NSStoryboard *__mainStoryboard = nil;
{
[wc setWindow: w];
}
// perform segues after all is initialized.
FOR_IN(id, o, seguesToPerform)
{
NSStoryboardSeguePerformAction *ssa = (NSStoryboardSeguePerformAction *)o;
[ssa doAction: result]; // this will, as far as I know, only happen with window controllers, to set content.
}
END_FOR_IN(seguesToPerform);
// process placeholders...
FOR_IN(id, o, placeholders)
@ -263,6 +255,14 @@ static NSStoryboard *__mainStoryboard = nil;
result = [ph instantiate];
}
END_FOR_IN(placeholders);
// perform segues after all is initialized.
FOR_IN(id, o, seguesToPerform)
{
NSStoryboardSeguePerformAction *ssa = (NSStoryboardSeguePerformAction *)o;
[ssa doAction: result]; // this will, as far as I know, only happen with window controllers, to set content.
}
END_FOR_IN(seguesToPerform);
}
else
{

View file

@ -196,29 +196,10 @@
- (void)performSegueWithIdentifier: (NSStoryboardSegueIdentifier)identifier
sender: (id)sender
{
BOOL should = [self shouldPerformSegueWithIdentifier: identifier
sender: sender];
if (should)
{
NSStoryboardSegue *segue = [_segueMap objectForKey: identifier];
id destCon = nil;
if ([[segue destinationController] isKindOfClass: [NSViewController class]] ||
[[segue destinationController] isKindOfClass: [NSWindowController class]])
{
destCon = [segue destinationController];
}
else
{
NSString *destId = [segue destinationController];
destCon = [_storyboard instantiateControllerWithIdentifier: destId];
}
[segue _setSourceController: self];
[segue _setDestinationController: destCon]; // replace with actual controller...
[self prepareForSegue: segue
sender: sender];
[segue perform];
}
NSStoryboardSegue *segue = [_segueMap objectForKey: identifier];
[self prepareForSegue: segue
sender: sender];
[segue perform];
}
- (void)prepareForSegue: (NSStoryboardSegue *)segue

View file

@ -566,29 +566,8 @@
- (void)performSegueWithIdentifier: (NSStoryboardSegueIdentifier)identifier
sender: (id)sender
{
BOOL should = [self shouldPerformSegueWithIdentifier: identifier
sender: sender];
if (should)
{
NSStoryboardSegue *segue = [_segueMap objectForKey: identifier];
id destCon = nil;
if ([[segue destinationController] isKindOfClass: [NSViewController class]] ||
[[segue destinationController] isKindOfClass: [NSWindowController class]])
{
destCon = [segue destinationController];
}
else
{
NSString *destId = [segue destinationController];
destCon = [_storyboard instantiateControllerWithIdentifier: destId];
}
[segue _setSourceController: self];
[segue _setDestinationController: destCon]; // replace with actual controller...
[self prepareForSegue: segue
sender: sender];
[segue perform];
}
NSStoryboardSegue *segue = [_segueMap objectForKey: identifier];
[segue perform];
}
- (void)prepareForSegue: (NSStoryboardSegue *)segue