Skip to content

Commit 15f317b

Browse files
lolgearlucasderraugh
authored andcommitted
Drag and drop to welcome window (#571)
Welcome Window accepts drag and drop of folders with git repos - Main GitUp icon is currently taking the drag and drop and needs to have it's drag types removed. Follow up with future commit.
1 parent d1a831b commit 15f317b

File tree

5 files changed

+160
-27
lines changed

5 files changed

+160
-27
lines changed

GitUp/Application/AppDelegate.m

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,6 @@
4040
#define kToolInstallPath @"/usr/local/bin/" kToolName
4141

4242
@interface AppDelegate () <NSUserNotificationCenterDelegate, SUUpdaterDelegate>
43-
- (IBAction)closeWelcomeWindow:(id)sender;
44-
@end
45-
46-
@interface WelcomeWindow : NSWindow
47-
@end
48-
49-
@implementation WelcomeWindow
50-
51-
- (void)awakeFromNib {
52-
self.opaque = NO;
53-
self.backgroundColor = [NSColor clearColor];
54-
self.movableByWindowBackground = YES;
55-
}
56-
57-
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
58-
return menuItem.action == @selector(performClose:) ? YES : [super validateMenuItem:menuItem];
59-
}
60-
61-
- (void)performClose:(id)sender {
62-
[[AppDelegate sharedDelegate] closeWelcomeWindow:sender];
63-
}
64-
65-
- (BOOL)canBecomeKeyWindow {
66-
return YES;
67-
}
68-
6943
@end
7044

7145
@implementation AppDelegate {

GitUp/Application/Base.lproj/MainMenu.xib

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ UI design by Wayne Fan</string>
11401140
<box boxType="custom" borderType="none" borderWidth="0.0" cornerRadius="10" title="Box" titlePosition="noTitle" id="UoN-n1-xSr">
11411141
<rect key="frame" x="0.0" y="0.0" width="280" height="349"/>
11421142
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1143-
<view key="contentView" id="UVs-2r-EAT">
1143+
<view key="contentView" id="UVs-2r-EAT" customClass="WelcomeWindowView">
11441144
<rect key="frame" x="0.0" y="0.0" width="280" height="349"/>
11451145
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
11461146
<subviews>
@@ -1284,6 +1284,9 @@ UI design by Wayne Fan</string>
12841284
</box>
12851285
</subviews>
12861286
</view>
1287+
<connections>
1288+
<outlet property="destinationView" destination="UVs-2r-EAT" id="AvQ-6L-KSz"/>
1289+
</connections>
12871290
<point key="canvasLocation" x="-252" y="578.5"/>
12881291
</window>
12891292
<userDefaultsController representsSharedInstance="YES" id="AR1-cq-KNa"/>

GitUp/Application/WelcomeWindow.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// WelcomeWindow.h
3+
// Application
4+
//
5+
// Created by Dmitry Lobanov on 10/09/2019.
6+
//
7+
8+
#import <Cocoa/Cocoa.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
@interface WelcomeWindow : NSWindow
13+
14+
@end
15+
16+
NS_ASSUME_NONNULL_END

GitUp/Application/WelcomeWindow.m

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//
2+
// WelcomeWindow.m
3+
// Application
4+
//
5+
// Created by Dmitry Lobanov on 10/09/2019.
6+
//
7+
8+
#import "WelcomeWindow.h"
9+
10+
#import "AppDelegate.h"
11+
#import "Document.h"
12+
13+
@interface AppDelegate (WelcomeWindow)
14+
- (IBAction)closeWelcomeWindow:(id)sender;
15+
- (void)_openRepositoryWithURL:(NSURL*)url withCloneMode:(CloneMode)cloneMode windowModeID:(WindowModeID)windowModeID;
16+
@end
17+
18+
@interface WelcomeWindowView : NSView <NSDraggingDestination>
19+
@property (weak, nonatomic, readonly) AppDelegate *appDelegate;
20+
@property (assign, nonatomic) BOOL receivingDrag;
21+
@end
22+
23+
@implementation WelcomeWindowView
24+
25+
#pragma mark - Accessors
26+
- (AppDelegate *)appDelegate {
27+
return [AppDelegate sharedDelegate];
28+
}
29+
30+
#pragma mark - Setup
31+
- (void)setup {
32+
[self registerForDraggedTypes:@[NSURLPboardType]];
33+
}
34+
35+
- (void)awakeFromNib {
36+
[super awakeFromNib];
37+
[self setup];
38+
}
39+
40+
#pragma mark - Drawing
41+
- (void)setReceivingDrag:(BOOL)receivingDrag {
42+
_receivingDrag = receivingDrag;
43+
[self setNeedsDisplay:YES];
44+
}
45+
46+
- (void)drawRect:(NSRect)dirtyRect {
47+
if (self.receivingDrag) {
48+
[NSColor.selectedControlColor set];
49+
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:self.bounds xRadius:10 yRadius:10];
50+
path.lineWidth = 5;
51+
[path stroke];
52+
}
53+
}
54+
55+
#pragma mark - Dragging Data Extraction
56+
- (BOOL)canDragItem:(id<NSDraggingInfo>)sender {
57+
return [self draggingItems:sender].count > 0;
58+
}
59+
60+
- (NSArray <NSURL *>*)draggingItems:(id<NSDraggingInfo>)sender {
61+
return [[sender draggingPasteboard] readObjectsForClasses:@[NSURL.class] options:nil];
62+
}
63+
64+
#pragma mark - NSDraggingDestination
65+
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
66+
BOOL canDragItem = [self canDragItem:sender];
67+
self.receivingDrag = canDragItem;
68+
return canDragItem ? NSDragOperationCopy : NSDragOperationNone;
69+
}
70+
71+
- (void)draggingEnded:(id<NSDraggingInfo>)sender {
72+
self.receivingDrag = NO;
73+
}
74+
75+
- (void)draggingExited:(id<NSDraggingInfo>)sender {
76+
self.receivingDrag = NO;
77+
}
78+
79+
- (BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender {
80+
return [self canDragItem:sender];
81+
}
82+
83+
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
84+
self.receivingDrag = NO;
85+
86+
NSURL *first = [self draggingItems:sender].firstObject;
87+
[self.appDelegate _openRepositoryWithURL:first withCloneMode:kCloneMode_None windowModeID:NSNotFound];
88+
89+
return YES;
90+
}
91+
92+
- (void)concludeDragOperation:(id<NSDraggingInfo>)sender {
93+
// necessary cleanup?
94+
}
95+
@end
96+
97+
@interface WelcomeWindow ()
98+
@property (weak, nonatomic, readonly) AppDelegate *appDelegate;
99+
@property (weak, nonatomic, readwrite) IBOutlet WelcomeWindowView *destinationView;
100+
@end
101+
102+
@implementation WelcomeWindow
103+
104+
#pragma mark - Accessors
105+
- (AppDelegate *)appDelegate {
106+
return [AppDelegate sharedDelegate];
107+
}
108+
109+
#pragma mark - Setup
110+
- (void)setup {
111+
self.opaque = NO;
112+
self.backgroundColor = [NSColor clearColor];
113+
self.movableByWindowBackground = YES;
114+
}
115+
116+
- (void)awakeFromNib {
117+
[self setup];
118+
}
119+
120+
#pragma mark - Actions
121+
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
122+
return menuItem.action == @selector(performClose:) ? YES : [super validateMenuItem:menuItem];
123+
}
124+
125+
- (void)performClose:(id)sender {
126+
[self.appDelegate closeWelcomeWindow:sender];
127+
}
128+
129+
#pragma mark - Window
130+
- (BOOL)canBecomeKeyWindow {
131+
return YES;
132+
}
133+
134+
@end

GitUp/GitUp.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
0AD4625B232711B000BE28D1 /* WelcomeWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 0AD4625A232711B000BE28D1 /* WelcomeWindow.m */; };
1011
0AE7F5F12312C1B000B06050 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0AE7F5ED2312C1B000B06050 /* InfoPlist.strings */; };
1112
165C32B61B95739700D2F894 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 165C32B51B95739700D2F894 /* QuartzCore.framework */; };
1213
31CD50E3203E2E2800360B3A /* ToolbarItemWrapperView.m in Sources */ = {isa = PBXBuildFile; fileRef = 31CD50E2203E2E2800360B3A /* ToolbarItemWrapperView.m */; };
@@ -107,6 +108,8 @@
107108
/* End PBXCopyFilesBuildPhase section */
108109

109110
/* Begin PBXFileReference section */
111+
0AD46259232711B000BE28D1 /* WelcomeWindow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WelcomeWindow.h; sourceTree = "<group>"; };
112+
0AD4625A232711B000BE28D1 /* WelcomeWindow.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WelcomeWindow.m; sourceTree = "<group>"; };
110113
0AE7F5EE2312C1B000B06050 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
111114
165C32B51B95739700D2F894 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
112115
31CD50E1203E2E2800360B3A /* ToolbarItemWrapperView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ToolbarItemWrapperView.h; sourceTree = "<group>"; };
@@ -276,6 +279,8 @@
276279
E2C5672C1A6D98BC00ECFE07 /* WindowController.m */,
277280
31CD50E1203E2E2800360B3A /* ToolbarItemWrapperView.h */,
278281
31CD50E2203E2E2800360B3A /* ToolbarItemWrapperView.m */,
282+
0AD46259232711B000BE28D1 /* WelcomeWindow.h */,
283+
0AD4625A232711B000BE28D1 /* WelcomeWindow.m */,
279284
);
280285
path = Application;
281286
sourceTree = "<group>";
@@ -432,6 +437,7 @@
432437
E2C5672D1A6D98BC00ECFE07 /* WindowController.m in Sources */,
433438
E2C338B219F8562F00063D95 /* AppDelegate.m in Sources */,
434439
E2C338B719F8562F00063D95 /* Document.m in Sources */,
440+
0AD4625B232711B000BE28D1 /* WelcomeWindow.m in Sources */,
435441
31CD50E3203E2E2800360B3A /* ToolbarItemWrapperView.m in Sources */,
436442
);
437443
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)