forked from dempseyatgithub/BuildSettingExtractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragFileView.m
More file actions
83 lines (67 loc) · 2.28 KB
/
Copy pathDragFileView.m
File metadata and controls
83 lines (67 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// DragFileView.m
// BuildSettingExtractor
//
// Created by James Dempsey on 1/30/15.
// Copyright (c) 2015 Tapas Software. All rights reserved.
//
#import "DragFileView.h"
#import "AppConstants+Categories.h"
#import "Constants+Categories.h"
@interface DragFileView ()
@property NSURL *fileURL;
@property (weak) IBOutlet NSTextField *labelView;
@end
@implementation DragFileView
- (void)commonInit {
self.boxType = NSBoxCustom;
self.cornerRadius = 20.0;
self.borderWidth = 0.0;
[self setHighlight:NO];
[self registerForDraggedTypes:@[(NSString *)kUTTypeFileURL]];
}
- (instancetype)initWithCoder:(NSCoder *)coder {
if (self = [super initWithCoder:coder]) { [self commonInit]; } return self;
}
- (instancetype)initWithFrame:(NSRect)frameRect {
if (self = [super initWithFrame:frameRect]) { [self commonInit]; } return self;
}
- (void)setHighlight:(BOOL)flag {
if (flag) {
if (@available(macOS 10.14, *)) {
self.fillColor = [[NSColor colorNamed: @"dragViewBackgroundColor"] colorWithSystemEffect:NSColorSystemEffectPressed];
} else {
self.fillColor = [NSColor colorWithCalibratedRed:0.56 green:0.7 blue:0.81 alpha:1.0];
}
} else {
if (@available(macOS 10.13, *)) {
self.fillColor = [NSColor colorNamed: @"dragViewBackgroundColor"];
} else {
self.fillColor = [NSColor colorWithCalibratedRed:0.7 green:0.85 blue:1.0 alpha:1.0];
}
}
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
BOOL canRead = [[sender draggingPasteboard] tps_canReadXcodeProjectFileURL];
if (canRead) {
[self setHighlight:YES];
return NSDragOperationGeneric;
} else {
return NSDragOperationNone;
}
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
[self setHighlight:NO];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
return [[sender draggingPasteboard] tps_canReadXcodeProjectFileURL];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
self.fileURL = [[sender draggingPasteboard] tps_readXcodeProjectFileURL];
return self.fileURL != nil;
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender {
[self setHighlight:NO];
[NSApp sendAction:self.action to:self.target from:self];
}
@end