Implement popUpMenuPositonItem:... dragging, dropdown implementation, menu changes

This commit is contained in:
Gregory John Casamento 2020-05-04 09:50:22 -04:00
parent 8222de40c6
commit 266ec7e430
3 changed files with 106 additions and 3 deletions

View file

@ -434,6 +434,12 @@
withFont: (NSFont *)font;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
- (void) popUpMenuPositionItem: (NSMenuItem *)item
atLocation: (NSPoint) point
inView: (NSView *) view;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
+ (BOOL) menuBarVisible;
+ (void) setMenuBarVisible: (BOOL)flag;

View file

@ -1626,6 +1626,18 @@ static BOOL menuBarVisible = YES;
[menu _rightMouseDisplay: event];
}
- (void) popUpMenuPositionItem: (NSMenuItem *)item
atLocation: (NSPoint) point
inView: (NSView *) view
{
NSRect cellFrame = [view frame]; // NSMakeRect(point.x, point.y, 10.0, 10.0);
[[GSTheme theme] displayPopUpMenu: [self menuRepresentation]
withCellFrame: cellFrame
controlViewWindow: [NSApp mainWindow]
preferredEdge: NSMinYEdge
selectedItem: 0];
}
/*
* NSObject Protocol
*/

View file

@ -27,6 +27,8 @@
#import "AppKit/NSGraphics.h"
#import "AppKit/NSDragging.h"
#import "AppKit/NSPasteboard.h"
#import "AppKit/NSMenu.h"
#import "AppKit/NSOpenPanel.h"
@implementation NSPathControl
@ -224,6 +226,39 @@
return _target;
}
- (void) _doMenuAction: (id)sender
{
if (_action)
{
[self sendAction: _action
to: _target];
}
[[sender menu] close];
}
- (void) _doChooseMenuAction: (id)sender
{
NSOpenPanel *op = [NSOpenPanel openPanel];
NSArray *urls = [op URLs];
NSURL *url = [urls objectAtIndex: 0];
int result = 0;
[op setAllowsMultipleSelection: NO];
[op setCanChooseFiles: YES];
[op setCanChooseDirectories: YES];
result = [op runModalForDirectory: nil
file: nil
types: nil];
if (result == NSOKButton)
{
[self setURL: url];
}
[[sender menu] close];
}
- (void) mouseDown: (NSEvent *)event
{
if (![self isEnabled])
@ -232,10 +267,60 @@
return;
}
if (_action)
if ([self pathStyle] == NSPathStylePopUp)
{
[self sendAction: _action
to: _target];
NSPathCell *acell = (NSPathCell *)[self cell];
NSArray *array = [acell pathComponentCells];
NSMenu *menu = [[NSMenu alloc] initWithTitle: @"Select File"];
NSPathComponentCell *c = nil;
NSEnumerator *en = [array objectEnumerator];
while((c = [en nextObject]) != nil)
{
NSURL *u = [c URL];
NSString *s = [[u path] lastPathComponent];
NSMenuItem *i = [[NSMenuItem alloc] init];
[i setTitle: s];
[i setTarget: self];
[i setAction: @selector(_doMenuAction:)];
[menu insertItem: i
atIndex: 0];
}
// Add separator
[menu insertItem: [NSMenuItem separatorItem]
atIndex: 0];
// Add choose menu option
NSMenuItem *i = [[NSMenuItem alloc] init];
[i setTitle: @"Choose..."];
[i setTarget: self];
[i setAction: @selector(_doChooseMenuAction:)];
[menu insertItem: i
atIndex: 0];
if (_delegate)
{
if ([(id)_delegate respondsToSelector: @selector(pathControl:willPopUpMenu:)])
{
[_delegate pathControl: self
willPopUpMenu: menu];
}
}
[menu popUpMenuPositionItem: [menu itemAtIndex: 0]
atLocation: NSMakePoint(0.0, 0.0)
inView: self];
}
else
{
if (_action)
{
[self sendAction: _action
to: _target];
}
}
}