Skip to content

Commit a6a1660

Browse files
committed
Use the dialog method to alert when moving branch labels
1 parent a1a4196 commit a6a1660

File tree

3 files changed

+26
-44
lines changed

3 files changed

+26
-44
lines changed

Classes/Controllers/PBRefController.m

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,6 @@ - (NSDragOperation)tableView:(NSTableView*)tv
110110
return NSDragOperationNone;
111111
}
112112

113-
- (void) dropRef:(NSDictionary *)dropInfo
114-
{
115-
PBGitRef *ref = [dropInfo objectForKey:@"dragRef"];
116-
PBGitCommit *oldCommit = [dropInfo objectForKey:@"oldCommit"];
117-
PBGitCommit *dropCommit = [dropInfo objectForKey:@"dropCommit"];
118-
if (!ref || ! oldCommit || !dropCommit)
119-
return;
120-
121-
if (![historyController.repository updateReference:ref toPointAtCommit:dropCommit])
122-
123-
[dropCommit addRef:ref];
124-
[oldCommit removeRef:ref];
125-
[historyController.commitList reloadData];
126-
}
127-
128113
- (BOOL)tableView:(NSTableView *)aTableView
129114
acceptDrop:(id <NSDraggingInfo>)info
130115
row:(NSInteger)row
@@ -149,17 +134,6 @@ - (BOOL)tableView:(NSTableView *)aTableView
149134

150135
PBGitCommit *dropCommit = [[commitController arrangedObjects] objectAtIndex:row];
151136

152-
NSDictionary *dropInfo = [NSDictionary dictionaryWithObjectsAndKeys:
153-
ref, @"dragRef",
154-
oldCommit, @"oldCommit",
155-
dropCommit, @"dropCommit",
156-
nil];
157-
158-
if ([PBGitDefaults isDialogWarningSuppressedForDialog:kDialogAcceptDroppedRef]) {
159-
[self dropRef:dropInfo];
160-
return YES;
161-
}
162-
163137
NSString *subject = [dropCommit subject];
164138
if ([subject length] > 99)
165139
subject = [[subject substringToIndex:99] stringByAppendingString:@""];
@@ -168,19 +142,22 @@ - (BOOL)tableView:(NSTableView *)aTableView
168142
alert.messageText = [NSString stringWithFormat:NSLocalizedString(@"Move %@: %@", @""), [ref refishType], [ref shortName]];
169143
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"Move the %@ to point to the commit: %@", @""), [ref refishType], subject];
170144

171-
[alert addButtonWithTitle:@"Move"];
172-
[alert addButtonWithTitle:@"Cancel"];
173-
[alert setShowsSuppressionButton:YES];
174-
175-
[alert beginSheetModalForWindow:historyController.windowController.window
176-
completionHandler:^(NSModalResponse returnCode) {
177-
if (returnCode == NSAlertFirstButtonReturn) {
178-
[self dropRef:dropInfo];
179-
}
180-
181-
if ([[alert suppressionButton] state] == NSOnState)
182-
[PBGitDefaults suppressDialogWarningForDialog:kDialogAcceptDroppedRef];
183-
}];
145+
[alert addButtonWithTitle:NSLocalizedString(@"Move", @"Move branch label - default button")];
146+
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"Move branch label - cancel button")];
147+
148+
PBGitWindowController *wc = historyController.windowController;
149+
[wc confirmDialog:alert
150+
suppressionIdentifier:kDialogAcceptDroppedRef
151+
forAction:^{
152+
NSError *error = nil;
153+
if (![wc.repository updateReference:ref toPointAtCommit:dropCommit error:&error]) {
154+
[wc showErrorSheet:error];
155+
return;
156+
}
157+
158+
[dropCommit addRef:ref];
159+
[oldCommit removeRef:ref];
160+
}];
184161

185162
return YES;
186163
}

Classes/git/PBGitRepository.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ typedef enum branchFilterTypes {
8383

8484
- (BOOL)ignoreFilePaths:(NSArray *)filePaths error:(NSError **)error;
8585

86-
- (BOOL)updateReference:(PBGitRef *)ref toPointAtCommit:(PBGitCommit *)newCommit;
86+
- (BOOL)updateReference:(PBGitRef *)ref toPointAtCommit:(PBGitCommit *)newCommit error:(NSError **)error;
8787
- (NSString *)performDiff:(PBGitCommit *)startCommit against:(PBGitCommit *)diffCommit forFiles:(NSArray *)filePaths;
8888

8989
- (NSURL *) gitURL ;

Classes/git/PBGitRepository.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,12 +1081,17 @@ - (BOOL) deleteRef:(PBGitRef *)ref error:(NSError **)error
10811081
return YES;
10821082
}
10831083

1084-
- (BOOL)updateReference:(PBGitRef *)ref toPointAtCommit:(PBGitCommit *)newCommit {
1085-
NSError *error = nil;
1086-
BOOL success = [self launchTaskWithArguments:@[@"update-ref", @"-mUpdate from GitX", ref.ref, newCommit.SHA] error:&error];
1084+
- (BOOL)updateReference:(PBGitRef *)ref toPointAtCommit:(PBGitCommit *)newCommit error:(NSError **)error {
1085+
NSError *gitError = nil;
1086+
BOOL success = [self launchTaskWithArguments:@[@"update-ref", @"-mUpdate from GitX", ref.ref, newCommit.SHA] error:&gitError];
10871087
if (!success) {
1088-
PBLogError(error);
1088+
NSString *title = NSLocalizedString(@"Reference update failed", @"Reference update failure - error title");
1089+
NSString *message = NSLocalizedString(@"The reference %@ couldn't be update", @"Reference update failure - error message");
1090+
message = [NSString stringWithFormat:message, ref.shortName];
1091+
1092+
return PBReturnError(error, title, message, gitError);
10891093
}
1094+
[self reloadRefs];
10901095
return success;
10911096
}
10921097

0 commit comments

Comments
 (0)