forked from pieter/gitx
-
Notifications
You must be signed in to change notification settings - Fork 4
/
PBCreateTagSheet.m
93 lines (63 loc) · 2.15 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
//
// 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"
@interface PBCreateTagSheet ()
- (void) beginCreateTagSheetAtRefish:(id <PBGitRefish>)refish inRepository:(PBGitRepository *)repo;
@end
@implementation PBCreateTagSheet
@synthesize repository;
@synthesize targetRefish;
@synthesize tagNameField;
@synthesize tagMessageText;
@synthesize errorMessageField;
#pragma mark -
#pragma mark PBCreateTagSheet
+ (void) beginCreateTagSheetAtRefish:(id <PBGitRefish>)refish inRepository:(PBGitRepository *)repo
{
PBCreateTagSheet *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];
[self.errorMessageField setHidden:YES];
NSString *refName = [@"refs/tags/" stringByAppendingString:tagName];
if (![self.repository checkRefFormat:refName]) {
[self.errorMessageField setStringValue:@"Invalid name"];
[self.errorMessageField setHidden:NO];
return;
}
for (PBGitRevSpecifier *rev in self.repository.branches) {
NSString *name = [[rev ref] tagName];
if ([tagName isEqualToString:name]) {
[self.errorMessageField setStringValue:@"Tag already exists"];
[self.errorMessageField setHidden:NO];
return;
}
}
[self closeCreateTagSheet:sender];
NSString *message = [self.tagMessageText string];
[self.repository createTag:tagName message:message atRefish:self.targetRefish];
}
- (IBAction) closeCreateTagSheet:(id)sender
{
[NSApp endSheet:[self window]];
[[self window] orderOut:self];
}
@end