forked from dgrijalva/gitx
-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathPBResetSheet.m
72 lines (60 loc) · 2.04 KB
/
PBResetSheet.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
//
// PBResetSheet.m
// GitX
//
// Created by Leszek Slazynski on 11-03-13.
// Copyright 2011 LSL. All rights reserved.
//
#import "PBResetSheet.h"
#import "PBGitRefish.h"
#import "PBCommand.h"
#import "PBGitRepository.h"
#import "PBGitWindowController.h"
static const char* StringFromResetType(PBResetType type) {
static const char* resetTypes[] = {
"none", "soft", "mixed", "hard", "merge", "keep"
};
return resetTypes[type];
}
@implementation PBResetSheet
static PBResetSheet* sheet;
- (void) beginResetSheetForRepository:(PBGitRepository*) repo refish:(id<PBGitRefish>)refish andType:(PBResetType)type {
defaultType = type;
targetRefish = refish;
repository = repo;
[NSApp beginSheet: [self window]
modalForWindow: [[repository windowController] window]
modalDelegate: self
didEndSelector: nil
contextInfo: NULL];
}
+ (void) beginResetSheetForRepository:(PBGitRepository*) repo refish:(id<PBGitRefish>)refish andType:(PBResetType)type {
if (!sheet) {
sheet = [[self alloc] initWithWindowNibName: @"PBResetSheet"];
}
[sheet beginResetSheetForRepository: repo refish: refish andType: type];
}
- (id) init {
if ( (self = [super initWithWindowNibName: @"PBResetSheet"]) ) {
defaultType = PBResetTypeMixed;
}
return self;
}
- (void) windowDidLoad {
[resetType setSelectedSegment: defaultType - 1];
[resetDesc selectTabViewItemAtIndex: defaultType - 1];
}
- (IBAction)resetBranch:(id)sender {
[NSApp endSheet:[self window]];
[[self window] orderOut:self];
PBResetType type = [resetType selectedSegment] + 1;
NSString* type_arg = [NSString stringWithFormat: @"--%s", StringFromResetType(type)];
NSArray *arguments = [NSArray arrayWithObjects:@"reset", type_arg, [targetRefish refishName], nil];
PBCommand *cmd = [[PBCommand alloc] initWithDisplayName:@"Reset branch" parameters:arguments repository:repository];
[cmd invoke];
}
- (IBAction)cancel:(id)sender {
[NSApp endSheet:[self window]];
[[self window] orderOut:self];
}
@end