From e02ee5231c197e913a0aa3955971309d99d8a447 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sat, 1 Nov 2008 22:20:22 +0100 Subject: [PATCH] WebHistoryController: Move ref deletion to RefController 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. --- PBCommitList.h | 4 +- PBCommitList.m | 3 +- PBGitHistoryView.xib | 173 +++++++++++++++++++++------------------ PBGitRepository.h | 1 - PBGitRepository.m | 13 --- PBRefController.h | 5 +- PBRefController.m | 43 ++++++++++ PBWebHistoryController.h | 3 + PBWebHistoryController.m | 31 ++----- 9 files changed, 158 insertions(+), 118 deletions(-) diff --git a/PBCommitList.h b/PBCommitList.h index 9dd67fd..1e721b8 100644 --- a/PBCommitList.h +++ b/PBCommitList.h @@ -8,11 +8,11 @@ #import #import -#import "PBWebHistoryController.h" +#import "PBGitHistoryController.h" @interface PBCommitList : NSTableView { IBOutlet WebView* webView; - IBOutlet PBWebHistoryController* webController; + IBOutlet id webController; IBOutlet PBGitHistoryController *controller; NSPoint mouseDownPoint; diff --git a/PBCommitList.m b/PBCommitList.m index f189c61..06c5ec8 100644 --- a/PBCommitList.m +++ b/PBCommitList.m @@ -8,6 +8,7 @@ #import "PBCommitList.h" #import "PBGitRevisionCell.h" +#import "PBWebHistoryController.h" @implementation PBCommitList @@ -29,7 +30,7 @@ [webView scrollPageDown: self]; } else if ([character rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"jkcv"]].location == 0) - [webController sendKey: character]; + [((PBWebHistoryController *)webController) sendKey: character]; else [super keyDown: event]; } diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index 5273b8e..818202e 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -1030,7 +1030,7 @@ PBRefController - + 15 2 {{196, 376}, {346, 134}} @@ -1039,26 +1039,26 @@ NSWindow {3.40282e+38, 3.40282e+38} - + 256 YES - - + + 268 {{145, 61}, {96, 22}} - + YES - + -1804468671 272630784 topic - + YES - + 6 System textBackgroundColor @@ -1072,50 +1072,50 @@ - - + + 268 {{17, 63}, {123, 17}} - + YES - + 68288064 272630784 New Branch Name: - + - - + + 268 {{17, 97}, {134, 17}} - + YES - + 68288064 272630784 Create a new branch - + - - + + 268 {{236, 12}, {96, 32}} - + YES - + 67239424 134217728 OK - + -2038284033 129 @@ -1124,18 +1124,18 @@ 25 - - + + 268 {{139, 13}, {96, 32}} - + YES - + 67239424 134217728 Cancel - + -2038284033 129 @@ -1220,7 +1220,7 @@ YES 0 - + 6F542219-165D-4621-B546-D8E7DF547248 @@ -1264,7 +1264,7 @@ YES 1 - + 130560 @@ -1471,7 +1471,7 @@ YES - + @@ -1481,7 +1481,7 @@ - + @@ -2046,8 +2046,8 @@ performClick: - - + + 248 @@ -2055,7 +2055,7 @@ newBranchSheet - + 249 @@ -2063,7 +2063,7 @@ newBranchName - + 250 @@ -2071,7 +2071,7 @@ closeSheet: - + 252 @@ -2079,7 +2079,7 @@ saveSheet: - + 253 @@ -2087,10 +2087,18 @@ addRef: - + 255 + + + refController + + + + 258 + @@ -2475,95 +2483,95 @@ 236 - + YES - + 237 - + YES - - - - - + + + + + - + 238 - + YES - + - + 239 - + YES - + - + 240 - + YES - + - + 241 - + YES - + - + 242 - + YES - + - + 243 - - + + 244 - - + + 245 - - + + 246 - - + + 247 - - + + 113 @@ -2575,7 +2583,7 @@ - + History Toolbar @@ -2619,7 +2627,7 @@ 254 - + @@ -2931,7 +2939,7 @@ - 257 + 258 @@ -3151,8 +3159,17 @@ PBWebHistoryController PBWebController - historyController - PBGitHistoryController + YES + + YES + historyController + refController + + + YES + PBGitHistoryController + PBRefController + IBProjectSource diff --git a/PBGitRepository.h b/PBGitRepository.h index f1750d5..605ea82 100644 --- a/PBGitRepository.h +++ b/PBGitRepository.h @@ -39,7 +39,6 @@ extern NSString* PBGitRepositoryErrorDomain; - (BOOL) reloadRefs; - (void) addRef:(PBGitRef *)ref fromParameters:(NSArray *)params; -- (BOOL) removeRef:(NSString *)ref; - (void) lazyReload; - (PBGitRevSpecifier*) headRef; diff --git a/PBGitRepository.m b/PBGitRepository.m index 23ac75d..6301628 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -387,17 +387,4 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; 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 diff --git a/PBRefController.h b/PBRefController.h index e829467..f7dcfcc 100644 --- a/PBRefController.h +++ b/PBRefController.h @@ -9,6 +9,8 @@ #import #import "PBGitHistoryController.h" #import "PBCommitList.h" +#import "PBGitRef.h" +#import "PBGitCommit.h" @interface PBRefController : NSObject { IBOutlet __weak PBGitHistoryController *historyController; @@ -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 diff --git a/PBRefController.m b/PBRefController.m index 313f673..98b3a61 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -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 @@ -16,6 +27,32 @@ [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]]; @@ -116,6 +153,12 @@ 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]; } diff --git a/PBWebHistoryController.h b/PBWebHistoryController.h index 9f018d0..17723c2 100644 --- a/PBWebHistoryController.h +++ b/PBWebHistoryController.h @@ -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; } diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index 03b56c9..a909ccd 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -7,16 +7,6 @@ // #import "PBWebHistoryController.h" -@interface RefMenuItem : NSMenuItem -{ - NSString *ref; -} -@property (copy) NSString *ref; -@end -@implementation RefMenuItem -@synthesize ref; -@end - @implementation PBWebHistoryController @@ -78,12 +68,6 @@ [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 @@ -98,12 +82,15 @@ contextMenuItemsForElement:(NSDictionary *)element 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; }