Skip to content

Commit ceb4389

Browse files
lolgearlucasderraugh
authored andcommitted
Windows Separation Remastered: Clone Window Controller (#611)
* application: windows clone window controller has been added. * application: project has been updated. * application: app delegate has been cleaned up. * application: windows xibs main menu clone window has been removed. * application: windows clone window controller result unnecessary failable initializer has been removed. * application: windows clone window controller property modifiers have been changed.
1 parent 78569b8 commit ceb4389

File tree

7 files changed

+306
-118
lines changed

7 files changed

+306
-118
lines changed

GitUp/Application/AppDelegate.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
@property(nonatomic, weak) IBOutlet NSTabView* preferencesTabView;
2222
@property(nonatomic, weak) IBOutlet NSPopUpButton* channelPopUpButton;
2323
@property(nonatomic, weak) IBOutlet NSPopUpButton* themePopUpButton;
24-
25-
@property(nonatomic, strong) IBOutlet NSWindow* cloneWindow;
26-
@property(nonatomic, weak) IBOutlet NSTextField* cloneURLTextField;
27-
@property(nonatomic, weak) IBOutlet NSButton* cloneRecursiveButton;
28-
2924
+ (instancetype)sharedDelegate;
3025

3126
- (void)handleDocumentCountChanged;

GitUp/Application/AppDelegate.m

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#import "GARawTracker.h"
3131

3232
#import "AboutWindowController.h"
33+
#import "CloneWindowController.h"
3334
#import "WelcomeWindowController.h"
3435

3536
#define __ENABLE_SUDDEN_TERMINATION__ 1
@@ -44,6 +45,7 @@
4445

4546
@interface AppDelegate () <NSUserNotificationCenterDelegate, SUUpdaterDelegate>
4647
@property(nonatomic, strong) AboutWindowController *aboutWindowController;
48+
@property(nonatomic, strong) CloneWindowController *cloneWindowController;
4749
@property(nonatomic, strong) WelcomeWindowController *welcomeWindowController;
4850
@end
4951

@@ -63,6 +65,13 @@ - (AboutWindowController *)aboutWindowController {
6365
return _aboutWindowController;
6466
}
6567

68+
- (CloneWindowController *)cloneWindowController {
69+
if (!_cloneWindowController) {
70+
_cloneWindowController = [[CloneWindowController alloc] init];
71+
}
72+
return _cloneWindowController;
73+
}
74+
6675
- (WelcomeWindowController *)welcomeWindowController {
6776
if (!_welcomeWindowController) {
6877
_welcomeWindowController = [[WelcomeWindowController alloc] init];
@@ -506,41 +515,42 @@ - (IBAction)newRepository:(id)sender {
506515
}
507516

508517
- (void)_cloneRepositoryFromURLString:(NSString*)urlString {
509-
_cloneURLTextField.stringValue = urlString;
510-
_cloneRecursiveButton.state = NSOnState;
511-
if ([NSApp runModalForWindow:_cloneWindow] && _cloneURLTextField.stringValue.length) {
512-
NSURL* url = GCURLFromGitURL(_cloneURLTextField.stringValue);
513-
if (url) {
514-
NSString* name = [url.path.lastPathComponent stringByDeletingPathExtension];
515-
NSSavePanel* savePanel = [NSSavePanel savePanel];
516-
savePanel.title = NSLocalizedString(@"Clone Repository", nil);
517-
savePanel.prompt = NSLocalizedString(@"Clone", nil);
518-
savePanel.nameFieldLabel = NSLocalizedString(@"Name:", nil);
519-
savePanel.nameFieldStringValue = name ? name : @"";
520-
savePanel.showsTagField = NO;
521-
if ([savePanel runModal] == NSFileHandlingPanelOKButton) {
522-
NSString* path = savePanel.URL.path;
523-
NSError* error;
524-
if (![[NSFileManager defaultManager] fileExistsAtPath:path followLastSymlink:NO] || [[NSFileManager defaultManager] moveItemAtPathToTrash:path error:&error]) {
525-
GCRepository* repository = [[GCRepository alloc] initWithNewLocalRepository:path bare:NO error:&error];
526-
if (repository) {
527-
if ([repository addRemoteWithName:@"origin" url:url error:&error]) {
528-
[self _openRepositoryWithURL:[NSURL fileURLWithPath:repository.workingDirectoryPath] withCloneMode:(_cloneRecursiveButton.state ? kCloneMode_Recursive : kCloneMode_Default)windowModeID:NSNotFound];
529-
} else {
530-
[NSApp presentError:error];
531-
[[NSFileManager defaultManager] removeItemAtPath:path error:NULL]; // Ignore errors
532-
}
533-
} else {
534-
[NSApp presentError:error];
535-
}
536-
} else {
537-
[NSApp presentError:error];
538-
}
539-
}
540-
} else {
518+
[self.cloneWindowController runModalForURL:urlString completion:^(CloneWindowControllerResult * _Nonnull result) {
519+
if (result.invalidRepository) {
541520
[NSApp presentError:MAKE_ERROR(@"Invalid Git repository URL")];
521+
return;
542522
}
543-
}
523+
524+
if (result.emptyDirectoryPath) {
525+
return;
526+
}
527+
528+
NSURL* url = result.repositoryURL;
529+
NSString* path = result.directoryPath;
530+
CloneMode cloneMode = result.recursive ? kCloneMode_Recursive : kCloneMode_Default;
531+
NSError* error;
532+
533+
BOOL fileDoesntExistOrEvictedToTrash = ![[NSFileManager defaultManager] fileExistsAtPath:path followLastSymlink:NO] || [[NSFileManager defaultManager] moveItemAtPathToTrash:path error:&error];
534+
535+
if (!fileDoesntExistOrEvictedToTrash) {
536+
[NSApp presentError:error];
537+
return;
538+
}
539+
540+
GCRepository* repository = [[GCRepository alloc] initWithNewLocalRepository:path bare:NO error:&error];
541+
if (!repository) {
542+
[NSApp presentError:error];
543+
return;
544+
}
545+
546+
if ([repository addRemoteWithName:@"origin" url:url error:&error]) {
547+
[self _openRepositoryWithURL:[NSURL fileURLWithPath:repository.workingDirectoryPath] withCloneMode:cloneMode windowModeID:NSNotFound];
548+
} else {
549+
[NSApp presentError:error];
550+
[[NSFileManager defaultManager] removeItemAtPath:path error:NULL]; // Ignore errors
551+
}
552+
553+
}];
544554
}
545555

546556
- (IBAction)cloneRepository:(id)sender {
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
3+
<dependencies>
4+
<deployment identifier="macosx"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15505"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<objects>
9+
<customObject id="-2" userLabel="File's Owner" customClass="CloneWindowController">
10+
<connections>
11+
<outlet property="cloneRecursiveButton" destination="V3d-LG-L26" id="vch-Du-0Ut"/>
12+
<outlet property="urlTextField" destination="KgY-GJ-dY0" id="I60-hS-oGZ"/>
13+
<outlet property="window" destination="6SP-eN-0Kv" id="fVR-oh-RCy"/>
14+
</connections>
15+
</customObject>
16+
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
17+
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
18+
<window title="Clone Repository" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="6SP-eN-0Kv">
19+
<windowStyleMask key="styleMask" titled="YES"/>
20+
<rect key="contentRect" x="131" y="158" width="502" height="167"/>
21+
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
22+
<view key="contentView" id="Msr-na-RRU">
23+
<rect key="frame" x="0.0" y="0.0" width="502" height="167"/>
24+
<autoresizingMask key="autoresizingMask"/>
25+
<subviews>
26+
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="KgY-GJ-dY0">
27+
<rect key="frame" x="104" y="126" width="378" height="21"/>
28+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="Required" drawsBackground="YES" id="QXH-ou-KWa">
29+
<font key="font" metaFont="system"/>
30+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
31+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
32+
</textFieldCell>
33+
</textField>
34+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="G2f-8q-uIU">
35+
<rect key="frame" x="18" y="128" width="80" height="16"/>
36+
<constraints>
37+
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="76" id="g1r-5V-s1c"/>
38+
</constraints>
39+
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Clone URL:" id="1V7-UU-BXR">
40+
<font key="font" metaFont="system"/>
41+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
42+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
43+
</textFieldCell>
44+
</textField>
45+
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="MbF-lm-4Vc">
46+
<rect key="frame" x="102" y="89" width="382" height="28"/>
47+
<textFieldCell key="cell" controlSize="small" sendsActionOnEndEditing="YES" alignment="left" title="Enter a Git URL like &quot;https://example.com/repositories/example.git&quot; or &quot;[email protected]:repositories/example.git&quot;." id="EFG-t2-f6c">
48+
<font key="font" metaFont="menu" size="11"/>
49+
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
50+
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
51+
</textFieldCell>
52+
</textField>
53+
<button translatesAutoresizingMaskIntoConstraints="NO" id="V3d-LG-L26">
54+
<rect key="frame" x="102" y="65" width="382" height="18"/>
55+
<buttonCell key="cell" type="check" title="Initialize and clone submodules automatically" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="X4y-Bk-C2g">
56+
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
57+
<font key="font" metaFont="system"/>
58+
</buttonCell>
59+
</button>
60+
<button verticalHuggingPriority="750" tag="1" translatesAutoresizingMaskIntoConstraints="NO" id="nd4-Yg-sbG">
61+
<rect key="frame" x="393" y="13" width="95" height="32"/>
62+
<buttonCell key="cell" type="push" title="Continue" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="dOr-TN-HvE">
63+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
64+
<font key="font" metaFont="system"/>
65+
<string key="keyEquivalent" base64-UTF8="YES">
66+
DQ
67+
</string>
68+
</buttonCell>
69+
<connections>
70+
<action selector="dismissModal:" target="-2" id="N95-8T-ucZ"/>
71+
</connections>
72+
</button>
73+
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="KUn-Ed-CKb">
74+
<rect key="frame" x="311" y="13" width="82" height="32"/>
75+
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="CCL-f6-Fl1">
76+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
77+
<font key="font" metaFont="system"/>
78+
<string key="keyEquivalent" base64-UTF8="YES">
79+
Gw
80+
</string>
81+
</buttonCell>
82+
<connections>
83+
<action selector="dismissModal:" target="-2" id="VN4-Yo-oOY"/>
84+
</connections>
85+
</button>
86+
</subviews>
87+
<constraints>
88+
<constraint firstItem="MbF-lm-4Vc" firstAttribute="trailing" secondItem="KgY-GJ-dY0" secondAttribute="trailing" id="3aH-hK-7rh"/>
89+
<constraint firstAttribute="bottom" secondItem="nd4-Yg-sbG" secondAttribute="bottom" constant="20" id="BwP-fi-rEQ"/>
90+
<constraint firstItem="V3d-LG-L26" firstAttribute="top" secondItem="MbF-lm-4Vc" secondAttribute="bottom" constant="8" id="MTn-iZ-HcU"/>
91+
<constraint firstItem="KgY-GJ-dY0" firstAttribute="leading" secondItem="G2f-8q-uIU" secondAttribute="trailing" constant="8" id="MWQ-Rr-rs4"/>
92+
<constraint firstItem="G2f-8q-uIU" firstAttribute="leading" secondItem="Msr-na-RRU" secondAttribute="leading" constant="20" id="P15-QE-Bpj"/>
93+
<constraint firstItem="KgY-GJ-dY0" firstAttribute="top" secondItem="Msr-na-RRU" secondAttribute="top" constant="20" id="Plk-9h-K5n"/>
94+
<constraint firstAttribute="trailing" secondItem="KgY-GJ-dY0" secondAttribute="trailing" constant="20" id="QzC-o0-bsr"/>
95+
<constraint firstItem="KUn-Ed-CKb" firstAttribute="bottom" secondItem="nd4-Yg-sbG" secondAttribute="bottom" id="Uec-Og-jSY"/>
96+
<constraint firstItem="MbF-lm-4Vc" firstAttribute="leading" secondItem="V3d-LG-L26" secondAttribute="leading" id="ejl-9K-FCA"/>
97+
<constraint firstItem="MbF-lm-4Vc" firstAttribute="leading" secondItem="KgY-GJ-dY0" secondAttribute="leading" id="fG8-lm-FTO"/>
98+
<constraint firstAttribute="trailing" secondItem="nd4-Yg-sbG" secondAttribute="trailing" constant="20" id="iZz-yh-1rZ"/>
99+
<constraint firstItem="MbF-lm-4Vc" firstAttribute="trailing" secondItem="V3d-LG-L26" secondAttribute="trailing" id="jcm-bJ-Bwg"/>
100+
<constraint firstItem="MbF-lm-4Vc" firstAttribute="top" secondItem="KgY-GJ-dY0" secondAttribute="bottom" constant="9" id="m7p-hb-G6H"/>
101+
<constraint firstItem="G2f-8q-uIU" firstAttribute="top" secondItem="Msr-na-RRU" secondAttribute="top" constant="23" id="pcC-Md-ozG"/>
102+
<constraint firstItem="nd4-Yg-sbG" firstAttribute="top" relation="greaterThanOrEqual" secondItem="V3d-LG-L26" secondAttribute="bottom" constant="26" id="rQD-4k-Nyl"/>
103+
<constraint firstItem="nd4-Yg-sbG" firstAttribute="leading" secondItem="KUn-Ed-CKb" secondAttribute="trailing" constant="12" id="vHR-O2-LaP"/>
104+
<constraint firstItem="KUn-Ed-CKb" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="Msr-na-RRU" secondAttribute="leading" constant="317" id="zcO-UE-N8u"/>
105+
</constraints>
106+
</view>
107+
<point key="canvasLocation" x="-716" y="966.5"/>
108+
</window>
109+
</objects>
110+
</document>

0 commit comments

Comments
 (0)