From c52aedfcf292cb68e4f8ab5744863dda045eada9 Mon Sep 17 00:00:00 2001 From: brotherbard Date: Sun, 8 Nov 2009 10:04:58 -0700 Subject: [PATCH] Add an "Add Remote" button to the toolbar that adds and fetches a remote. TODO: a custom icon --- PBGitHistoryView.xib | 500 +++++++++++++++++++++++++++++++++++++++++-- PBRefController.h | 10 + PBRefController.m | 74 +++++++ 3 files changed, 568 insertions(+), 16 deletions(-) diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index 27b1680..fd3c7ed 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -3,7 +3,7 @@ 1050 10B504 - 740 + 732 1038.2 437.00 @@ -15,14 +15,15 @@ YES - 740 - 740 + 732 + 732 YES - + + @@ -957,7 +958,7 @@ textBackgroundColor - + 6 System textColor @@ -1034,7 +1035,7 @@ - + 1 MSAwIDAAA @@ -1067,6 +1068,7 @@ YES 1E431E79-1591-49E7-9E17-49497CA4622A + 1F28F8E8-5C61-4EC8-A2AA-6BD82F8E0B22 1F42879A-1F5D-447B-9C67-74C618C03247 7FFB691C-2D2F-49A9-997F-AE1AE8BFF3F1 86360841-A2B1-4802-845A-AE424521FE99 @@ -1136,6 +1138,48 @@ YES 0 + + + 1F28F8E8-5C61-4EC8-A2AA-6BD82F8E0B22 + + Add Remote + Add Remote + + + + 268 + {{17, 14}, {40, 25}} + + YES + + -2080244224 + 134217728 + + + + -2033434369 + 163 + + NSImage + AddBranchTemplate + + + + 400 + 75 + + + + + + {40, 25} + {40, 25} + YES + YES + 0 + YES + 0 + 1F42879A-1F5D-447B-9C67-74C618C03247 @@ -1281,17 +1325,14 @@ -2033434369 163 - - NSImage - AddBranchTemplate - + 400 75 - + {40, 25} @@ -1588,7 +1629,7 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA - + YES @@ -1596,6 +1637,7 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA + @@ -1618,6 +1660,153 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA YES + + 15 + 2 + {{196, 380}, {474, 130}} + 603979776 + Add Remote Sheet + NSWindow + + {1000, 130} + {346, 102} + + + 256 + + YES + + + 266 + {{117, 88}, {155, 22}} + + YES + + -1804468671 + 272630784 + + + name + + YES + + + + + + + 268 + {{17, 90}, {95, 17}} + + YES + + 68288064 + 71304192 + Remote name: + + + + + + + + + 266 + {{117, 60}, {337, 22}} + + YES + + -1804468671 + 272630784 + + + URL + + YES + + + + + + + 268 + {{27, 62}, {85, 17}} + + YES + + 68288064 + 71304192 + Remote URL: + + + + + + + + + 289 + {{364, 12}, {96, 32}} + + YES + + 67239424 + 134217728 + Add + + + -2038284033 + 129 + + DQ + 200 + 25 + + + + + 289 + {{268, 12}, {96, 32}} + + YES + + 67239424 + 134217728 + Cancel + + + -2038284033 + 129 + + Gw + 200 + 25 + + + + + 292 + {{17, 22}, {252, 17}} + + YES + + 68288064 + 272630784 + Invalid name + + + + + + + + {474, 130} + + + {{0, 0}, {2560, 1578}} + {346, 124} + {1000, 152} + @@ -2248,6 +2437,62 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA 425 + + + addRemoteName + + + + 447 + + + + addRemoteURL + + + + 448 + + + + addRemoteErrorMessage + + + + 449 + + + + addRemoteButton: + + + + 454 + + + + addRemoteSheet + + + + 455 + + + + closeAddRemoteSheet: + + + + 456 + + + + addRemoteSheet: + + + + 457 + @@ -2703,6 +2948,7 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA + History Toolbar @@ -2931,6 +3177,153 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA + + 426 + + + YES + + + + + + 427 + + + YES + + + + + + + + + + + + 428 + + + YES + + + + + + 429 + + + YES + + + + + + 430 + + + YES + + + + + + 431 + + + YES + + + + + + 432 + + + YES + + + + Text Field (Name) + + + 433 + + + + + 434 + + + + + 435 + + + + + 436 + + + + + 437 + + + + + 442 + + + YES + + + + Text Field (URL) + + + 443 + + + YES + + + + + + 444 + + + + + 445 + + + + + 450 + + + YES + + + + + + 451 + + + YES + + + + + + 452 + + + @@ -3044,6 +3437,33 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA 39.ImportedFromIB2 4.IBAttributePlaceholdersKey 4.IBPluginDependency + 426.IBEditorWindowLastContentRect + 426.IBPluginDependency + 426.IBWindowTemplateEditedContentRect + 426.NSWindowTemplate.visibleAtLaunch + 426.windowTemplate.hasMaxSize + 426.windowTemplate.hasMinSize + 426.windowTemplate.maxSize + 426.windowTemplate.minSize + 427.IBPluginDependency + 428.IBPluginDependency + 429.IBPluginDependency + 430.IBPluginDependency + 431.IBPluginDependency + 432.IBPluginDependency + 433.IBPluginDependency + 434.IBPluginDependency + 435.IBPluginDependency + 436.IBPluginDependency + 437.IBPluginDependency + 442.IBPluginDependency + 443.IBPluginDependency + 444.IBPluginDependency + 445.IBPluginDependency + 450.IBPluginDependency + 451.IBAttributePlaceholdersKey + 451.IBPluginDependency + 452.IBPluginDependency 46.IBEditorWindowLastContentRect 46.IBPluginDependency 47.IBPluginDependency @@ -3085,9 +3505,9 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA com.apple.WebKitIBPlugin - {{350, 207}, {346, 102}} + {{466, 293}, {346, 102}} com.apple.InterfaceBuilder.CocoaPlugin - {{350, 207}, {346, 102}} + {{466, 293}, {346, 102}} @@ -3131,7 +3551,7 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA PBGitRevisionCell com.apple.InterfaceBuilder.CocoaPlugin - {{841, 929}, {616, 227}} + {{496, 1095}, {616, 285}} com.apple.InterfaceBuilder.CocoaPlugin {{132, 614}, {616, 0}} com.apple.InterfaceBuilder.CocoaPlugin @@ -3186,6 +3606,40 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA com.apple.InterfaceBuilder.CocoaPlugin + {{864, 502}, {474, 130}} + com.apple.InterfaceBuilder.CocoaPlugin + {{864, 502}, {474, 130}} + + + + {1000, 130} + {346, 102} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Create Branch + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{483, 605}, {852, 432}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3217,7 +3671,7 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA - 425 + 457 @@ -3376,7 +3830,10 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA YES addRef: + addRemoteButton: + addRemoteSheet: changeBranch: + closeAddRemoteSheet: closeSheet: fetchButton: pullButton: @@ -3387,6 +3844,8 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA YES id + id + id NSMenuItem id id @@ -3394,12 +3853,17 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA id id id + id YES YES + addRemoteErrorMessage + addRemoteName + addRemoteSheet + addRemoteURL branchPopUp commitController commitList @@ -3410,6 +3874,10 @@ TG9jYWwgYnJhbmNoZXMnIHdpbGwgbm90IHdvcmsuA YES + NSTextField + NSTextField + NSWindow + NSTextField NSPopUpButton NSArrayController PBCommitList diff --git a/PBRefController.h b/PBRefController.h index c2f2f7d..da8004d 100644 --- a/PBRefController.h +++ b/PBRefController.h @@ -21,6 +21,11 @@ IBOutlet NSWindow *newBranchSheet; IBOutlet NSTextField *newBranchName; IBOutlet NSTextField *errorMessage; + + IBOutlet NSWindow *addRemoteSheet; + IBOutlet NSTextField *addRemoteName; + IBOutlet NSTextField *addRemoteURL; + IBOutlet NSTextField *addRemoteErrorMessage; IBOutlet NSPopUpButton *branchPopUp; } @@ -34,6 +39,10 @@ - (IBAction)pullButton:(id)sender; - (IBAction)fetchButton:(id)sender; +- (IBAction)addRemoteButton:(id)sender; +- (IBAction)addRemoteSheet:(id)sender; +- (IBAction)closeAddRemoteSheet:(id)sender; + - (NSArray *) menuItemsForRef:(PBGitRef *)ref commit:(PBGitCommit *)commit; - (void) changeBranch:(NSMenuItem *)sender; @@ -44,6 +53,7 @@ - (BOOL) pushImpl:(NSString *)refName; - (BOOL) rebaseImpl:(NSString *)refName; - (BOOL) fetchImpl:(NSString *)refName; +- (BOOL) addRemoteImplWithName:(NSString *)remoteName forURL:(NSString *)remoteURL; - (void) showMessageSheet:(NSString *)title message:(NSString *)msg; diff --git a/PBRefController.m b/PBRefController.m index 5010079..faf9464 100644 --- a/PBRefController.m +++ b/PBRefController.m @@ -185,6 +185,25 @@ return success; } +- (BOOL) addRemoteImplWithName:(NSString *)remoteName forURL:(NSString *)remoteURL +{ + int ret = 1; + BOOL success = NO; + if (!remoteName || !remoteURL) { + return success; + } + NSString *rval = [historyController.repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"remote", @"add", @"-f", remoteName, remoteURL, nil] retValue: &ret]; + if (ret) { + NSString *info = [NSString stringWithFormat:@"There was an error adding the remote.\n\n%d\n%@", ret, rval]; + [[historyController.repository windowController] showMessageSheet:@"Adding Remote failed" infoText:info]; + return success; + } + [historyController.repository reloadRefs]; + [commitController rearrangeObjects]; + success = YES; + return success; +} + # pragma mark Tableview delegate methods - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pboard @@ -374,6 +393,61 @@ [newBranchSheet orderOut:self]; } +- (void) addRemoteButton:(id)sender +{ + [addRemoteErrorMessage setStringValue:@""]; + [addRemoteName setStringValue:@""]; + [addRemoteName setTextColor:[NSColor blackColor]]; + [addRemoteURL setStringValue:@""]; + [NSApp beginSheet:addRemoteSheet + modalForWindow:[[historyController view] window] + modalDelegate:NULL + didEndSelector:NULL + contextInfo:NULL]; +} + +- (void) addRemoteSheet:(id)sender +{ + NSString *remoteName = [addRemoteName stringValue]; + NSString *remoteURL = [addRemoteURL stringValue]; + NSLog(@"%s remoteName = %@ remoteURL = %@", _cmd, remoteName, remoteURL); + + if ([remoteName isEqualToString:@""]) { + [addRemoteErrorMessage setStringValue:@"Remote name is required"]; + return; + } + + NSRange range = [remoteName rangeOfCharacterFromSet:[NSCharacterSet whitespaceCharacterSet]]; + if (range.location != NSNotFound) { + [addRemoteErrorMessage setStringValue:@"Whitespace is not allowed"]; + [addRemoteName setTextColor:[NSColor redColor]]; + return; + } + + [addRemoteName setTextColor:[NSColor blackColor]]; + + if ([remoteURL isEqualToString:@""]) { + [addRemoteErrorMessage setStringValue:@"Remote URL is required"]; + return; + } + + [addRemoteURL setTextColor:[NSColor blackColor]]; + + [self closeAddRemoteSheet:sender]; + + [self addRemoteImplWithName:remoteName forURL:remoteURL]; +} + +- (void) closeAddRemoteSheet:(id)sender +{ + [NSApp endSheet:addRemoteSheet]; + [addRemoteErrorMessage setStringValue:@""]; + [addRemoteName setStringValue:@""]; + [addRemoteName setTextColor:[NSColor blackColor]]; + [addRemoteURL setStringValue:@""]; + [addRemoteSheet orderOut:self]; +} + # pragma mark Branches menu - (void) updateBranchMenu