From 058fbcff58c8fadc8b89ab94045f7170b9e4f8b3 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sat, 1 Nov 2008 23:16:41 +0100 Subject: [PATCH] RefController: Refactor ref menu to its own class --- GitX.xcodeproj/project.pbxproj | 6 +++++ PBGitHistoryView.xib | 22 +++++++++--------- PBRefController.m | 22 +++--------------- PBRefMenuItem.h | 23 +++++++++++++++++++ PBRefMenuItem.m | 41 ++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 30 deletions(-) create mode 100644 PBRefMenuItem.h create mode 100644 PBRefMenuItem.m diff --git a/GitX.xcodeproj/project.pbxproj b/GitX.xcodeproj/project.pbxproj index 2a34336..25ad551 100644 --- a/GitX.xcodeproj/project.pbxproj +++ b/GitX.xcodeproj/project.pbxproj @@ -71,6 +71,7 @@ F5E92A230E88569500056E75 /* new_file.png in Resources */ = {isa = PBXBuildFile; fileRef = F5E92A220E88569500056E75 /* new_file.png */; }; F5EF8C8E0E9D4A5D0050906B /* PBWebController.m in Sources */ = {isa = PBXBuildFile; fileRef = F5EF8C8D0E9D4A5D0050906B /* PBWebController.m */; }; F5FC41F40EBCBD4300191D80 /* PBGitXProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */; }; + F5FC43FE0EBD08EE00191D80 /* PBRefMenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = F5FC43FD0EBD08EE00191D80 /* PBRefMenuItem.m */; }; F5FE6C030EB13BC900F30D12 /* PBServicesController.m in Sources */ = {isa = PBXBuildFile; fileRef = F5FE6C020EB13BC900F30D12 /* PBServicesController.m */; }; F5FF4E180E0829C20006317A /* PBGitRevList.m in Sources */ = {isa = PBXBuildFile; fileRef = F5FF4E170E0829C20006317A /* PBGitRevList.m */; }; F5FF4E7A0E082E440006317A /* PBGitGrapher.m in Sources */ = {isa = PBXBuildFile; fileRef = F5FF4E790E082E440006317A /* PBGitGrapher.m */; }; @@ -208,6 +209,8 @@ F5FC41F20EBCBD4300191D80 /* PBGitXProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitXProtocol.h; sourceTree = ""; }; F5FC41F30EBCBD4300191D80 /* PBGitXProtocol.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitXProtocol.m; sourceTree = ""; }; F5FC43C30EBD050800191D80 /* PBRefContextDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBRefContextDelegate.h; sourceTree = ""; }; + F5FC43FC0EBD08EE00191D80 /* PBRefMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBRefMenuItem.h; sourceTree = ""; }; + F5FC43FD0EBD08EE00191D80 /* PBRefMenuItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBRefMenuItem.m; sourceTree = ""; }; F5FE6C010EB13BC900F30D12 /* PBServicesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBServicesController.h; sourceTree = ""; }; F5FE6C020EB13BC900F30D12 /* PBServicesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBServicesController.m; sourceTree = ""; }; F5FF4E160E0829C20006317A /* PBGitRevList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRevList.h; sourceTree = ""; }; @@ -471,6 +474,8 @@ F56174550E058893001DCD79 /* PBGitTree.h */, F56174560E058893001DCD79 /* PBGitTree.m */, F5FC43C30EBD050800191D80 /* PBRefContextDelegate.h */, + F5FC43FC0EBD08EE00191D80 /* PBRefMenuItem.h */, + F5FC43FD0EBD08EE00191D80 /* PBRefMenuItem.m */, ); name = History; sourceTree = ""; @@ -661,6 +666,7 @@ F50A41230EBB875D00208746 /* PBNiceSplitView.m in Sources */, F5FC41F40EBCBD4300191D80 /* PBGitXProtocol.m in Sources */, F574A2850EAE2EAC003F2CB1 /* PBRefController.m in Sources */, + F5FC43FE0EBD08EE00191D80 /* PBRefMenuItem.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index d32f9d3..fbc32ab 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -2091,14 +2091,6 @@ 255 - - - refController - - - - 258 - contextMenuDelegate @@ -2107,6 +2099,14 @@ 259 + + + contextMenuDelegate + + + + 260 + @@ -2947,7 +2947,7 @@ - 259 + 260 @@ -3172,13 +3172,13 @@ YES YES + contextMenuDelegate historyController - refController YES + id PBGitHistoryController - PBRefController diff --git a/PBRefController.m b/PBRefController.m index 98b3a61..4bf1ce4 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -8,17 +8,7 @@ #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 +#import "PBRefMenuItem.h" @implementation PBRefController @@ -27,7 +17,7 @@ [commitList registerForDraggedTypes:[NSArray arrayWithObject:@"PBGitRef"]]; } -- (void) removeRef:(RefMenuItem *) sender +- (void) removeRef:(PBRefMenuItem *) sender { int ret = 1; [historyController.repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-d", [[sender ref] ref], nil] retValue: &ret]; @@ -42,13 +32,7 @@ - (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]; + return [PBRefMenuItem defaultMenuItemsForRef:ref commit:commit target:self]; } # pragma mark Tableview delegate methods diff --git a/PBRefMenuItem.h b/PBRefMenuItem.h new file mode 100644 index 0000000..0e3f455 --- /dev/null +++ b/PBRefMenuItem.h @@ -0,0 +1,23 @@ +// +// PBRefMenuItem.h +// GitX +// +// Created by Pieter de Bie on 01-11-08. +// Copyright 2008 Pieter de Bie. All rights reserved. +// + +#import +#import "PBGitRef.h" +#import "PBGitCommit.h" + +@interface PBRefMenuItem : NSMenuItem { + PBGitRef *ref; + PBGitCommit *commit; +} + +@property (retain) PBGitCommit *commit; +@property (retain) PBGitRef *ref; + ++ (NSArray *)defaultMenuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit target:(id)target; + +@end diff --git a/PBRefMenuItem.m b/PBRefMenuItem.m new file mode 100644 index 0000000..bc70d16 --- /dev/null +++ b/PBRefMenuItem.m @@ -0,0 +1,41 @@ +// +// PBRefMenuItem.m +// GitX +// +// Created by Pieter de Bie on 01-11-08. +// Copyright 2008 Pieter de Bie. All rights reserved. +// + +#import "PBRefMenuItem.h" + + +@implementation PBRefMenuItem +@synthesize ref, commit; + ++ (NSArray *)defaultMenuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit target:(id)target +{ + NSMutableArray *array = [NSMutableArray array]; + NSString *type = [ref type]; + if ([type isEqualToString:@"remote"]) + type = @"remote branch"; + else if ([type isEqualToString:@"head"]) + type = @"branch"; + + [array addObject:[[PBRefMenuItem alloc] initWithTitle:[@"Delete " stringByAppendingString:type] + action:@selector(removeRef:) + keyEquivalent: @""]]; + + [array addObject:[[PBRefMenuItem alloc] initWithTitle:[@"Checkout " stringByAppendingString:type] + action:@selector(checkoutRef:) + keyEquivalent: @""]]; + + for (PBRefMenuItem *item in array) + { + [item setTarget: target]; + [item setRef: ref]; + [item setCommit:commit]; + } + + return array; +} +@end