mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
- Added controller 4 stashes, submodules, reset management
- Added additional menu for the repository actions - Added action for 'Revealing in Finder'
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user