forked from laullon/gitx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PBAddRemoteSheet.m
142 lines (96 loc) · 3.23 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
//
// 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;
- (void) openAddRemoteSheet;
@end
@implementation PBAddRemoteSheet
@synthesize repository;
@synthesize remoteName;
@synthesize remoteURL;
@synthesize errorMessage;
@synthesize browseSheet;
@synthesize browseAccessoryView;
#pragma mark -
#pragma mark PBAddRemoteSheet
+ (void) beginAddRemoteSheetForRepository:(PBGitRepository *)repo
{
PBAddRemoteSheet *sheet = [[self alloc] initWithWindowNibName:@"PBAddRemoteSheet"];
[sheet beginAddRemoteSheetForRepository:repo];
}
- (void) beginAddRemoteSheetForRepository:(PBGitRepository *)repo
{
self.repository = repo;
[self window];
[self openAddRemoteSheet];
}
- (void) openAddRemoteSheet
{
[self.errorMessage setStringValue:@""];
[NSApp beginSheet:[self window] modalForWindow:[self.repository.windowController window] modalDelegate:self didEndSelector:nil contextInfo:NULL];
}
- (void) browseSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)code contextInfo:(void *)info
{
[sheet orderOut:self];
if (code == NSOKButton)
[self.remoteURL setStringValue:[(NSOpenPanel *)sheet filename]];
[self openAddRemoteSheet];
}
#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 beginSheetForDirectory:nil file:nil types:nil
modalForWindow:[self.repository.windowController window]
modalDelegate:self
didEndSelector:@selector(browseSheetDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
- (IBAction) addRemote:(id)sender
{
[self.errorMessage setStringValue:@""];
NSString *name = [[self.remoteName stringValue] copy];
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] copy];
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
{
// This uses undocumented OpenPanel features to show hidden files (required for 10.5 support)
NSNumber *showHidden = [NSNumber numberWithBool:[sender state] == NSOnState];
[[self.browseSheet valueForKey:@"_navView"] setValue:showHidden forKey:@"showsHiddenFiles"];
}
@end