Skip to content

Commit

Permalink
WebHistoryController: Move ref deletion to RefController
Browse files Browse the repository at this point in the history
That's why it's there, after all. This also makes the system
more robust and catches some more errors.

The next thing this enables is to also allow right-clicking
on refs in the commit list.
  • Loading branch information
pieter committed Nov 1, 2008
1 parent 8a399c0 commit e02ee52
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 118 deletions.
4 changes: 2 additions & 2 deletions PBCommitList.h
Expand Up @@ -8,11 +8,11 @@

#import <Cocoa/Cocoa.h>
#import <WebKit/WebView.h>
#import "PBWebHistoryController.h"
#import "PBGitHistoryController.h"

@interface PBCommitList : NSTableView {
IBOutlet WebView* webView;
IBOutlet PBWebHistoryController* webController;
IBOutlet id webController;
IBOutlet PBGitHistoryController *controller;

NSPoint mouseDownPoint;
Expand Down
3 changes: 2 additions & 1 deletion PBCommitList.m
Expand Up @@ -8,6 +8,7 @@

#import "PBCommitList.h"
#import "PBGitRevisionCell.h"
#import "PBWebHistoryController.h"

@implementation PBCommitList

Expand All @@ -29,7 +30,7 @@ - (void) keyDown: (id) event
[webView scrollPageDown: self];
}
else if ([character rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"jkcv"]].location == 0)
[webController sendKey: character];
[((PBWebHistoryController *)webController) sendKey: character];
else
[super keyDown: event];
}
Expand Down
173 changes: 95 additions & 78 deletions PBGitHistoryView.xib

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion PBGitRepository.h
Expand Up @@ -39,7 +39,6 @@ extern NSString* PBGitRepositoryErrorDomain;

- (BOOL) reloadRefs;
- (void) addRef:(PBGitRef *)ref fromParameters:(NSArray *)params;
- (BOOL) removeRef:(NSString *)ref;
- (void) lazyReload;
- (PBGitRevSpecifier*) headRef;

Expand Down
13 changes: 0 additions & 13 deletions PBGitRepository.m
Expand Up @@ -387,17 +387,4 @@ - (NSString*) parseSymbolicReference:(NSString*) reference
return nil;
}

- (BOOL) removeRef:(NSString *)ref
{
int i;
[self outputForArguments:[NSArray arrayWithObjects:@"branch", @"-D", ref, nil] retValue:&i];

if (i == 0) {
// Todo: We can do better than this!
[self reloadRefs];
[revisionList reload];
return YES;
}
return NO;
}
@end
5 changes: 4 additions & 1 deletion PBRefController.h
Expand Up @@ -9,6 +9,8 @@
#import <Cocoa/Cocoa.h>
#import "PBGitHistoryController.h"
#import "PBCommitList.h"
#import "PBGitRef.h"
#import "PBGitCommit.h"

@interface PBRefController : NSObject {
IBOutlet __weak PBGitHistoryController *historyController;
Expand All @@ -19,8 +21,9 @@
IBOutlet NSTextField *newBranchName;
}

- (IBAction) addRef:(id)sender;
- (IBAction)addRef:(id)sender;
- (IBAction)closeSheet:(id) sender;
- (IBAction)saveSheet:(id) sender;

- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit;
@end
43 changes: 43 additions & 0 deletions PBRefController.m
Expand Up @@ -8,6 +8,17 @@

#import "PBRefController.h"
#import "PBGitRevisionCell.h"
@interface RefMenuItem : NSMenuItem
{
PBGitRef *ref;
PBGitCommit *commit;
}
@property (retain) PBGitCommit *commit;
@property (retain) PBGitRef *ref;
@end
@implementation RefMenuItem
@synthesize ref, commit;
@end

@implementation PBRefController

Expand All @@ -16,6 +27,32 @@ - (void)awakeFromNib
[commitList registerForDraggedTypes:[NSArray arrayWithObject:@"PBGitRef"]];
}

- (void) removeRef:(RefMenuItem *) sender
{
int ret = 1;
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-d", [[sender ref] ref], nil] retValue: &ret];
if (ret) {
NSLog(@"Removing ref failed!");
return;
}

[[sender commit] removeRef:[sender ref]];
[commitController rearrangeObjects];
}

- (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit
{
RefMenuItem *item = [[RefMenuItem alloc] initWithTitle:@"Remove"
action:@selector(removeRef:)
keyEquivalent: @""];
[item setTarget: self];
[item setRef: ref];
[item setCommit:commit];
return [NSArray arrayWithObject: item];
}

# pragma mark Tableview delegate methods

- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard
{
NSPoint location = [tv convertPointFromBase:[(PBCommitList *)tv mouseDownPoint]];
Expand Down Expand Up @@ -116,6 +153,12 @@ -(void)saveSheet:(id) sender
PBGitCommit *commit = [[commitController selectedObjects] objectAtIndex:0];
int retValue = 1;
[historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-mCreate branch from GitX", branchName, [commit sha], NULL] retValue:&retValue];
if (retValue)
{
NSLog(@"Creating ref failed!");
return;
}

[commit addRef:[PBGitRef refFromString:branchName]];
[commitController rearrangeObjects];
}
Expand Down
3 changes: 3 additions & 0 deletions PBWebHistoryController.h
Expand Up @@ -11,9 +11,12 @@

#import "PBGitCommit.h"
#import "PBGitHistoryController.h"
#import "PBRefController.h"

@interface PBWebHistoryController : PBWebController {
IBOutlet PBGitHistoryController* historyController;
IBOutlet PBRefController *refController;

NSString* currentSha;
NSString* diff;
}
Expand Down
31 changes: 9 additions & 22 deletions PBWebHistoryController.m
Expand Up @@ -7,16 +7,6 @@
//

#import "PBWebHistoryController.h"
@interface RefMenuItem : NSMenuItem
{
NSString *ref;
}
@property (copy) NSString *ref;
@end
@implementation RefMenuItem
@synthesize ref;
@end


@implementation PBWebHistoryController

Expand Down Expand Up @@ -78,12 +68,6 @@ - (void) copySource
[a setString:source forType: NSStringPboardType];
}

- (void) removeRef:(RefMenuItem *)sender
{
if (![historyController.repository removeRef: [sender ref]])
NSLog(@"Deletion failed!");
}

- (NSArray *) webView:(WebView *)sender
contextMenuItemsForElement:(NSDictionary *)element
defaultMenuItems:(NSArray *)defaultMenuItems
Expand All @@ -98,12 +82,15 @@ - (NSArray *) webView:(WebView *)sender
if (![[node className] hasPrefix:@"refs "])
return defaultMenuItems;

RefMenuItem *item = [[RefMenuItem alloc] initWithTitle:@"Remove"
action:@selector(removeRef:)
keyEquivalent: @""];
[item setTarget: self];
[item setRef: [[[node childNodes] item:0] textContent]];
return [NSArray arrayWithObject: item];
NSString *selectedRefString = [[[node childNodes] item:0] textContent];
for (PBGitRef *ref in historyController.webCommit.refs)
{
if ([[ref shortName] isEqualToString:selectedRefString])
return [refController menuItemsForRef:ref commit:historyController.webCommit];
}
NSLog(@"Could not find selected ref!");

return defaultMenuItems;
}


Expand Down

0 comments on commit e02ee52

Please sign in to comment.