diff --git a/PBGitSidebarController.h b/PBGitSidebarController.h index 59b9b9d..a2eb106 100644 --- a/PBGitSidebarController.h +++ b/PBGitSidebarController.h @@ -12,6 +12,7 @@ @class PBSourceViewItem; @class PBGitHistoryController; @class PBGitCommitController; +@class PBStashContentController; @interface PBGitSidebarController : PBViewController PROTOCOL_10_6(NSOutlineViewDelegate, NSMenuDelegate){ IBOutlet NSWindow *window; @@ -33,6 +34,7 @@ PBGitHistoryController *historyViewController; PBGitCommitController *commitViewController; + PBStashContentController *stashViewController; } - (void) selectStage; @@ -54,5 +56,6 @@ @property(readonly) NSView *sourceListControlsView; @property(readonly) PBGitHistoryController *historyViewController; @property(readonly) PBGitCommitController *commitViewController; +@property(readonly) PBStashContentController *stashViewController; @end diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m index bb84afa..28d8fb0 100644 --- a/PBGitSidebarController.m +++ b/PBGitSidebarController.m @@ -24,6 +24,7 @@ #import "PBGitStash.h" #import "PBGitSubmodule.h" #import "PBSubmoduleController.h" +#import "PBStashContentController.h" static NSString * const kObservingContextStashes = @"stashesChanged"; static NSString * const kObservingContextSubmodules = @"submodulesChanged"; @@ -43,6 +44,7 @@ static NSString * const kObservingContextSubmodules = @"submodulesChanged"; @synthesize sourceListControlsView; @synthesize historyViewController; @synthesize commitViewController; +@synthesize stashViewController; - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGitWindowController *)controller { @@ -61,6 +63,7 @@ static NSString * const kObservingContextSubmodules = @"submodulesChanged"; historyViewController = [[PBGitHistoryController alloc] initWithRepository:repository superController:superController]; commitViewController = [[PBGitCommitController alloc] initWithRepository:repository superController:superController]; + stashViewController = [[PBStashContentController alloc] initWithRepository:repository superController:superController]; [repository addObserver:self forKeyPath:@"refs" options:0 context:@"updateRefs"]; [repository addObserver:self forKeyPath:@"currentBranch" options:0 context:@"currentBranchChange"]; @@ -319,6 +322,12 @@ static NSString * const kObservingContextSubmodules = @"submodulesChanged"; [PBGitDefaults setShowStageView:YES]; } + if ([item parent] == stashes) { + [superController changeContentController:stashViewController]; + [PBGitDefaults setShowStageView:NO]; + [stashViewController showStash:(PBGitStash*)[(PBGitMenuItem*)item sourceObject]]; + } + [self updateActionMenu]; [self updateRemoteControls]; } diff --git a/PBStashContentController.h b/PBStashContentController.h index f048bac..6254632 100644 --- a/PBStashContentController.h +++ b/PBStashContentController.h @@ -7,7 +7,7 @@ // #import "PBViewController.h" -#import "PBWebController.h" +#import "PBWebHistoryController.h" @class PBGitStash; @class PBWebStashController; @@ -22,13 +22,8 @@ @end -@interface PBWebStashController : PBWebController { - PBGitStash* currentStash; - NSString* diff; +// TODO: This class may not be needed +@interface PBWebStashController : PBWebHistoryController { } -- (void) changeContentTo:(PBGitStash*)stash; - -@property (readonly) NSString* diff; - @end diff --git a/PBStashContentController.m b/PBStashContentController.m index b2a7a11..27d2175 100644 --- a/PBStashContentController.m +++ b/PBStashContentController.m @@ -7,17 +7,50 @@ // #import "PBStashContentController.h" +#import "PBGitDefaults.h" #import "PBGitStash.h" @implementation PBStashContentController - (void) awakeFromNib { + [webController setRepository:repository]; } - (void) showStash:(PBGitStash*)stash { - [webController changeContentTo:stash]; + NSString *stashRef = [NSString stringWithFormat:@"refs/%@", [stash name]]; + NSString *stashSha = [repository shaForRef:[PBGitRef refFromString:stashRef]]; + PBGitCommit *commit = [PBGitCommit commitWithRepository:repository andSha:stashSha]; + + [webController changeContentTo:commit]; } @end + +@implementation PBWebStashController +/* +- (void) changeContentTo:(PBGitStash*)stash +{ + if (stash == nil || !finishedLoading) + return; + + currentStash = stash; + + // TODO: get the stash's SHA and put it in currentSha + + NSString *stashRef = [NSString stringWithFormat:@"refs/%@", [stash name]]; + NSMutableArray *taskArguments = [NSMutableArray arrayWithObjects:@"show", @"--numstat", @"--summary", @"--pretty=raw", stashRef, nil]; + + if (![PBGitDefaults showWhitespaceDifferences]) + [taskArguments insertObject:@"-w" atIndex:1]; + + NSFileHandle *handle = [repository handleForArguments:taskArguments]; + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + + [nc removeObserver:self name:NSFileHandleReadToEndOfFileCompletionNotification object:nil]; + [nc addObserver:self selector:@selector(commitDetailsLoaded:) name:NSFileHandleReadToEndOfFileCompletionNotification object:handle]; + [handle readToEndOfFileInBackgroundAndNotify]; +} +*/ +@end