Fix select option

This commit is contained in:
Gregory John Casamento 2020-05-05 15:24:00 -04:00
parent dd62ab2d2c
commit 482b78d1ea
3 changed files with 60 additions and 2 deletions

View file

@ -54,7 +54,11 @@ extern "C" {
- (void) setPathStyle: (NSPathStyle)style; - (void) setPathStyle: (NSPathStyle)style;
- (NSPathStyle) pathStyle; - (NSPathStyle) pathStyle;
- (NSColor *) backgroundColor;
- (void) setBackgroundColor: (NSColor *)backgroundColor;
- (NSPathComponentCell *) clickedPathComponentCell; - (NSPathComponentCell *) clickedPathComponentCell;
- (NSArray *) pathComponentCells; - (NSArray *) pathComponentCells;
- (void) setPathComponentCells: (NSArray *)cells; - (void) setPathComponentCells: (NSArray *)cells;

View file

@ -135,7 +135,7 @@
- (NSPathComponentCell *) clickedPathComponentCell - (NSPathComponentCell *) clickedPathComponentCell
{ {
return nil; return _clickedPathComponentCell;
} }
- (NSArray *) pathComponentCells - (NSArray *) pathComponentCells

View file

@ -22,6 +22,8 @@
Boston, MA 02110 USA. Boston, MA 02110 USA.
*/ */
#import <Foundation/NSNotification.h>
#import "AppKit/NSPathControl.h" #import "AppKit/NSPathControl.h"
#import "AppKit/NSPathCell.h" #import "AppKit/NSPathCell.h"
#import "AppKit/NSGraphics.h" #import "AppKit/NSGraphics.h"
@ -29,6 +31,13 @@
#import "AppKit/NSPasteboard.h" #import "AppKit/NSPasteboard.h"
#import "AppKit/NSMenu.h" #import "AppKit/NSMenu.h"
#import "AppKit/NSOpenPanel.h" #import "AppKit/NSOpenPanel.h"
#import "AppKit/NSPathComponentCell.h"
static NSNotificationCenter *nc = nil;
@interface NSPathCell (Private)
- (void) _setClickedPathComponentCell: (NSPathComponentCell *)c;
@end
@implementation NSPathControl @implementation NSPathControl
@ -38,6 +47,7 @@
{ {
[self setVersion: 1.0]; [self setVersion: 1.0];
[self setCellClass: [NSPathCell class]]; [self setCellClass: [NSPathCell class]];
nc = [NSNotificationCenter defaultCenter];
} }
} }
@ -55,6 +65,12 @@
return self; return self;
} }
- (void) dealloc
{
RELEASE(_backgroundColor);
[super dealloc];
}
- (void) setPathStyle: (NSPathStyle)style - (void) setPathStyle: (NSPathStyle)style
{ {
[_cell setPathStyle: style]; [_cell setPathStyle: style];
@ -228,12 +244,20 @@
- (void) _doMenuAction: (id)sender - (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) if (_action)
{ {
[self sendAction: _action [self sendAction: _action
to: _target]; to: _target];
} }
[self setURL: [cc URL]];
[[sender menu] close]; [[sender menu] close];
} }
@ -246,6 +270,18 @@
[op setCanChooseFiles: YES]; [op setCanChooseFiles: YES];
[op setCanChooseDirectories: 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 result = [op runModalForDirectory: nil
file: nil file: nil
types: nil]; types: nil];
@ -309,7 +345,17 @@
willPopUpMenu: menu]; willPopUpMenu: menu];
} }
} }
if ([_cell delegate])
{
if ([(id)[_cell delegate] respondsToSelector: @selector(pathCell:willPopUpMenu:)])
{
[[_cell delegate] pathCell: _cell
willPopUpMenu: menu];
}
}
[menu popUpMenuPositionItem: [menu itemAtIndex: 0] [menu popUpMenuPositionItem: [menu itemAtIndex: 0]
atLocation: NSMakePoint(0.0, 0.0) atLocation: NSMakePoint(0.0, 0.0)
inView: self]; inView: self];
@ -394,3 +440,11 @@
} }
@end @end
@implementation NSPathCell (Private)
- (void) _setClickedPathComponentCell: (NSPathComponentCell *)c
{
_clickedPathComponentCell = c;
}
@end