forked from dgrijalva/gitx
-
Notifications
You must be signed in to change notification settings - Fork 76
/
PBAddRemoteSheet.m
146 lines (103 loc) · 3.21 KB
/
PBAddRemoteSheet.m
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
// PBAddRemoteSheet.m
// GitX
//
// Created by Nathan Kinsinger on 12/8/09.
// Copyright 2009 Nathan Kinsinger. All rights reserved.
//
#import "PBAddRemoteSheet.h"
#import "PBGitWindowController.h"
#import "PBGitRepository.h"
@interface PBAddRemoteSheet ()
- (void) beginAddRemoteSheetForRepository:(PBGitRepository *)repo withRemoteURL:(NSString*)url;
- (void) openAddRemoteSheet;
@end
@implementation PBAddRemoteSheet
@synthesize repository;
@synthesize remoteName;
@synthesize remoteURL;
@synthesize errorMessage;
@synthesize browseSheet;
@synthesize browseAccessoryView;
static PBAddRemoteSheet *sheet;
#pragma mark -
#pragma mark PBAddRemoteSheet
+ (void) beginAddRemoteSheetForRepository:(PBGitRepository *)repo withRemoteURL:(NSString*)url;
{
if(!sheet){
sheet = [[self alloc] initWithWindowNibName:@"PBAddRemoteSheet"];
}
[sheet beginAddRemoteSheetForRepository:repo withRemoteURL:url];
}
- (void) beginAddRemoteSheetForRepository:(PBGitRepository *)repo withRemoteURL:(NSString*)url
{
self.repository = repo;
remoteUrl = url;
[self window];
[self openAddRemoteSheet];
}
- (void) openAddRemoteSheet
{
[self.errorMessage setStringValue:@""];
if (remoteUrl)
{
[remoteURL setStringValue:remoteUrl];
[remoteURL setEnabled:NO];
}
[NSApp beginSheet:[self window] modalForWindow:[self.repository.windowController window] modalDelegate:self didEndSelector:nil contextInfo:NULL];
}
#pragma mark IBActions
- (IBAction) browseFolders:(id)sender
{
[self orderOutAddRemoteSheet:nil];
self.browseSheet = [NSOpenPanel openPanel];
[browseSheet setTitle:@"Add remote"];
[browseSheet setMessage:@"Select a folder with a git repository"];
[browseSheet setCanChooseFiles:NO];
[browseSheet setCanChooseDirectories:YES];
[browseSheet setAllowsMultipleSelection:NO];
[browseSheet setCanCreateDirectories:NO];
[browseSheet setAccessoryView:browseAccessoryView];
[browseSheet beginSheetModalForWindow:[self.repository.windowController window]
completionHandler:
^(NSInteger result)
{
[browseSheet orderOut:self];
if (result == NSFileHandlingPanelOKButton)
{
[self.remoteURL setStringValue:[[browseSheet URL] path]];
}
[self openAddRemoteSheet];
}
];
}
- (IBAction) addRemote:(id)sender
{
[self.errorMessage setStringValue:@""];
NSString *name = [self.remoteName stringValue];
if ([name isEqualToString:@""]) {
[self.errorMessage setStringValue:@"Remote name is required"];
return;
}
if (![self.repository checkRefFormat:[@"refs/remotes/" stringByAppendingString:name]]) {
[self.errorMessage setStringValue:@"Invalid remote name"];
return;
}
NSString *url = [self.remoteURL stringValue];
if ([url isEqualToString:@""]) {
[self.errorMessage setStringValue:@"Remote URL is required"];
return;
}
[self orderOutAddRemoteSheet:self];
[self.repository beginAddRemote:name forURL:url];
}
- (IBAction) orderOutAddRemoteSheet:(id)sender
{
[NSApp endSheet:[self window]];
[[self window] orderOut:self];
}
- (IBAction) showHideHiddenFiles:(id)sender
{
[self.browseSheet setShowsHiddenFiles:[sender state]];
}
@end