forked from dgrijalva/gitx
-
Notifications
You must be signed in to change notification settings - Fork 76
/
PBCreateTagSheet.m
117 lines (88 loc) · 3.45 KB
/
PBCreateTagSheet.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
//
// PBCreateTagSheet.m
// GitX
//
// Created by Nathan Kinsinger on 12/18/09.
// Copyright 2009 Nathan Kinsinger. All rights reserved.
//
#import "PBCreateTagSheet.h"
#import "PBGitRepository.h"
#import "PBGitCommit.h"
#import "PBGitWindowController.h"
@interface PBCreateTagSheet ()
- (void) beginCreateTagSheetAtRefish:(id <PBGitRefish>)refish inRepository:(PBGitRepository *)repo;
@end
@implementation PBCreateTagSheet
@synthesize repository;
@synthesize targetRefish;
@synthesize tagNameField;
@synthesize tagMessageText;
@synthesize errorMessageField;
@synthesize replaceExisting;
static PBCreateTagSheet *sheet;
#pragma mark -
#pragma mark PBCreateTagSheet
+ (void) beginCreateTagSheetAtRefish:(id <PBGitRefish>)refish inRepository:(PBGitRepository *)repo
{
if (!sheet) {
sheet = [[self alloc] initWithWindowNibName:@"PBCreateTagSheet"];
}
[sheet beginCreateTagSheetAtRefish:refish inRepository:repo];
}
- (void) beginCreateTagSheetAtRefish:(id <PBGitRefish>)refish inRepository:(PBGitRepository *)repo
{
self.repository = repo;
self.targetRefish = refish;
[self window]; // loads the window (if it wasn't already)
[self.errorMessageField setStringValue:@""];
[NSApp beginSheet:[self window] modalForWindow:[self.repository.windowController window] modalDelegate:self didEndSelector:nil contextInfo:NULL];
}
#pragma mark IBActions
- (IBAction) createTag:(id)sender
{
NSString *tagName = [self.tagNameField stringValue];
PBGitRef *ref = [PBGitRef refFromString:[kGitXTagRefPrefix stringByAppendingString:tagName]];
[self.errorMessageField setHidden:YES];
if (![self.repository checkRefFormat:[ref ref]]) {
[self.errorMessageField setStringValue:@"Invalid name!"];
[self.errorMessageField setHidden:NO];
return;
}
NSString *refExistsReturnMessage;
if(!self.replaceExisting && [self.repository refExists:ref checkOnRemotesWithoutBranches:NO resultMessage:&refExistsReturnMessage])
{
NSError *error = [NSError errorWithDomain:PBGitRepositoryErrorDomain
code:0
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
refExistsReturnMessage, NSLocalizedDescriptionKey,
@"Enter another tag name.", NSLocalizedRecoverySuggestionErrorKey,
nil]
];
[[NSAlert alertWithError:error]runModal];
return;
}
else
{
if (refExistsReturnMessage)
{
int returnButton = [[NSAlert alertWithMessageText:refExistsReturnMessage
defaultButton:@"Yes"
alternateButton:@"No"
otherButton:nil
informativeTextWithFormat:@"Do you still want to create the %@ %@?",[ref refishType],[ref shortName]] runModal];
if (returnButton == NSAlertAlternateReturn)
{
return;
}
}
}
[self closeCreateTagSheet:sender];
NSString *message = [self.tagMessageText string];
[self.repository createTag:tagName message:message atRefish:self.targetRefish force:self.replaceExisting];
}
- (IBAction) closeCreateTagSheet:(id)sender
{
[NSApp endSheet:[self window]];
[[self window] orderOut:self];
}
@end