Permalink
Browse files

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.
  • Loading branch information...
1 parent 8a399c0 commit e02ee5231c197e913a0aa3955971309d99d8a447 @pieter committed Nov 1, 2008
Showing with 158 additions and 118 deletions.
  1. +2 −2 PBCommitList.h
  2. +2 −1 PBCommitList.m
  3. +95 −78 PBGitHistoryView.xib
  4. +0 −1 PBGitRepository.h
  5. +0 −13 PBGitRepository.m
  6. +4 −1 PBRefController.h
  7. +43 −0 PBRefController.m
  8. +3 −0 PBWebHistoryController.h
  9. +9 −22 PBWebHistoryController.m
View
@@ -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;
View
@@ -8,6 +8,7 @@
#import "PBCommitList.h"
#import "PBGitRevisionCell.h"
+#import "PBWebHistoryController.h"
@implementation PBCommitList
@@ -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];
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -39,7 +39,6 @@ extern NSString* PBGitRepositoryErrorDomain;
- (BOOL) reloadRefs;
- (void) addRef:(PBGitRef *)ref fromParameters:(NSArray *)params;
-- (BOOL) removeRef:(NSString *)ref;
- (void) lazyReload;
- (PBGitRevSpecifier*) headRef;
View
@@ -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
View
@@ -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;
@@ -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
View
@@ -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 @@ - (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]];
@@ -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];
}
View
@@ -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;
}
View
@@ -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 @@ - (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
@@ -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;
}

0 comments on commit e02ee52

Please sign in to comment.