Skip to content

Commit 004d7b7

Browse files
committed
Rewire delete-reference sheet
1 parent c16d5ad commit 004d7b7

File tree

2 files changed

+42
-54
lines changed

2 files changed

+42
-54
lines changed

Classes/Controllers/PBGitHistoryController.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,48 @@ - (IBAction) rebaseHeadBranch:(id)sender
768768
}
769769
}
770770

771+
- (IBAction)showDeleteRefSheet:(PBRefMenuItem *)sender
772+
{
773+
id <PBGitRefish> refish = [self refishForSender:sender refishTypes:@[kGitXBranchType]];
774+
if (!refish)
775+
return;
776+
777+
PBGitRef *ref = (PBGitRef *)refish;
778+
779+
void (^performDelete)(void) = ^{
780+
NSError *error = nil;
781+
BOOL success = [self.repository deleteRef:ref error:&error];
782+
if (!success) {
783+
[self.windowController showErrorSheet:error];
784+
}
785+
return;
786+
};
787+
788+
if ([PBGitDefaults isDialogWarningSuppressedForDialog:kDialogDeleteRef]) {
789+
performDelete();
790+
return;
791+
}
792+
793+
NSString *ref_desc = [NSString stringWithFormat:@"%@ '%@'", [ref refishType], [ref shortName]];
794+
795+
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:@"Delete %@?", ref_desc]
796+
defaultButton:@"Delete"
797+
alternateButton:@"Cancel"
798+
otherButton:nil
799+
informativeTextWithFormat:@"Are you sure you want to remove the %@?", ref_desc];
800+
[alert setShowsSuppressionButton:YES];
801+
802+
[alert beginSheetModalForWindow:self.windowController.window
803+
completionHandler:^(NSModalResponse returnCode) {
804+
if ([[alert suppressionButton] state] == NSOnState)
805+
[PBGitDefaults suppressDialogWarningForDialog:kDialogDeleteRef];
806+
807+
if (returnCode == NSModalResponseOK) {
808+
performDelete();
809+
}
810+
}];
811+
}
812+
771813
#pragma mark -
772814
#pragma mark Quick Look
773815

Classes/Controllers/PBRefController.m

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -144,60 +144,6 @@ - (IBAction) showTagInfoSheet:(PBRefMenuItem *)sender
144144
}
145145

146146

147-
#pragma mark Remove a branch, remote or tag
148-
149-
- (IBAction)showDeleteRefSheet:(PBRefMenuItem *)sender
150-
{
151-
id<PBGitRefish> refish = sender.refishs.firstObject;
152-
if ([refish refishType] == kGitXCommitType)
153-
return;
154-
155-
PBGitRef *ref = (PBGitRef *)refish;
156-
157-
if ([PBGitDefaults isDialogWarningSuppressedForDialog:kDialogDeleteRef]) {
158-
NSError *error = nil;
159-
BOOL success = [historyController.repository deleteRef:ref error:&error];
160-
if (!success) {
161-
[historyController.windowController showErrorSheet:error];
162-
}
163-
return;
164-
}
165-
166-
NSString *ref_desc = [NSString stringWithFormat:@"%@ '%@'", [ref refishType], [ref shortName]];
167-
168-
NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:@"Delete %@?", ref_desc]
169-
defaultButton:@"Delete"
170-
alternateButton:@"Cancel"
171-
otherButton:nil
172-
informativeTextWithFormat:@"Are you sure you want to remove the %@?", ref_desc];
173-
[alert setShowsSuppressionButton:YES];
174-
175-
[alert beginSheetModalForWindow:[historyController.windowController window]
176-
modalDelegate:self
177-
didEndSelector:@selector(deleteRefSheetDidEnd:returnCode:contextInfo:)
178-
contextInfo:(__bridge_retained void*)ref];
179-
}
180-
181-
- (void)deleteRefSheetDidEnd:(NSAlert *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
182-
{
183-
[[sheet window] orderOut:nil];
184-
185-
if ([[sheet suppressionButton] state] == NSOnState)
186-
[PBGitDefaults suppressDialogWarningForDialog:kDialogDeleteRef];
187-
188-
if (returnCode == NSAlertDefaultReturn) {
189-
PBGitRef *ref = (__bridge PBGitRef *)contextInfo;
190-
191-
NSError *error = nil;
192-
BOOL success = [historyController.repository deleteRef:ref error:&error];
193-
if (!success) {
194-
[historyController.windowController showErrorSheet:error];
195-
}
196-
}
197-
}
198-
199-
200-
201147
#pragma mark Contextual menus
202148

203149
- (NSArray<NSMenuItem *> *) menuItemsForRef:(PBGitRef *)ref

0 commit comments

Comments
 (0)