Skip to content

Commit be507c8

Browse files
- Added controller 4 stashes, submodules, reset management
- Added additional menu for the repository actions - Added action for 'Revealing in Finder'
1 parent f121873 commit be507c8

12 files changed

+516
-99
lines changed

Commands/PBRevealWithFinderCommand.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// PBRevealWithFinder.h
3+
// GitX
4+
//
5+
// Created by Tomasz Krasnyk on 10-11-27.
6+
// Copyright 2010 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
#import "PBOpenDocumentCommand.h"
11+
12+
@interface PBRevealWithFinderCommand : PBOpenDocumentCommand {
13+
14+
}
15+
16+
17+
@end

Commands/PBRevealWithFinderCommand.m

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// PBRevealWithFinder.m
3+
// GitX
4+
//
5+
// Created by Tomasz Krasnyk on 10-11-27.
6+
// Copyright 2010 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "PBRevealWithFinderCommand.h"
10+
11+
12+
@implementation PBRevealWithFinderCommand
13+
14+
- (id) initWithDocumentAbsolutePath:(NSString *) path {
15+
if (!path) {
16+
[self autorelease];
17+
return nil;
18+
}
19+
20+
if (self = [super initWithDisplayName:@"Reveal in Finder" parameters:nil repository:nil]) {
21+
documentURL = [[NSURL alloc] initWithString:path];
22+
}
23+
return self;
24+
}
25+
26+
- (void) invoke {
27+
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
28+
[ws selectFile:[documentURL absoluteString] inFileViewerRootedAtPath:nil];
29+
}
30+
31+
@end

Controller/PBGitResetController.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// PBGitResetController.h
3+
// GitX
4+
//
5+
// Created by Tomasz Krasnyk on 10-11-27.
6+
// Copyright 2010 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
@class PBGitRepository;
12+
13+
@interface PBGitResetController : NSObject {
14+
PBGitRepository *repository;
15+
}
16+
- (id) initWithRepository:(PBGitRepository *) repo;
17+
18+
- (NSArray *) menuItems;
19+
20+
21+
// actions
22+
- (void) resetHardToHead;
23+
24+
@end

Controller/PBGitResetController.m

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// PBGitResetController.m
3+
// GitX
4+
//
5+
// Created by Tomasz Krasnyk on 10-11-27.
6+
// Copyright 2010 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "PBGitResetController.h"
10+
#import "PBGitRepository.h"
11+
#import "PBCommand.h"
12+
13+
@implementation PBGitResetController
14+
15+
- (id) initWithRepository:(PBGitRepository *) repo {
16+
if (self = [super init]){
17+
repository = [repo retain];
18+
}
19+
return self;
20+
}
21+
22+
- (void) resetHardToHead {
23+
NSArray *arguments = [NSArray arrayWithObjects:@"reset", @"--hard", @"HEAD", nil];
24+
PBCommand *cmd = [[PBCommand alloc] initWithDisplayName:@"Reset hard to HEAD" parameters:arguments repository:repository];
25+
cmd.commandTitle = cmd.displayName;
26+
cmd.commandDescription = @"Reseting head";
27+
[cmd invoke];
28+
}
29+
30+
- (void) reset {
31+
//TODO missing implementation
32+
}
33+
34+
- (NSArray *) menuItems {
35+
NSMenuItem *resetHeadHardly = [[NSMenuItem alloc] initWithTitle:@"Reset hard to HEAD" action:@selector(resetHardToHead) keyEquivalent:@""];
36+
[resetHeadHardly setTarget:self];
37+
38+
NSMenuItem *reset = [[NSMenuItem alloc] initWithTitle:@"Reset..." action:@selector(reset) keyEquivalent:@""];
39+
[reset setTarget:self];
40+
41+
return [NSArray arrayWithObjects:resetHeadHardly, reset, nil];
42+
}
43+
44+
- (BOOL) validateMenuItem:(NSMenuItem *)menuItem {
45+
BOOL shouldBeEnabled = YES;
46+
SEL action = [menuItem action];
47+
if (action == @selector(reset)) {
48+
shouldBeEnabled = NO;
49+
//TODO missing implementation
50+
}
51+
return shouldBeEnabled;
52+
}
53+
54+
- (void) dealloc {
55+
[repository release];
56+
[super dealloc];
57+
}
58+
59+
60+
@end

Controller/PBSubmoduleController.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// PBSubmoduleController.h
3+
// GitX
4+
//
5+
// Created by Tomasz Krasnyk on 10-11-27.
6+
// Copyright 2010 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
#import "PBGitSubmodule.h"
11+
12+
@class PBGitRepository;
13+
@class PBCommand;
14+
15+
@interface PBSubmoduleController : NSObject {
16+
NSArray *submodules;
17+
@private
18+
PBGitRepository *repository;
19+
}
20+
@property (nonatomic, retain, readonly) NSArray *submodules;
21+
22+
- (id) initWithRepository:(PBGitRepository *) repo;
23+
24+
- (void) reload;
25+
26+
- (NSArray *) menuItems;
27+
28+
29+
// actions
30+
31+
- (void) addNewSubmodule;
32+
- (void) initializeAllSubmodules;
33+
- (void) updateAllSubmodules;
34+
35+
- (PBCommand *) commandForOpeningSubmodule:(PBGitSubmodule *) submodule;
36+
- (PBCommand *) defaultCommandForSubmodule:(PBGitSubmodule *) submodule;
37+
@end

Controller/PBSubmoduleController.m

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//
2+
// PBSubmoduleController.m
3+
// GitX
4+
//
5+
// Created by Tomasz Krasnyk on 10-11-27.
6+
// Copyright 2010 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "PBSubmoduleController.h"
10+
#import "PBGitRepository.h"
11+
#import "PBOpenDocumentCommand.h"
12+
13+
@interface PBSubmoduleController()
14+
@property (nonatomic, retain) NSArray *submodules;
15+
@end
16+
17+
18+
@implementation PBSubmoduleController
19+
@synthesize submodules;
20+
21+
- (id) initWithRepository:(PBGitRepository *) repo {
22+
if (self = [super init]){
23+
repository = [repo retain];
24+
}
25+
return self;
26+
}
27+
28+
- (void)dealloc {
29+
[repository release];
30+
[submodules release];
31+
[super dealloc];
32+
}
33+
34+
- (void) reload {
35+
NSArray *arguments = [NSArray arrayWithObjects:@"submodule", @"status", @"--recursive", nil];
36+
NSString *output = [repository outputInWorkdirForArguments:arguments];
37+
NSArray *lines = [output componentsSeparatedByString:@"\n"];
38+
39+
NSMutableArray *loadedSubmodules = [[NSMutableArray alloc] initWithCapacity:[lines count]];
40+
41+
for (NSString *submoduleLine in lines) {
42+
if ([submoduleLine length] == 0)
43+
continue;
44+
PBGitSubmodule *submodule = [[PBGitSubmodule alloc] initWithRawSubmoduleStatusString:submoduleLine];
45+
[loadedSubmodules addObject:submodule];
46+
}
47+
48+
NSMutableArray *groupedSubmodules = [[NSMutableArray alloc] init];
49+
for (PBGitSubmodule *submodule in loadedSubmodules) {
50+
BOOL added = NO;
51+
for (PBGitSubmodule *addedItem in groupedSubmodules) {
52+
if ([[submodule path] hasPrefix:[addedItem path]]) {
53+
[addedItem addSubmodule:submodule];
54+
added = YES;
55+
}
56+
}
57+
if (!added) {
58+
[groupedSubmodules addObject:submodule];
59+
}
60+
}
61+
62+
63+
self.submodules = loadedSubmodules;
64+
}
65+
66+
#pragma mark -
67+
#pragma mark Actions
68+
69+
- (void) addNewSubmodule {
70+
//TODO implement
71+
}
72+
73+
- (void) initializeAllSubmodules {
74+
NSArray *parameters = [NSArray arrayWithObjects:@"submodule", @"init", nil];
75+
PBCommand *initializeSubmodules = [[PBCommand alloc] initWithDisplayName:@"Initialize All Submodules" parameters:parameters repository:repository];
76+
initializeSubmodules.commandTitle = initializeSubmodules.displayName;
77+
initializeSubmodules.commandDescription = @"Initializing submodules";
78+
[initializeSubmodules invoke];
79+
[initializeSubmodules release];
80+
}
81+
82+
- (void) updateAllSubmodules {
83+
NSArray *parameters = [NSArray arrayWithObjects:@"submodule", @"update", nil];
84+
PBCommand *initializeSubmodules = [[PBCommand alloc] initWithDisplayName:@"Update All Submodules" parameters:parameters repository:repository];
85+
initializeSubmodules.commandTitle = initializeSubmodules.displayName;
86+
initializeSubmodules.commandDescription = @"Updating submodules";
87+
[initializeSubmodules invoke];
88+
[initializeSubmodules release];
89+
}
90+
91+
- (NSArray *) menuItems {
92+
NSMutableArray *items = [[NSMutableArray alloc] init];
93+
[items addObject:[[NSMenuItem alloc] initWithTitle:@"Add Submodule..." action:@selector(addNewSubmodule) keyEquivalent:@""]];
94+
[items addObject:[[NSMenuItem alloc] initWithTitle:@"Initialize All Submodules" action:@selector(initializeAllSubmodules) keyEquivalent:@""]];
95+
[items addObject:[[NSMenuItem alloc] initWithTitle:@"Update All Submodules" action:@selector(updateAllSubmodules) keyEquivalent:@""]];
96+
97+
for (NSMenuItem *item in items) {
98+
[item setTarget:self];
99+
}
100+
101+
return items;
102+
}
103+
104+
- (PBCommand *) defaultCommandForSubmodule:(PBGitSubmodule *) submodule {
105+
return [self commandForOpeningSubmodule:submodule];
106+
}
107+
108+
- (PBCommand *) commandForOpeningSubmodule:(PBGitSubmodule *) submodule {
109+
if (!([submodule path] && [submodule submoduleState] != PBGitSubmoduleStateNotInitialized)) {
110+
return nil;
111+
}
112+
NSString *repoPath = [repository workingDirectory];
113+
NSString *path = [repoPath stringByAppendingPathComponent:[submodule path]];
114+
115+
PBOpenDocumentCommand *command = [[PBOpenDocumentCommand alloc] initWithDocumentAbsolutePath:path];
116+
command.commandTitle = command.displayName;
117+
command.commandDescription = @"Opening document";
118+
return [command autorelease];
119+
}
120+
121+
- (BOOL) validateMenuItem:(NSMenuItem *)menuItem {
122+
BOOL shouldBeEnabled = YES;
123+
SEL action = [menuItem action];
124+
if (action == @selector(addNewSubmodule)) {
125+
shouldBeEnabled = NO;
126+
//TODO implementation missing
127+
} else {
128+
shouldBeEnabled = [self.submodules count] > 0;
129+
}
130+
return shouldBeEnabled;
131+
}
132+
133+
@end

0 commit comments

Comments
 (0)