From 482b78d1ea7ebac2afddd8e7608a345699637da0 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 5 May 2020 15:24:00 -0400 Subject: [PATCH] Fix select option --- Headers/AppKit/NSPathControl.h | 4 +++ Source/NSPathCell.m | 2 +- Source/NSPathControl.m | 56 +++++++++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Headers/AppKit/NSPathControl.h b/Headers/AppKit/NSPathControl.h index 84945e359..6392cc968 100644 --- a/Headers/AppKit/NSPathControl.h +++ b/Headers/AppKit/NSPathControl.h @@ -54,7 +54,11 @@ extern "C" { - (void) setPathStyle: (NSPathStyle)style; - (NSPathStyle) pathStyle; +- (NSColor *) backgroundColor; +- (void) setBackgroundColor: (NSColor *)backgroundColor; + - (NSPathComponentCell *) clickedPathComponentCell; + - (NSArray *) pathComponentCells; - (void) setPathComponentCells: (NSArray *)cells; diff --git a/Source/NSPathCell.m b/Source/NSPathCell.m index c07025ba7..019d627f2 100644 --- a/Source/NSPathCell.m +++ b/Source/NSPathCell.m @@ -135,7 +135,7 @@ - (NSPathComponentCell *) clickedPathComponentCell { - return nil; + return _clickedPathComponentCell; } - (NSArray *) pathComponentCells diff --git a/Source/NSPathControl.m b/Source/NSPathControl.m index c11c01171..39aa5b60b 100644 --- a/Source/NSPathControl.m +++ b/Source/NSPathControl.m @@ -22,6 +22,8 @@ Boston, MA 02110 USA. */ +#import + #import "AppKit/NSPathControl.h" #import "AppKit/NSPathCell.h" #import "AppKit/NSGraphics.h" @@ -29,6 +31,13 @@ #import "AppKit/NSPasteboard.h" #import "AppKit/NSMenu.h" #import "AppKit/NSOpenPanel.h" +#import "AppKit/NSPathComponentCell.h" + +static NSNotificationCenter *nc = nil; + +@interface NSPathCell (Private) +- (void) _setClickedPathComponentCell: (NSPathComponentCell *)c; +@end @implementation NSPathControl @@ -38,6 +47,7 @@ { [self setVersion: 1.0]; [self setCellClass: [NSPathCell class]]; + nc = [NSNotificationCenter defaultCenter]; } } @@ -55,6 +65,12 @@ return self; } +- (void) dealloc +{ + RELEASE(_backgroundColor); + [super dealloc]; +} + - (void) setPathStyle: (NSPathStyle)style { [_cell setPathStyle: style]; @@ -228,12 +244,20 @@ - (void) _doMenuAction: (id)sender { + NSArray *cells = [self pathComponentCells]; + NSUInteger c = [cells count]; + NSUInteger i = [[sender menu] indexOfItem: sender]; + NSUInteger ci = (c - i) + 1; + NSPathComponentCell *cc = [cells objectAtIndex: ci]; + + [_cell _setClickedPathComponentCell: cc]; if (_action) { [self sendAction: _action to: _target]; } - + + [self setURL: [cc URL]]; [[sender menu] close]; } @@ -246,6 +270,18 @@ [op setCanChooseFiles: YES]; [op setCanChooseDirectories: YES]; + if ([(id)_delegate respondsToSelector: @selector(pathCell:willPopUpMenu:)]) + { + [_delegate pathControl: self + willDisplayOpenPanel: op]; + } + + if ([(id)[_cell delegate] respondsToSelector: @selector(pathCell:willPopUpMenu:)]) + { + [[_cell delegate] pathCell: _cell + willDisplayOpenPanel: op]; + } + result = [op runModalForDirectory: nil file: nil types: nil]; @@ -309,7 +345,17 @@ willPopUpMenu: menu]; } } + + if ([_cell delegate]) + { + if ([(id)[_cell delegate] respondsToSelector: @selector(pathCell:willPopUpMenu:)]) + { + [[_cell delegate] pathCell: _cell + willPopUpMenu: menu]; + } + } + [menu popUpMenuPositionItem: [menu itemAtIndex: 0] atLocation: NSMakePoint(0.0, 0.0) inView: self]; @@ -394,3 +440,11 @@ } @end +@implementation NSPathCell (Private) + +- (void) _setClickedPathComponentCell: (NSPathComponentCell *)c +{ + _clickedPathComponentCell = c; +} + +@end