Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitx dev stashes #239

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
14 changes: 13 additions & 1 deletion Classes/Controllers/PBGitCommitController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,33 @@
// This might have to transfer over to the PBGitRepository
// object sometime
PBGitIndex *index;

BOOL stashKeepIndex;

IBOutlet NSTextView *commitMessageView;
IBOutlet NSArrayController *unstagedFilesController;
IBOutlet NSArrayController *cachedFilesController;
IBOutlet NSArrayController *trackedFilesController;

IBOutlet NSTabView *controlsTabView;
IBOutlet NSButton *commitButton;
IBOutlet NSButton *stashButton;

IBOutlet PBGitIndexController *indexController;
IBOutlet PBWebChangesController *webController;
IBOutlet PBNiceSplitView *commitSplitView;
}

@property(readonly) PBGitIndex *index;
@property(assign) BOOL stashKeepIndex;

- (IBAction) refresh:(id) sender;
- (IBAction) commit:(id) sender;
- (IBAction) forceCommit:(id) sender;
- (IBAction)signOff:(id)sender;
- (IBAction) signOff:(id)sender;
- (IBAction) stashChanges:(id) sender;

- (NSView *) nextKeyViewFor:(NSView *)view;
- (NSView *) previousKeyViewFor:(NSView *)view;

@end
95 changes: 88 additions & 7 deletions Classes/Controllers/PBGitCommitController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
#import "PBGitIndex.h"
#import "PBNiceSplitView.h"
#import "PBGitRepositoryWatcher.h"
#import "PBGitIndexController.h"

#import <ObjectiveGit/GTRepository.h>
#import <ObjectiveGit/GTConfiguration.h>

#define kCommitSplitViewPositionDefault @"Commit SplitView Position"
#define kControlsTabIndexCommit 0
#define kControlsTabIndexStash 1

@interface PBGitCommitController ()
@interface PBGitCommitController () <NSTextViewDelegate>
- (void)refreshFinished:(NSNotification *)notification;
- (void)commitWithVerification:(BOOL) doVerify;
- (void)commitStatusUpdated:(NSNotification *)notification;
Expand All @@ -35,6 +38,7 @@ - (void)saveCommitSplitViewPosition;
@implementation PBGitCommitController

@synthesize index;
@synthesize stashKeepIndex;

- (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGitWindowController *)controller
{
Expand All @@ -60,10 +64,12 @@ - (void)awakeFromNib
{
[super awakeFromNib];

commitMessageView.delegate = self;
[commitMessageView setTypingAttributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Monaco" size:12.0] forKey:NSFontAttributeName]];

[unstagedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"hasUnstagedChanges == 1"]];
[cachedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"hasStagedChanges == 1"]];
[trackedFilesController setFilterPredicate:[NSPredicate predicateWithFormat:@"status > 0"]];

[unstagedFilesController setSortDescriptors:[NSArray arrayWithObjects:
[[NSSortDescriptor alloc] initWithKey:@"status" ascending:false],
Expand Down Expand Up @@ -123,6 +129,8 @@ - (IBAction)signOff:(id)sender

- (void) refresh:(id) sender
{
[controlsTabView selectTabViewItemAtIndex:kControlsTabIndexCommit];

self.isBusy = YES;
self.status = @"Refreshing index…";
[index refresh];
Expand All @@ -136,6 +144,12 @@ - (void) updateView
[self refresh:nil];
}

- (IBAction) stashChanges:(id)sender
{
NSLog(@"stash changes: %@", stashKeepIndex ? @"keep index" : @"");
[self.repository stashSaveWithKeepIndex:stashKeepIndex];
}

- (IBAction) commit:(id) sender
{
[self commitWithVerification:YES];
Expand Down Expand Up @@ -226,12 +240,12 @@ - (void)indexChanged:(NSNotification *)notification
{
[cachedFilesController rearrangeObjects];
[unstagedFilesController rearrangeObjects];
if ([[cachedFilesController arrangedObjects] count]) {
[commitButton setEnabled:YES];
} else {
[commitButton setEnabled:NO];
}


NSUInteger tracked = [[trackedFilesController arrangedObjects] count];
NSUInteger staged = [[cachedFilesController arrangedObjects] count];

[commitButton setEnabled:(staged > 0)];
[stashButton setEnabled:(staged > 0 || tracked > 0)];
}

- (void)indexOperationFailed:(NSNotification *)notification
Expand Down Expand Up @@ -313,4 +327,71 @@ - (void)restoreCommitSplitViewPositiion
[commitSplitView setHidden:NO];
}

#pragma mark Handle "alt" key-down/up events
// to toggle commit/stash controls

- (void)flagsChanged:(NSEvent *)theEvent
{
BOOL altDown = !!([theEvent modifierFlags] & NSAlternateKeyMask);
int currIndex = [controlsTabView indexOfTabViewItem:controlsTabView.selectedTabViewItem];
int desiredIndex = altDown ? kControlsTabIndexStash : kControlsTabIndexCommit;
if (currIndex != desiredIndex) {
[controlsTabView selectTabViewItemAtIndex:desiredIndex];
}
}


#pragma mark NSTextView delegate methods

- (void)focusTable:(NSTableView *)table
{
if ([table numberOfRows] > 0) {
if ([table numberOfSelectedRows] == 0) {
[table selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];
}
[[table window] makeFirstResponder:table];
}
}

- (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector;
{
if (commandSelector == @selector(insertTab:)) {
[self focusTable:indexController.stagedTable];
return YES;
} else if (commandSelector == @selector(insertBacktab:)) {
[self focusTable:indexController.unstagedTable];
return YES;
}
return NO;
}

# pragma mark Key View Chain

-(NSView *)nextKeyViewFor:(NSView *)view
{
NSView * next = nil;
if (view == indexController.unstagedTable) {
next = commitMessageView;
}
else if (view == commitMessageView) {
next = indexController.stagedTable;
}
else if (view == indexController.stagedTable) {
next = commitButton;
}
return next;
}

-(NSView *)previousKeyViewFor:(NSView *)view
{
NSView * next = nil;
if (view == indexController.stagedTable) {
next = commitMessageView;
}
else if (view == commitMessageView) {
next = indexController.unstagedTable;
}
return next;
}

@end
6 changes: 6 additions & 0 deletions Classes/Controllers/PBGitIndexController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
IBOutlet NSTableView *stagedTable;
}

@property (readonly) NSTableView *unstagedTable;
@property (readonly) NSTableView *stagedTable;

- (IBAction) rowClicked:(NSCell *) sender;
- (IBAction) tableClicked:(NSTableView *)tableView;

- (NSMenu *) menuForTable:(NSTableView *)table;
- (NSView *) nextKeyViewFor:(NSView *)view;
- (NSView *) previousKeyViewFor:(NSView *)view;


- (void) stageSelectedFiles;
- (void) unstageSelectedFiles;
Expand Down
14 changes: 14 additions & 0 deletions Classes/Controllers/PBGitIndexController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ - (void)discardChangesForFiles:(NSArray *)files force:(BOOL)force;

@implementation PBGitIndexController

@synthesize stagedTable, unstagedTable;

- (void)awakeFromNib
{
[unstagedTable setDoubleAction:@selector(tableClicked:)];
Expand Down Expand Up @@ -386,4 +388,16 @@ - (BOOL)tableView:(NSTableView *)aTableView
return YES;
}

# pragma mark Key View Chain

-(NSView *)nextKeyViewFor:(NSView *)view
{
return [commitController nextKeyViewFor:view];
}

-(NSView *)previousKeyViewFor:(NSView *)view
{
return [commitController previousKeyViewFor:view];
}

@end
2 changes: 1 addition & 1 deletion Classes/Controllers/PBGitSidebarController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/* Specific things */
PBSourceViewItem *stage;

PBSourceViewItem *branches, *remotes, *tags, *others, *submodules;
PBSourceViewItem *branches, *remotes, *tags, *others, *submodules, *stashes;

PBGitHistoryController *historyViewController;
PBGitCommitController *commitViewController;
Expand Down
24 changes: 24 additions & 0 deletions Classes/Controllers/PBGitSidebarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#import "PBAddRemoteSheet.h"
#import "PBGitDefaults.h"
#import "PBHistorySearchController.h"
#import "PBGitStash.h"
#import "PBGitSVStashItem.h"

@interface PBGitSidebarController ()

Expand Down Expand Up @@ -53,6 +55,7 @@ - (void)awakeFromNib

[repository addObserver:self forKeyPath:@"currentBranch" options:0 context:@"currentBranchChange"];
[repository addObserver:self forKeyPath:@"branches" options:(NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew) context:@"branchesModified"];
[repository addObserver:self forKeyPath:@"stashes" options:0 context:@"stashesModified"];

[sourceView setTarget:self];
[sourceView setDoubleAction:@selector(doubleClicked:)];
Expand Down Expand Up @@ -82,6 +85,7 @@ - (void)closeView

[repository removeObserver:self forKeyPath:@"currentBranch"];
[repository removeObserver:self forKeyPath:@"branches"];
[repository removeObserver:self forKeyPath:@"stashes"];

[super closeView];
}
Expand Down Expand Up @@ -112,6 +116,20 @@ - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(
}
return;
}

if ([@"stashesModified" isEqualToString:(__bridge NSString*)context]) {

for (PBGitSVStashItem *stashItem in stashes.sortedChildren)
[stashes removeChild:stashItem];

for (PBGitStash *stash in repository.stashes)
[stashes addChild: [PBGitSVStashItem itemWithStash:stash]];

[sourceView expandItem:stashes];
[sourceView reloadItem:stashes reloadChildren:YES];

return;
}

[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
Expand Down Expand Up @@ -288,9 +306,13 @@ - (void)populateList
branches = [PBSourceViewItem groupItemWithTitle:@"Branches"];
remotes = [PBSourceViewItem groupItemWithTitle:@"Remotes"];
tags = [PBSourceViewItem groupItemWithTitle:@"Tags"];
stashes = [PBSourceViewItem groupItemWithTitle:@"Stashes"];
submodules = [PBSourceViewItem groupItemWithTitle:@"Submodules"];
others = [PBSourceViewItem groupItemWithTitle:@"Other"];

for (PBGitStash *stash in repository.stashes)
[stashes addChild: [PBGitSVStashItem itemWithStash:stash]];

for (PBGitRevSpecifier *rev in repository.branches)
[self addRevSpec:rev];

Expand All @@ -301,13 +323,15 @@ - (void)populateList
[items addObject:branches];
[items addObject:remotes];
[items addObject:tags];
[items addObject:stashes];
[items addObject:submodules];
[items addObject:others];

[sourceView reloadData];
[sourceView expandItem:project];
[sourceView expandItem:branches expandChildren:YES];
[sourceView expandItem:remotes];
[sourceView expandItem:stashes];
[sourceView expandItem:submodules];

[sourceView reloadItem:nil reloadChildren:YES];
Expand Down
3 changes: 3 additions & 0 deletions Classes/Controllers/PBGitWindowController.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
- (IBAction) revealInFinder:(id)sender;
- (IBAction) openInTerminal:(id)sender;
- (IBAction) refresh:(id)sender;
- (IBAction) stashSave:(id) sender;
- (IBAction) stashSaveWithKeepIndex:(id) sender;
- (IBAction) stashPop:(id) sender;

- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;

Expand Down
21 changes: 21 additions & 0 deletions Classes/Controllers/PBGitWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,27 @@ - (void)hideModalSheet:(RJModalRepoSheet *)sheet
}
}

#pragma mark SplitView Delegates

- (IBAction) stashSave:(id) sender
{
[repository stashSaveWithKeepIndex:NO];
}

- (IBAction) stashSaveWithKeepIndex:(id) sender
{
[repository stashSaveWithKeepIndex:YES];
}

- (IBAction) stashPop:(id) sender
{
if ([repository.stashes count] > 0) {
PBGitStash * latestStash = [repository.stashes objectAtIndex:0];
[repository stashPop:latestStash];
}
}


#pragma mark -
#pragma mark SplitView Delegates

Expand Down
35 changes: 35 additions & 0 deletions Classes/Controllers/PBRefController.m
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,41 @@ - (void) diffWithHEAD:(PBRefMenuItem *)sender
[PBDiffWindowController showDiffWindowWithFiles:nil fromCommit:commit diffCommit:nil];
}

#pragma mark Stash

-(void) stashPop:(id)sender
{
PBGitStash * stash = [historyController.repository stashForRef:[sender refish]];
BOOL ok = [historyController.repository stashPop:stash];
if (ok) {
[historyController.repository.windowController showCommitView:sender];
}
}

-(void) stashApply:(id)sender
{
PBGitStash * stash = [historyController.repository stashForRef:[sender refish]];
BOOL ok = [historyController.repository stashApply:stash];
if (ok) {
[historyController.repository.windowController showCommitView:sender];
}
}

-(void) stashDrop:(id)sender
{
PBGitStash * stash = [historyController.repository stashForRef:[sender refish]];
BOOL ok = [historyController.repository stashDrop:stash];
if (ok) {
[historyController.repository.windowController showHistoryView:sender];
}
}

-(void) stashViewDiff:(id)sender
{
PBGitStash * stash = [historyController.repository stashForRef:[sender refish]];
[PBDiffWindowController showDiffWindowWithFiles:nil fromCommit:stash.ancesterCommit diffCommit:stash.commit];
}

#pragma mark Tags

- (void) createTag:(PBRefMenuItem *)sender
Expand Down
Loading