libs-gui/Source/NSStoryboardSegue.m

154 lines
4.1 KiB
Mathematica
Raw Normal View History

2020-01-20 20:58:19 +00:00
/* Implementation of class NSStoryboardSegue
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory Casamento
Date: Mon Jan 20 15:57:31 EST 2020
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
2020-07-02 17:24:48 +00:00
#import <Foundation/NSString.h>
2020-07-02 20:39:40 +00:00
#import "AppKit/NSStoryboardSegue.h"
2020-07-02 20:39:40 +00:00
#import "AppKit/NSWindowController.h"
#import "AppKit/NSViewController.h"
#import "AppKit/NSWindow.h"
#import "AppKit/NSApplication.h"
2020-01-20 20:58:19 +00:00
@implementation NSStoryboardSegue
- (id) sourceController
{
return _sourceController;
}
- (id) destinationController
{
return _destinationController;
}
- (NSStoryboardSegueIdentifier)identifier
{
return _identifier;
}
2020-07-02 17:24:48 +00:00
- (void) _setHandler: (GSStoryboardSeguePerformHandler)handler
{
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
performHandler: (GSStoryboardSeguePerformHandler)performHandler
{
NSStoryboardSegue *segue = [[NSStoryboardSegue alloc] initWithIdentifier: identifier
source: sourceController
destination: destinationController];
AUTORELEASE(segue);
2020-07-02 17:24:48 +00:00
[segue _setHandler: performHandler];
return segue;
}
- (instancetype)initWithIdentifier: (NSStoryboardSegueIdentifier)identifier
source: (id)sourceController
destination: (id)destinationController
{
self = [super init];
if (self != nil)
{
ASSIGN(_sourceController, sourceController);
ASSIGN(_destinationController, destinationController);
ASSIGN(_identifier, identifier);
}
return self;
}
2020-07-02 17:24:48 +00:00
- (void) dealloc
{
RELEASE(_sourceController);
RELEASE(_destinationController);
RELEASE(_identifier);
RELEASE(_kind);
RELEASE(_relationship);
RELEASE(_handler);
[super dealloc];
}
- (void)perform
{
2020-07-02 20:39:40 +00:00
// Perform segue based on it's kind...
2020-07-02 17:24:48 +00:00
if ([_kind isEqualToString: @"relationship"])
{
2020-07-02 20:39:40 +00:00
NSWindow *w = [_sourceController window];
NSView *v = [_destinationController view];
[w setContentView: v];
2020-07-02 17:24:48 +00:00
}
else if ([_kind isEqualToString: @"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);
2020-07-02 17:24:48 +00:00
}
else if ([_kind isEqualToString: @"show"])
{
if ([_destinationController isKindOfClass: [NSWindowController class]])
{
[_destinationController showWindow: _sourceController];
}
else
{
NSWindow *w = [NSWindow windowWithContentViewController: _destinationController];
[w orderFrontRegardless];
}
2020-07-02 20:39:40 +00:00
}
if (_handler != nil)
{
CALL_BLOCK_NO_ARGS(_handler);
2020-07-02 17:24:48 +00:00
}
}
2020-01-20 20:58:19 +00:00
@end