Use enum for behavior

This commit is contained in:
Gregory John Casamento 2020-07-28 07:44:47 -04:00
parent 52fd3b0cc6
commit bc802f3833
3 changed files with 25 additions and 24 deletions

View file

@ -27,6 +27,7 @@
#import <Foundation/NSObject.h>
#import <Foundation/NSGeometry.h>
#import <AppKit/NSPopover.h>
#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
@ -46,7 +47,7 @@ DEFINE_BLOCK_TYPE_NO_ARGS(GSStoryboardSeguePerformHandler, void);
NSString *_kind;
NSString *_relationship;
id _popoverAnchorView;
NSString *_popoverBehavior;
NSPopoverBehavior _popoverBehavior;
NSRectEdge _preferredEdge;
GSStoryboardSeguePerformHandler _handler;
}

View file

@ -59,8 +59,8 @@
- (NSString *) _relationship;
- (void) _setPopoverAnchorView: (id)view;
- (id) _popoverAnchorView;
- (void) _setPopoverBehavior: (NSString *)behavior;
- (NSString *) _popoverBehavior;
- (void) _setPopoverBehavior: (NSPopoverBehavior)behavior;
- (NSPopoverBehavior) _popoverBehavior;
- (void) _setPreferredEdge: (NSRectEdge)edge;
- (NSRectEdge) _preferredEdge;
@end
@ -97,12 +97,12 @@
return _popoverAnchorView;
}
- (void) _setPopoverBehavior: (NSString *)behavior
- (void) _setPopoverBehavior: (NSPopoverBehavior)behavior
{
ASSIGN(_popoverBehavior, behavior);
_popoverBehavior = behavior;
}
- (NSString *) _popoverBehavior
- (NSPopoverBehavior) _popoverBehavior
{
return _popoverBehavior;
}
@ -112,7 +112,7 @@
_preferredEdge = edge;
}
- (NSString *) _preferredEdge
- (NSRectEdge) _preferredEdge
{
return _preferredEdge;
}
@ -777,6 +777,20 @@
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;
@ -837,7 +851,7 @@
destination: dst];
[ss _setKind: kind];
[ss _setRelationship: rel];
[ss _setPopoverBehavior: pb];
[ss _setPopoverBehavior: behavior];
[ss _setPreferredEdge: edge];
// Add to maptable...

View file

@ -174,22 +174,8 @@
{
NSPopover *po = [[NSPopover alloc] init];
NSRect rect = [_popoverAnchorView frame];
NSPopoverBehavior behavior = NSPopoverBehaviorApplicationDefined;
// Convert behavior
if ([_popoverBehavior isEqualToString: @"a"])
{
behavior = NSPopoverBehaviorApplicationDefined;
}
else if ([_popoverBehavior isEqualToString: @"t"])
{
behavior = NSPopoverBehaviorTransient;
}
else if ([_popoverBehavior isEqualToString: @"s"])
{
behavior = NSPopoverBehaviorSemitransient;
}
[po setBehavior: _popoverBehavior];
[po setContentViewController: _destinationController];
[po showRelativeToRect: rect
ofView: _popoverAnchorView