forked from laullon/gitx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added controller 4 stashes, submodules, reset management
- Added additional menu for the repository actions - Added action for 'Revealing in Finder'
- Loading branch information
1 parent
f121873
commit be507c8
Showing
12 changed files
with
516 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// PBRevealWithFinder.h | ||
// GitX | ||
// | ||
// Created by Tomasz Krasnyk on 10-11-27. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import "PBOpenDocumentCommand.h" | ||
|
||
@interface PBRevealWithFinderCommand : PBOpenDocumentCommand { | ||
|
||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// PBRevealWithFinder.m | ||
// GitX | ||
// | ||
// Created by Tomasz Krasnyk on 10-11-27. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "PBRevealWithFinderCommand.h" | ||
|
||
|
||
@implementation PBRevealWithFinderCommand | ||
|
||
- (id) initWithDocumentAbsolutePath:(NSString *) path { | ||
if (!path) { | ||
[self autorelease]; | ||
return nil; | ||
} | ||
|
||
if (self = [super initWithDisplayName:@"Reveal in Finder" parameters:nil repository:nil]) { | ||
documentURL = [[NSURL alloc] initWithString:path]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void) invoke { | ||
NSWorkspace *ws = [NSWorkspace sharedWorkspace]; | ||
[ws selectFile:[documentURL absoluteString] inFileViewerRootedAtPath:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// PBGitResetController.h | ||
// GitX | ||
// | ||
// Created by Tomasz Krasnyk on 10-11-27. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@class PBGitRepository; | ||
|
||
@interface PBGitResetController : NSObject { | ||
PBGitRepository *repository; | ||
} | ||
- (id) initWithRepository:(PBGitRepository *) repo; | ||
|
||
- (NSArray *) menuItems; | ||
|
||
|
||
// actions | ||
- (void) resetHardToHead; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// PBGitResetController.m | ||
// GitX | ||
// | ||
// Created by Tomasz Krasnyk on 10-11-27. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "PBGitResetController.h" | ||
#import "PBGitRepository.h" | ||
#import "PBCommand.h" | ||
|
||
@implementation PBGitResetController | ||
|
||
- (id) initWithRepository:(PBGitRepository *) repo { | ||
if (self = [super init]){ | ||
repository = [repo retain]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void) resetHardToHead { | ||
NSArray *arguments = [NSArray arrayWithObjects:@"reset", @"--hard", @"HEAD", nil]; | ||
PBCommand *cmd = [[PBCommand alloc] initWithDisplayName:@"Reset hard to HEAD" parameters:arguments repository:repository]; | ||
cmd.commandTitle = cmd.displayName; | ||
cmd.commandDescription = @"Reseting head"; | ||
[cmd invoke]; | ||
} | ||
|
||
- (void) reset { | ||
//TODO missing implementation | ||
} | ||
|
||
- (NSArray *) menuItems { | ||
NSMenuItem *resetHeadHardly = [[NSMenuItem alloc] initWithTitle:@"Reset hard to HEAD" action:@selector(resetHardToHead) keyEquivalent:@""]; | ||
[resetHeadHardly setTarget:self]; | ||
|
||
NSMenuItem *reset = [[NSMenuItem alloc] initWithTitle:@"Reset..." action:@selector(reset) keyEquivalent:@""]; | ||
[reset setTarget:self]; | ||
|
||
return [NSArray arrayWithObjects:resetHeadHardly, reset, nil]; | ||
} | ||
|
||
- (BOOL) validateMenuItem:(NSMenuItem *)menuItem { | ||
BOOL shouldBeEnabled = YES; | ||
SEL action = [menuItem action]; | ||
if (action == @selector(reset)) { | ||
shouldBeEnabled = NO; | ||
//TODO missing implementation | ||
} | ||
return shouldBeEnabled; | ||
} | ||
|
||
- (void) dealloc { | ||
[repository release]; | ||
[super dealloc]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// PBSubmoduleController.h | ||
// GitX | ||
// | ||
// Created by Tomasz Krasnyk on 10-11-27. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
#import "PBGitSubmodule.h" | ||
|
||
@class PBGitRepository; | ||
@class PBCommand; | ||
|
||
@interface PBSubmoduleController : NSObject { | ||
NSArray *submodules; | ||
@private | ||
PBGitRepository *repository; | ||
} | ||
@property (nonatomic, retain, readonly) NSArray *submodules; | ||
|
||
- (id) initWithRepository:(PBGitRepository *) repo; | ||
|
||
- (void) reload; | ||
|
||
- (NSArray *) menuItems; | ||
|
||
|
||
// actions | ||
|
||
- (void) addNewSubmodule; | ||
- (void) initializeAllSubmodules; | ||
- (void) updateAllSubmodules; | ||
|
||
- (PBCommand *) commandForOpeningSubmodule:(PBGitSubmodule *) submodule; | ||
- (PBCommand *) defaultCommandForSubmodule:(PBGitSubmodule *) submodule; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// | ||
// PBSubmoduleController.m | ||
// GitX | ||
// | ||
// Created by Tomasz Krasnyk on 10-11-27. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import "PBSubmoduleController.h" | ||
#import "PBGitRepository.h" | ||
#import "PBOpenDocumentCommand.h" | ||
|
||
@interface PBSubmoduleController() | ||
@property (nonatomic, retain) NSArray *submodules; | ||
@end | ||
|
||
|
||
@implementation PBSubmoduleController | ||
@synthesize submodules; | ||
|
||
- (id) initWithRepository:(PBGitRepository *) repo { | ||
if (self = [super init]){ | ||
repository = [repo retain]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
[repository release]; | ||
[submodules release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void) reload { | ||
NSArray *arguments = [NSArray arrayWithObjects:@"submodule", @"status", @"--recursive", nil]; | ||
NSString *output = [repository outputInWorkdirForArguments:arguments]; | ||
NSArray *lines = [output componentsSeparatedByString:@"\n"]; | ||
|
||
NSMutableArray *loadedSubmodules = [[NSMutableArray alloc] initWithCapacity:[lines count]]; | ||
|
||
for (NSString *submoduleLine in lines) { | ||
if ([submoduleLine length] == 0) | ||
continue; | ||
PBGitSubmodule *submodule = [[PBGitSubmodule alloc] initWithRawSubmoduleStatusString:submoduleLine]; | ||
[loadedSubmodules addObject:submodule]; | ||
} | ||
|
||
NSMutableArray *groupedSubmodules = [[NSMutableArray alloc] init]; | ||
for (PBGitSubmodule *submodule in loadedSubmodules) { | ||
BOOL added = NO; | ||
for (PBGitSubmodule *addedItem in groupedSubmodules) { | ||
if ([[submodule path] hasPrefix:[addedItem path]]) { | ||
[addedItem addSubmodule:submodule]; | ||
added = YES; | ||
} | ||
} | ||
if (!added) { | ||
[groupedSubmodules addObject:submodule]; | ||
} | ||
} | ||
|
||
|
||
self.submodules = loadedSubmodules; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Actions | ||
|
||
- (void) addNewSubmodule { | ||
//TODO implement | ||
} | ||
|
||
- (void) initializeAllSubmodules { | ||
NSArray *parameters = [NSArray arrayWithObjects:@"submodule", @"init", nil]; | ||
PBCommand *initializeSubmodules = [[PBCommand alloc] initWithDisplayName:@"Initialize All Submodules" parameters:parameters repository:repository]; | ||
initializeSubmodules.commandTitle = initializeSubmodules.displayName; | ||
initializeSubmodules.commandDescription = @"Initializing submodules"; | ||
[initializeSubmodules invoke]; | ||
[initializeSubmodules release]; | ||
} | ||
|
||
- (void) updateAllSubmodules { | ||
NSArray *parameters = [NSArray arrayWithObjects:@"submodule", @"update", nil]; | ||
PBCommand *initializeSubmodules = [[PBCommand alloc] initWithDisplayName:@"Update All Submodules" parameters:parameters repository:repository]; | ||
initializeSubmodules.commandTitle = initializeSubmodules.displayName; | ||
initializeSubmodules.commandDescription = @"Updating submodules"; | ||
[initializeSubmodules invoke]; | ||
[initializeSubmodules release]; | ||
} | ||
|
||
- (NSArray *) menuItems { | ||
NSMutableArray *items = [[NSMutableArray alloc] init]; | ||
[items addObject:[[NSMenuItem alloc] initWithTitle:@"Add Submodule..." action:@selector(addNewSubmodule) keyEquivalent:@""]]; | ||
[items addObject:[[NSMenuItem alloc] initWithTitle:@"Initialize All Submodules" action:@selector(initializeAllSubmodules) keyEquivalent:@""]]; | ||
[items addObject:[[NSMenuItem alloc] initWithTitle:@"Update All Submodules" action:@selector(updateAllSubmodules) keyEquivalent:@""]]; | ||
|
||
for (NSMenuItem *item in items) { | ||
[item setTarget:self]; | ||
} | ||
|
||
return items; | ||
} | ||
|
||
- (PBCommand *) defaultCommandForSubmodule:(PBGitSubmodule *) submodule { | ||
return [self commandForOpeningSubmodule:submodule]; | ||
} | ||
|
||
- (PBCommand *) commandForOpeningSubmodule:(PBGitSubmodule *) submodule { | ||
if (!([submodule path] && [submodule submoduleState] != PBGitSubmoduleStateNotInitialized)) { | ||
return nil; | ||
} | ||
NSString *repoPath = [repository workingDirectory]; | ||
NSString *path = [repoPath stringByAppendingPathComponent:[submodule path]]; | ||
|
||
PBOpenDocumentCommand *command = [[PBOpenDocumentCommand alloc] initWithDocumentAbsolutePath:path]; | ||
command.commandTitle = command.displayName; | ||
command.commandDescription = @"Opening document"; | ||
return [command autorelease]; | ||
} | ||
|
||
- (BOOL) validateMenuItem:(NSMenuItem *)menuItem { | ||
BOOL shouldBeEnabled = YES; | ||
SEL action = [menuItem action]; | ||
if (action == @selector(addNewSubmodule)) { | ||
shouldBeEnabled = NO; | ||
//TODO implementation missing | ||
} else { | ||
shouldBeEnabled = [self.submodules count] > 0; | ||
} | ||
return shouldBeEnabled; | ||
} | ||
|
||
@end |
Oops, something went wrong.