2020-04-23 04:43:15 +00:00
|
|
|
/* Implementation of class NSPathControl
|
|
|
|
Copyright (C) 2020 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
By: Gregory John Casamento
|
|
|
|
Date: Wed Apr 22 18:19:40 EDT 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.1 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-05-05 19:24:00 +00:00
|
|
|
#import <Foundation/NSNotification.h>
|
|
|
|
|
2020-04-23 04:43:15 +00:00
|
|
|
#import "AppKit/NSPathControl.h"
|
2020-04-27 03:42:44 +00:00
|
|
|
#import "AppKit/NSPathCell.h"
|
2020-04-27 18:37:22 +00:00
|
|
|
#import "AppKit/NSGraphics.h"
|
2020-05-04 09:47:00 +00:00
|
|
|
#import "AppKit/NSDragging.h"
|
|
|
|
#import "AppKit/NSPasteboard.h"
|
2020-05-04 13:50:22 +00:00
|
|
|
#import "AppKit/NSMenu.h"
|
|
|
|
#import "AppKit/NSOpenPanel.h"
|
2020-05-05 19:24:00 +00:00
|
|
|
#import "AppKit/NSPathComponentCell.h"
|
2020-05-06 06:38:01 +00:00
|
|
|
#import "AppKit/NSPathControlItem.h"
|
|
|
|
#import "AppKit/NSEvent.h"
|
2020-05-06 08:55:10 +00:00
|
|
|
#import "AppKit/NSTrackingArea.h"
|
2020-05-05 19:24:00 +00:00
|
|
|
|
|
|
|
static NSNotificationCenter *nc = nil;
|
2020-05-06 15:50:03 +00:00
|
|
|
static Class pathCellClass;
|
2020-05-05 19:24:00 +00:00
|
|
|
|
2020-05-05 19:35:35 +00:00
|
|
|
@interface NSPathCell (PathControlPrivate)
|
2020-05-05 19:24:00 +00:00
|
|
|
- (void) _setClickedPathComponentCell: (NSPathComponentCell *)c;
|
|
|
|
@end
|
2020-04-23 04:43:15 +00:00
|
|
|
|
2020-05-06 06:38:01 +00:00
|
|
|
@interface NSPathComponentCell (PathControlPrivate)
|
|
|
|
- (NSPathControlItem *) _pathControlItem;
|
|
|
|
@end
|
|
|
|
|
2020-04-23 04:43:15 +00:00
|
|
|
@implementation NSPathControl
|
|
|
|
|
2020-04-27 03:42:44 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSPathControl class])
|
|
|
|
{
|
|
|
|
[self setVersion: 1.0];
|
|
|
|
[self setCellClass: [NSPathCell class]];
|
2020-05-05 19:24:00 +00:00
|
|
|
nc = [NSNotificationCenter defaultCenter];
|
2020-04-27 03:42:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 14:52:40 +00:00
|
|
|
|
|
|
|
+ (Class) cellClass
|
|
|
|
{
|
|
|
|
return pathCellClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) setCellClass: (Class)classId
|
|
|
|
{
|
|
|
|
pathCellClass = classId;
|
|
|
|
}
|
|
|
|
|
2020-05-06 18:02:41 +00:00
|
|
|
- (void) resetCursorRects
|
2020-05-06 11:56:37 +00:00
|
|
|
{
|
|
|
|
[[self superview] removeTrackingRect: _trackingTag];
|
|
|
|
_trackingTag = [[self superview] addTrackingRect: [self frame]
|
|
|
|
owner: self
|
|
|
|
userData: nil
|
|
|
|
assumeInside: YES];
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:47:00 +00:00
|
|
|
- (instancetype) init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
[self setPathStyle: NSPathStyleStandard];
|
|
|
|
[self setURL: nil];
|
|
|
|
[self setDelegate: nil];
|
|
|
|
[self setAllowedTypes: [NSArray arrayWithObject: NSFilenamesPboardType]];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-05-05 19:24:00 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2020-05-06 11:56:37 +00:00
|
|
|
[[self superview] removeTrackingRect: _trackingTag];
|
2020-05-05 19:24:00 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2020-05-06 08:39:39 +00:00
|
|
|
- (void) mouseEntered: (NSEvent *)event
|
|
|
|
{
|
2020-05-06 11:56:37 +00:00
|
|
|
[_cell mouseEntered: event
|
|
|
|
withFrame: [self frame]
|
|
|
|
inView: self];
|
2020-05-06 08:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseExited: (NSEvent *)event
|
|
|
|
{
|
2020-05-06 11:56:37 +00:00
|
|
|
[_cell mouseExited: event
|
|
|
|
withFrame: [self frame]
|
|
|
|
inView: self];
|
2020-05-06 08:39:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 00:57:16 +00:00
|
|
|
- (void) setPathStyle: (NSPathStyle)style
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
[_cell setPathStyle: style];
|
2020-04-27 18:37:22 +00:00
|
|
|
[self setNeedsDisplay];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPathStyle) pathStyle
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
return [_cell pathStyle];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPathComponentCell *) clickedPathComponentCell
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
return [_cell clickedPathComponentCell];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) pathComponentCells
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
return [_cell pathComponentCells];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPathComponentCells: (NSArray *)cells
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
[_cell setPathComponentCells: cells];
|
2020-04-27 18:37:22 +00:00
|
|
|
[self setNeedsDisplay];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (SEL) doubleAction;
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
return [_cell doubleAction];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDoubleAction: (SEL)doubleAction
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
[_cell setDoubleAction: doubleAction];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 06:38:01 +00:00
|
|
|
- (void) _createPathItems
|
|
|
|
{
|
|
|
|
NSArray *a = [_cell pathComponentCells];
|
|
|
|
NSEnumerator *en = [a objectEnumerator];
|
|
|
|
NSPathComponentCell *c = nil;
|
|
|
|
NSMutableArray *items = [NSMutableArray arrayWithCapacity: [a count]];
|
|
|
|
|
2020-05-08 05:29:59 +00:00
|
|
|
while ((c = [en nextObject]) != nil)
|
2020-05-06 06:38:01 +00:00
|
|
|
{
|
|
|
|
NSPathControlItem *pi = [c _pathControlItem];
|
|
|
|
[items addObject: pi];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setPathItems: [items copy]];
|
|
|
|
}
|
|
|
|
|
2020-04-27 00:57:16 +00:00
|
|
|
- (NSURL *) URL
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
return [_cell URL];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setURL: (NSURL *)url
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
[_cell setURL: url];
|
2020-05-06 06:38:01 +00:00
|
|
|
[self _createPathItems];
|
2020-04-27 18:37:22 +00:00
|
|
|
[self setNeedsDisplay];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id<NSPathControlDelegate>) delegate
|
|
|
|
{
|
|
|
|
return _delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDelegate: (id<NSPathControlDelegate>) delegate
|
|
|
|
{
|
|
|
|
_delegate = delegate;
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:47:00 +00:00
|
|
|
- (NSDragOperation) draggingSourceOperationMaskForLocal: (BOOL)flag
|
|
|
|
{
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
return _localMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _remoteMask;
|
|
|
|
}
|
|
|
|
|
2020-04-27 00:57:16 +00:00
|
|
|
- (void) setDraggingSourceOperationMask: (NSDragOperation)mask
|
|
|
|
forLocal: (BOOL)local
|
|
|
|
{
|
2020-05-04 09:47:00 +00:00
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
_localMask = mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_remoteMask = mask;
|
|
|
|
}
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) allowedTypes;
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
return [_cell allowedTypes];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAllowedTypes: (NSArray *)allowedTypes
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
[_cell setAllowedTypes: allowedTypes];
|
2020-05-04 09:47:00 +00:00
|
|
|
[self registerForDraggedTypes: allowedTypes];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPathControlItem *) clickedPathItem
|
|
|
|
{
|
2020-05-06 06:38:01 +00:00
|
|
|
return [[self clickedPathComponentCell] _pathControlItem];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) pathItems
|
|
|
|
{
|
2020-05-06 15:44:54 +00:00
|
|
|
return _pathItems;
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPathItems: (NSArray *)items
|
|
|
|
{
|
2020-05-08 00:10:54 +00:00
|
|
|
NSEnumerator *en = [items objectEnumerator];
|
|
|
|
NSMutableArray *array = [NSMutableArray arrayWithCapacity: [items count]];
|
|
|
|
NSPathControlItem *item = nil;
|
|
|
|
|
|
|
|
while ((item = [en nextObject]) != nil)
|
|
|
|
{
|
|
|
|
NSPathComponentCell *cell = [[NSPathComponentCell alloc] init];
|
|
|
|
[cell setImage: [item image]];
|
|
|
|
[cell setURL: [item URL]];
|
|
|
|
[array addObject: cell];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setPathComponentCells: array];
|
2020-05-06 15:44:54 +00:00
|
|
|
ASSIGNCOPY(_pathItems, items);
|
2020-05-03 17:07:53 +00:00
|
|
|
[self setNeedsDisplay];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSAttributedString *) placeholderAttributedString
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
return [_cell placeholderAttributedString];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPlaceholderAttributedString: (NSAttributedString *)string
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
[_cell setPlaceholderAttributedString: string];
|
2020-04-27 18:37:22 +00:00
|
|
|
[self setNeedsDisplay];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) placeholderString
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
return [_cell placeholderString];
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPlaceholderString: (NSString *)string
|
|
|
|
{
|
2020-04-27 09:34:02 +00:00
|
|
|
[_cell setPlaceholderString: string];
|
2020-04-27 18:37:22 +00:00
|
|
|
[self setNeedsDisplay];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSColor *) backgroundColor
|
|
|
|
{
|
2020-05-06 11:56:37 +00:00
|
|
|
return [_cell backgroundColor];
|
2020-04-27 18:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setBackgroundColor: (NSColor *)color
|
|
|
|
{
|
2020-05-06 11:56:37 +00:00
|
|
|
[_cell setBackgroundColor: color];
|
2020-04-27 18:37:22 +00:00
|
|
|
[self setNeedsDisplay];
|
|
|
|
}
|
|
|
|
|
2020-05-04 13:50:22 +00:00
|
|
|
- (void) _doMenuAction: (id)sender
|
|
|
|
{
|
2020-05-06 14:38:24 +00:00
|
|
|
NSPathComponentCell *cc = (NSPathComponentCell *)[sender representedObject];
|
2020-05-05 19:24:00 +00:00
|
|
|
|
|
|
|
[_cell _setClickedPathComponentCell: cc];
|
2020-05-06 11:56:37 +00:00
|
|
|
if ([[self cell] action])
|
2020-05-04 13:50:22 +00:00
|
|
|
{
|
2020-05-06 11:56:37 +00:00
|
|
|
[self sendAction: [[self cell] action]
|
|
|
|
to: [[self cell] target]];
|
2020-05-04 13:50:22 +00:00
|
|
|
}
|
2020-05-05 19:24:00 +00:00
|
|
|
|
2020-05-04 13:50:22 +00:00
|
|
|
[[sender menu] close];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _doChooseMenuAction: (id)sender
|
|
|
|
{
|
|
|
|
NSOpenPanel *op = [NSOpenPanel openPanel];
|
|
|
|
int result = 0;
|
2020-05-06 15:14:31 +00:00
|
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
|
|
BOOL isDir = NO;
|
|
|
|
NSString *path = nil;
|
|
|
|
NSString *file = nil;
|
|
|
|
|
|
|
|
[fm fileExistsAtPath: [[self URL] path]
|
|
|
|
isDirectory: &isDir];
|
|
|
|
|
|
|
|
if (isDir)
|
|
|
|
{
|
|
|
|
path = [[self URL] path];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = [[[self URL] path] stringByDeletingLastPathComponent];
|
|
|
|
file = [[[self URL] path] lastPathComponent];
|
|
|
|
}
|
2020-05-04 13:50:22 +00:00
|
|
|
|
|
|
|
[op setAllowsMultipleSelection: NO];
|
|
|
|
[op setCanChooseFiles: YES];
|
|
|
|
[op setCanChooseDirectories: YES];
|
|
|
|
|
2020-05-05 19:24:00 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2020-05-06 15:14:31 +00:00
|
|
|
result = [op runModalForDirectory: path
|
|
|
|
file: file
|
2020-05-04 13:50:22 +00:00
|
|
|
types: nil];
|
|
|
|
if (result == NSOKButton)
|
|
|
|
{
|
2020-05-05 06:14:46 +00:00
|
|
|
NSArray *urls = [op URLs];
|
|
|
|
NSURL *url = [urls objectAtIndex: 0];
|
2020-05-04 13:50:22 +00:00
|
|
|
[self setURL: url];
|
|
|
|
}
|
|
|
|
|
|
|
|
[[sender menu] close];
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:47:00 +00:00
|
|
|
- (void) mouseDown: (NSEvent *)event
|
|
|
|
{
|
|
|
|
if (![self isEnabled])
|
|
|
|
{
|
|
|
|
[super mouseDown: event];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-04 13:50:22 +00:00
|
|
|
if ([self pathStyle] == NSPathStylePopUp)
|
2020-05-04 09:47:00 +00:00
|
|
|
{
|
2020-05-04 13:50:22 +00:00
|
|
|
NSPathCell *acell = (NSPathCell *)[self cell];
|
|
|
|
NSArray *array = [acell pathComponentCells];
|
2020-05-06 15:44:54 +00:00
|
|
|
NSMenu *menu = AUTORELEASE([[NSMenu alloc] initWithTitle: nil]);
|
2020-05-04 13:50:22 +00:00
|
|
|
NSPathComponentCell *c = nil;
|
|
|
|
NSEnumerator *en = [array objectEnumerator];
|
|
|
|
|
2020-05-07 03:50:37 +00:00
|
|
|
while ((c = [en nextObject]) != nil)
|
2020-05-04 13:50:22 +00:00
|
|
|
{
|
|
|
|
NSURL *u = [c URL];
|
|
|
|
NSString *s = [[u path] lastPathComponent];
|
|
|
|
NSMenuItem *i = [[NSMenuItem alloc] init];
|
|
|
|
|
|
|
|
[i setTitle: s];
|
|
|
|
[i setTarget: self];
|
|
|
|
[i setAction: @selector(_doMenuAction:)];
|
2020-05-06 14:38:24 +00:00
|
|
|
[i setRepresentedObject: c];
|
2020-05-04 13:50:22 +00:00
|
|
|
|
|
|
|
[menu insertItem: i
|
|
|
|
atIndex: 0];
|
2020-05-06 12:11:28 +00:00
|
|
|
RELEASE(i);
|
2020-05-04 13:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add separator
|
|
|
|
[menu insertItem: [NSMenuItem separatorItem]
|
|
|
|
atIndex: 0];
|
|
|
|
|
|
|
|
// Add choose menu option
|
|
|
|
NSMenuItem *i = [[NSMenuItem alloc] init];
|
2020-05-07 21:56:02 +00:00
|
|
|
[i setTitle: _(@"Choose...")];
|
2020-05-04 13:50:22 +00:00
|
|
|
[i setTarget: self];
|
|
|
|
[i setAction: @selector(_doChooseMenuAction:)];
|
|
|
|
[menu insertItem: i
|
|
|
|
atIndex: 0];
|
2020-05-06 12:11:28 +00:00
|
|
|
RELEASE(i);
|
2020-05-06 14:38:24 +00:00
|
|
|
|
|
|
|
[self setMenu: menu];
|
2020-05-04 13:50:22 +00:00
|
|
|
|
|
|
|
if (_delegate)
|
|
|
|
{
|
|
|
|
if ([(id)_delegate respondsToSelector: @selector(pathControl:willPopUpMenu:)])
|
|
|
|
{
|
|
|
|
[_delegate pathControl: self
|
|
|
|
willPopUpMenu: menu];
|
|
|
|
}
|
|
|
|
}
|
2020-05-05 19:24:00 +00:00
|
|
|
|
|
|
|
if ([_cell delegate])
|
|
|
|
{
|
|
|
|
if ([(id)[_cell delegate] respondsToSelector: @selector(pathCell:willPopUpMenu:)])
|
|
|
|
{
|
|
|
|
[[_cell delegate] pathCell: _cell
|
|
|
|
willPopUpMenu: menu];
|
|
|
|
}
|
|
|
|
}
|
2020-05-04 13:50:22 +00:00
|
|
|
|
2020-05-05 19:24:00 +00:00
|
|
|
|
2020-05-04 13:50:22 +00:00
|
|
|
[menu popUpMenuPositionItem: [menu itemAtIndex: 0]
|
|
|
|
atLocation: NSMakePoint(0.0, 0.0)
|
|
|
|
inView: self];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-06 08:39:39 +00:00
|
|
|
NSPathComponentCell *pcc = [_cell pathComponentCellAtPoint: [event locationInWindow]
|
|
|
|
withFrame: [self frame]
|
|
|
|
inView: self];
|
|
|
|
[_cell _setClickedPathComponentCell: pcc];
|
2020-05-06 11:56:37 +00:00
|
|
|
if ([[self cell] action])
|
2020-05-04 13:50:22 +00:00
|
|
|
{
|
2020-05-06 11:56:37 +00:00
|
|
|
[self sendAction: [[self cell] action]
|
|
|
|
to: [[self cell] target]];
|
2020-05-04 13:50:22 +00:00
|
|
|
}
|
2020-05-04 09:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation) draggingEntered: (id<NSDraggingInfo>)sender
|
|
|
|
{
|
2020-05-06 06:38:01 +00:00
|
|
|
if (_delegate != nil)
|
2020-05-04 09:47:00 +00:00
|
|
|
{
|
2020-05-06 12:18:32 +00:00
|
|
|
NSDragOperation dop = [_delegate pathControl: self
|
|
|
|
validateDrop: sender];
|
|
|
|
return dop;
|
|
|
|
}
|
|
|
|
|
2020-05-07 03:44:03 +00:00
|
|
|
return NSDragOperationCopy;
|
2020-05-06 12:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) performDragOperation: (id<NSDraggingInfo>)sender
|
|
|
|
{
|
|
|
|
NSPasteboard *pb = [sender draggingPasteboard];
|
|
|
|
if ([[pb types] containsObject: NSFilenamesPboardType])
|
|
|
|
{
|
|
|
|
NSArray *files = [pb propertyListForType: NSFilenamesPboardType];
|
|
|
|
if ([files count] > 0)
|
2020-05-04 09:47:00 +00:00
|
|
|
{
|
2020-05-06 12:18:32 +00:00
|
|
|
NSString *file = [files objectAtIndex: 0];
|
|
|
|
NSURL *u = [NSURL URLWithString: file];
|
2020-05-07 23:03:46 +00:00
|
|
|
BOOL accept = NO;
|
|
|
|
|
|
|
|
if ([self delegate])
|
|
|
|
{
|
|
|
|
accept = [_delegate pathControl: self
|
|
|
|
acceptDrop: sender];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
accept = YES;
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:18:32 +00:00
|
|
|
if (accept)
|
|
|
|
{
|
|
|
|
[self setURL: u];
|
|
|
|
}
|
2020-05-04 09:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-06 12:18:32 +00:00
|
|
|
return YES;
|
2020-05-04 09:47:00 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 18:37:22 +00:00
|
|
|
- (instancetype) initWithCoder: (NSKeyedUnarchiver *)coder
|
|
|
|
{
|
|
|
|
self = [super initWithCoder: coder];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
if ([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
if ([coder containsValueForKey: @"NSBackgroundColor"])
|
|
|
|
{
|
|
|
|
[self setBackgroundColor: [coder decodeObjectForKey: @"NSBackgroundColor"]];
|
|
|
|
}
|
2020-05-07 21:53:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setBackgroundColor: [NSColor windowBackgroundColor]];
|
|
|
|
}
|
2020-05-03 17:07:53 +00:00
|
|
|
|
|
|
|
if ([coder containsValueForKey: @"NSDragTypes"])
|
|
|
|
{
|
|
|
|
[self setAllowedTypes: [coder decodeObjectForKey: @"NSDragTypes"]];
|
|
|
|
}
|
2020-05-07 21:53:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setAllowedTypes: [NSArray arrayWithObject: NSFilenamesPboardType]];
|
|
|
|
}
|
|
|
|
|
2020-05-04 09:47:00 +00:00
|
|
|
if ([coder containsValueForKey: @"NSControlAction"])
|
|
|
|
{
|
|
|
|
NSString *s = [coder decodeObjectForKey: @"NSControlAction"];
|
|
|
|
[self setAction: NSSelectorFromString(s)];
|
|
|
|
}
|
|
|
|
if ([coder containsValueForKey: @"NSControlTarget"])
|
|
|
|
{
|
|
|
|
id t = [coder decodeObjectForKey: @"NSControlTarget"];
|
|
|
|
[self setTarget: t];
|
|
|
|
}
|
2020-04-27 18:37:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-06 06:56:01 +00:00
|
|
|
[self setBackgroundColor: [coder decodeObject]];
|
|
|
|
[self setAllowedTypes: [coder decodeObject]];
|
|
|
|
[self setAction: NSSelectorFromString([coder decodeObject])];
|
|
|
|
[self setTarget: [coder decodeObject]];
|
2020-04-27 18:37:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
2020-04-27 00:57:16 +00:00
|
|
|
}
|
2020-05-06 06:56:01 +00:00
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
2020-05-06 14:38:24 +00:00
|
|
|
[super encodeWithCoder: coder];
|
2020-05-06 06:56:01 +00:00
|
|
|
if ([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
[coder encodeObject: [self backgroundColor]
|
|
|
|
forKey: @"NSBackgroundColor"];
|
|
|
|
[coder encodeObject: [self allowedTypes]
|
|
|
|
forKey: @"NSDragTypes"];
|
|
|
|
[coder encodeObject: NSStringFromSelector([self action])
|
|
|
|
forKey: @"NSControlAction"];
|
|
|
|
[coder encodeObject: [self target]
|
|
|
|
forKey: @"NSControlTarget"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[coder encodeObject: [self backgroundColor]];
|
|
|
|
[coder encodeObject: [self allowedTypes]];
|
|
|
|
[coder encodeObject: NSStringFromSelector([self action])];
|
|
|
|
[coder encodeObject: [self target]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 04:43:15 +00:00
|
|
|
@end
|
|
|
|
|
2020-05-05 19:35:35 +00:00
|
|
|
@implementation NSPathCell (PathControlPrivate)
|
2020-05-05 19:24:00 +00:00
|
|
|
|
|
|
|
- (void) _setClickedPathComponentCell: (NSPathComponentCell *)c
|
|
|
|
{
|
|
|
|
_clickedPathComponentCell = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2020-05-06 06:38:01 +00:00
|
|
|
|
|
|
|
@implementation NSPathComponentCell (PathControlPrivate)
|
|
|
|
|
|
|
|
- (NSPathControlItem *) _pathControlItem
|
|
|
|
{
|
|
|
|
NSPathControlItem *pi = [[NSPathControlItem alloc] init];
|
|
|
|
NSURL *u = [self URL];
|
|
|
|
NSString *path = [u path];
|
|
|
|
|
|
|
|
[pi setImage: [self image]];
|
|
|
|
[pi setURL: u];
|
|
|
|
[pi setTitle: [path lastPathComponent]];
|
2020-05-07 03:45:25 +00:00
|
|
|
AUTORELEASE(pi);
|
|
|
|
|
2020-05-06 06:38:01 +00:00
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|