Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 217 lines (160 sloc) 6.209 kB
0ad9234 @brotherbard Add Clone Repository
authored
1 //
2 // PBCloneRepositoryPanel.m
3 // GitX
4 //
5 // Created by Nathan Kinsinger on 2/7/10.
6 // Copyright 2010 Nathan Kinsinger. All rights reserved.
7 //
8
9 #import "PBCloneRepositoryPanel.h"
10 #import "PBRemoteProgressSheet.h"
11 #import "PBRepositoryDocumentController.h"
12 #import "PBGitDefaults.h"
13
14
15
16 @implementation PBCloneRepositoryPanel
17
18
19 @synthesize repositoryURL;
20 @synthesize destinationPath;
21 @synthesize errorMessage;
22 @synthesize repositoryAccessoryView;
23
17f50e3 @brotherbard Add --init and --clone to gitx CLI and Applescript
authored
24 @synthesize isBare;
25
0ad9234 @brotherbard Add Clone Repository
authored
26
27
28 #pragma mark -
29 #pragma mark PBCloneRepositoryPanel
30
31 + (id) panel
32 {
33 return [[self alloc] initWithWindowNibName:@"PBCloneRepositoryPanel"];
34 }
35
17f50e3 @brotherbard Add --init and --clone to gitx CLI and Applescript
authored
36 + (void)beginCloneRepository:(NSString *)repository toURL:(NSURL *)targetURL isBare:(BOOL)bare
37 {
38 if (!repository || [repository isEqualToString:@""] || !targetURL || [[targetURL path] isEqualToString:@""])
39 return;
40
41 PBCloneRepositoryPanel *clonePanel = [PBCloneRepositoryPanel panel];
42 [clonePanel showWindow:self];
43
44 [clonePanel.repositoryURL setStringValue:repository];
45 [clonePanel.destinationPath setStringValue:[targetURL path]];
46 clonePanel.isBare = bare;
47
48 [clonePanel clone:self];
49 }
50
0ad9234 @brotherbard Add Clone Repository
authored
51
52 - (void) awakeFromNib
53 {
54 [self window];
55 [self.errorMessage setStringValue:@""];
56 path = [PBGitDefaults recentCloneDestination];
57 if (path)
58 [self.destinationPath setStringValue:path];
59
60 browseRepositoryPanel = [NSOpenPanel openPanel];
61 [browseRepositoryPanel setTitle:@"Browse for git repository"];
62 [browseRepositoryPanel setMessage:@"Select a folder with a git repository"];
63 [browseRepositoryPanel setPrompt:@"Select"];
64 [browseRepositoryPanel setCanChooseFiles:NO];
65 [browseRepositoryPanel setCanChooseDirectories:YES];
66 [browseRepositoryPanel setAllowsMultipleSelection:NO];
67 [browseRepositoryPanel setCanCreateDirectories:NO];
68 [browseRepositoryPanel setAccessoryView:repositoryAccessoryView];
69
70 browseDestinationPanel = [NSOpenPanel openPanel];
71 [browseDestinationPanel setTitle:@"Browse clone destination"];
72 [browseDestinationPanel setMessage:@"Select a folder to clone the git repository into"];
73 [browseDestinationPanel setPrompt:@"Select"];
74 [browseDestinationPanel setCanChooseFiles:NO];
75 [browseDestinationPanel setCanChooseDirectories:YES];
76 [browseDestinationPanel setAllowsMultipleSelection:NO];
77 [browseDestinationPanel setCanCreateDirectories:YES];
78 }
79
80
81 - (void)showMessageSheet:(NSString *)messageText infoText:(NSString *)infoText
82 {
83 NSAlert *alert = [NSAlert alertWithMessageText:messageText
84 defaultButton:nil alternateButton:nil otherButton:nil
85 informativeTextWithFormat:infoText];
86
87 [alert beginSheetModalForWindow:[self window]
88 modalDelegate:self
89 didEndSelector:@selector(messageSheetDidEnd:returnCode:contextInfo:)
90 contextInfo:NULL];
91 }
92
93
94 - (void)showErrorSheet:(NSError *)error
95 {
96 [[NSAlert alertWithError:error] beginSheetModalForWindow:[self window]
97 modalDelegate:self
98 didEndSelector:@selector(errorSheetDidEnd:returnCode:contextInfo:)
99 contextInfo:NULL];
100 }
101
102
103
104 #pragma mark IBActions
105
106 - (IBAction) closeCloneRepositoryPanel:(id)sender
107 {
108 [self close];
109 }
110
111
112 - (IBAction) clone:(id)sender
113 {
114 [self.errorMessage setStringValue:@""];
115
116 NSString *url = [self.repositoryURL stringValue];
117 if ([url isEqualToString:@""]) {
118 [self.errorMessage setStringValue:@"Repository URL is required"];
119 return;
120 }
121
122 path = [self.destinationPath stringValue];
123 if ([path isEqualToString:@""]) {
124 [self.errorMessage setStringValue:@"Destination path is required"];
125 return;
126 }
127
128 NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"clone", @"--", url, path, nil];
129 if (isBare)
130 [arguments insertObject:@"--bare" atIndex:1];
131
132 NSString *description = [NSString stringWithFormat:@"Cloning repository at: %@", url];
133 NSString *title = @"Cloning Repository";
134 [PBRemoteProgressSheet beginRemoteProgressSheetForArguments:arguments title:title description:description inDir:nil windowController:self];
135 }
136
137
138 - (IBAction) browseRepository:(id)sender
139 {
140 [browseRepositoryPanel beginSheetForDirectory:nil file:nil types:nil
141 modalForWindow:[self window]
142 modalDelegate:self
143 didEndSelector:@selector(browseRepositorySheetDidEnd:returnCode:contextInfo:)
144 contextInfo:NULL];
145 }
146
147
148 - (IBAction) showHideHiddenFiles:(id)sender
149 {
150 // This uses undocumented OpenPanel features to show hidden files (required for 10.5 support)
151 NSNumber *showHidden = [NSNumber numberWithBool:[sender state] == NSOnState];
152 [[browseRepositoryPanel valueForKey:@"_navView"] setValue:showHidden forKey:@"showsHiddenFiles"];
153 }
154
155
156 - (IBAction) browseDestination:(id)sender
157 {
158 [browseDestinationPanel beginSheetForDirectory:nil file:nil types:nil
159 modalForWindow:[self window]
160 modalDelegate:self
161 didEndSelector:@selector(browseDestinationSheetDidEnd:returnCode:contextInfo:)
162 contextInfo:NULL];
163 }
164
165
166
167 #pragma mark Callbacks
168
169 - (void) browseRepositorySheetDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)code contextInfo:(void *)info
170 {
171 [sheet orderOut:self];
172
173 if (code == NSOKButton) {
174 NSURL *url = [[sheet URLs] lastObject];
175 [self.repositoryURL setStringValue:[url path]];
176 }
177 }
178
179
180 - (void) browseDestinationSheetDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)code contextInfo:(void *)info
181 {
182 [sheet orderOut:self];
183
184 if (code == NSOKButton) {
185 NSURL *url = [[sheet URLs] lastObject];
186 [self.destinationPath setStringValue:[url path]];
187 }
188 }
189
190
191 - (void) messageSheetDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)code contextInfo:(void *)info
192 {
193 NSURL *documentURL = [NSURL fileURLWithPath:path];
194
195 NSError *error = nil;
196 id document = [[PBRepositoryDocumentController sharedDocumentController] openDocumentWithContentsOfURL:documentURL display:YES error:&error];
197 if (!document && error)
198 [self showErrorSheet:error];
199 else {
200 [self close];
201
202 NSString *containingPath = [path stringByDeletingLastPathComponent];
203 [PBGitDefaults setRecentCloneDestination:containingPath];
204 [self.destinationPath setStringValue:containingPath];
205 [self.repositoryURL setStringValue:@""];
206 }
207 }
208
209
210 - (void) errorSheetDidEnd:(NSOpenPanel *)sheet returnCode:(NSInteger)code contextInfo:(void *)info
211 {
212 [self close];
213 }
214
215
216 @end
Something went wrong with that request. Please try again.