Skip to content

Commit 25621b3

Browse files
committed
Reorder methods so actions are all in one place
1 parent 93d05ed commit 25621b3

File tree

1 file changed

+106
-107
lines changed

1 file changed

+106
-107
lines changed

Classes/Controllers/PBGitWindowController.m

Lines changed: 106 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -267,61 +267,6 @@ - (void)revealURLsInFinder:(NSArray <NSURL *> *)fileURLs
267267
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
268268
}
269269

270-
#pragma mark IBActions
271-
272-
- (id <PBGitRefish>)refishForSender:(id)sender refishTypes:(NSArray *)types
273-
{
274-
if ([sender isKindOfClass:[NSMenuItem class]]) {
275-
id <PBGitRefish> refish = nil;
276-
if ([(refish = [(NSMenuItem *)sender representedObject]) conformsToProtocol:@protocol(PBGitRefish)]) {
277-
if (!types || [types indexOfObject:[refish refishType]] != NSNotFound)
278-
return refish;
279-
}
280-
281-
return nil;
282-
}
283-
284-
if ([types indexOfObject:kGitXCommitType] == NSNotFound)
285-
return nil;
286-
287-
return sidebarController.historyViewController.selectedCommits.firstObject;
288-
}
289-
290-
- (IBAction) showAddRemoteSheet:(id)sender
291-
{
292-
[self addRemote:sender];
293-
}
294-
295-
- (IBAction)addRemote:(id)sender
296-
{
297-
[PBAddRemoteSheet beginSheetWithWindowController:self completionHandler:^(PBAddRemoteSheet *addSheet, NSModalResponse returnCode) {
298-
if (returnCode != NSModalResponseOK) return;
299-
300-
NSString *remoteName = addSheet.remoteName.stringValue;
301-
NSString *remoteURL = addSheet.remoteURL.stringValue;
302-
303-
NSString *description = [NSString stringWithFormat:@"Adding remote \"%@\"", remoteName];
304-
305-
PBRemoteProgressSheet *progressSheet = [PBRemoteProgressSheet progressSheetWithTitle:@"Adding remote"
306-
description:description
307-
windowController:self];
308-
[progressSheet beginProgressSheetForBlock:^{
309-
NSError *error = nil;
310-
BOOL success = [self.repository addRemote:remoteName withURL:remoteURL error:&error];
311-
return success ? nil : error;
312-
} completionHandler:^(NSError *error) {
313-
if (error) {
314-
[self showErrorSheet:error];
315-
return;
316-
}
317-
318-
// Now fetch that remote
319-
PBGitRef *remoteRef = [self.repository refForName:remoteName];
320-
[self performFetchForRef:remoteRef];
321-
}];
322-
}];
323-
}
324-
325270
- (void)performFetchForRef:(PBGitRef *)ref
326271
{
327272
NSString *remoteName = (ref ? ref.remoteName : @"all remotes");
@@ -342,16 +287,6 @@ - (void)performFetchForRef:(PBGitRef *)ref
342287
}];
343288
}
344289

345-
- (IBAction) fetchRemote:(id)sender {
346-
/* FIXME: this is wrong, you can right-click in the sidebar but try to fetch the *selected* ref */
347-
PBGitRef *ref = [self selectedItem].ref;
348-
[self performFetchForRef:ref];
349-
}
350-
351-
- (IBAction) fetchAllRemotes:(id)sender {
352-
[self performFetchForRef:nil];
353-
}
354-
355290
- (void)performPullForBranch:(PBGitRef *)branchRef remote:(PBGitRef *)remoteRef rebase:(BOOL)rebase {
356291
NSString *description = nil;
357292
if (!branchRef && !remoteRef) {
@@ -379,26 +314,6 @@ - (void)performPullForBranch:(PBGitRef *)branchRef remote:(PBGitRef *)remoteRef
379314
}];
380315
}
381316

382-
- (IBAction) pullRemote:(id)sender {
383-
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
384-
[self performPullForBranch:ref remote:nil rebase:NO];
385-
}
386-
387-
- (IBAction) pullRebaseRemote:(id)sender {
388-
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
389-
[self performPullForBranch:ref remote:nil rebase:YES];
390-
}
391-
392-
- (IBAction) pullDefaultRemote:(id)sender {
393-
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
394-
[self performPullForBranch:ref remote:nil rebase:NO];
395-
}
396-
397-
- (IBAction) pullRebaseDefaultRemote:(id)sender {
398-
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
399-
[self performPullForBranch:ref remote:nil rebase:YES];
400-
}
401-
402317
- (void)performPushForBranch:(PBGitRef *)branchRef toRemote:(PBGitRef *)remoteRef
403318
{
404319
if ((!branchRef && !remoteRef)
@@ -462,11 +377,117 @@ - (void)performPushForBranch:(PBGitRef *)branchRef toRemote:(PBGitRef *)remoteRe
462377
}];
463378
}
464379

380+
- (NSArray <NSURL *> *)selectedURLsFromSender:(id)sender {
381+
NSArray *selectedFiles = [sender representedObject];
382+
if (![selectedFiles isKindOfClass:[NSArray class]] || [selectedFiles count] == 0)
383+
return nil;
384+
385+
NSMutableArray *URLs = [NSMutableArray array];
386+
for (id file in selectedFiles) {
387+
NSString *path = file;
388+
// Those can be PBChangedFiles sent by PBGitIndexController. Get their path.
389+
if ([file respondsToSelector:@selector(path)]) {
390+
path = [file path];
391+
}
392+
393+
if (![path isKindOfClass:[NSString class]])
394+
continue;
395+
[URLs addObject:[self.repository.workingDirectoryURL URLByAppendingPathComponent:path]];
396+
}
397+
398+
return URLs;
399+
}
400+
401+
#pragma mark IBActions
402+
403+
- (id <PBGitRefish>)refishForSender:(id)sender refishTypes:(NSArray *)types
404+
{
405+
if ([sender isKindOfClass:[NSMenuItem class]]) {
406+
id <PBGitRefish> refish = nil;
407+
if ([(refish = [(NSMenuItem *)sender representedObject]) conformsToProtocol:@protocol(PBGitRefish)]) {
408+
if (!types || [types indexOfObject:[refish refishType]] != NSNotFound)
409+
return refish;
410+
}
411+
412+
return nil;
413+
}
414+
415+
if ([types indexOfObject:kGitXCommitType] == NSNotFound)
416+
return nil;
417+
418+
return sidebarController.historyViewController.selectedCommits.firstObject;
419+
}
420+
465421
- (PBSourceViewItem *) selectedItem {
466422
NSOutlineView *sourceView = sidebarController.sourceView;
467423
return [sourceView itemAtRow:sourceView.selectedRow];
468424
}
469425

426+
- (IBAction) showAddRemoteSheet:(id)sender
427+
{
428+
[self addRemote:sender];
429+
}
430+
431+
- (IBAction)addRemote:(id)sender
432+
{
433+
[PBAddRemoteSheet beginSheetWithWindowController:self completionHandler:^(PBAddRemoteSheet *addSheet, NSModalResponse returnCode) {
434+
if (returnCode != NSModalResponseOK) return;
435+
436+
NSString *remoteName = addSheet.remoteName.stringValue;
437+
NSString *remoteURL = addSheet.remoteURL.stringValue;
438+
439+
NSString *description = [NSString stringWithFormat:@"Adding remote \"%@\"", remoteName];
440+
441+
PBRemoteProgressSheet *progressSheet = [PBRemoteProgressSheet progressSheetWithTitle:@"Adding remote"
442+
description:description
443+
windowController:self];
444+
[progressSheet beginProgressSheetForBlock:^{
445+
NSError *error = nil;
446+
BOOL success = [self.repository addRemote:remoteName withURL:remoteURL error:&error];
447+
return success ? nil : error;
448+
} completionHandler:^(NSError *error) {
449+
if (error) {
450+
[self showErrorSheet:error];
451+
return;
452+
}
453+
454+
// Now fetch that remote
455+
PBGitRef *remoteRef = [self.repository refForName:remoteName];
456+
[self performFetchForRef:remoteRef];
457+
}];
458+
}];
459+
}
460+
461+
- (IBAction) fetchRemote:(id)sender {
462+
/* FIXME: this is wrong, you can right-click in the sidebar but try to fetch the *selected* ref */
463+
PBGitRef *ref = [self selectedItem].ref;
464+
[self performFetchForRef:ref];
465+
}
466+
467+
- (IBAction) fetchAllRemotes:(id)sender {
468+
[self performFetchForRef:nil];
469+
}
470+
471+
- (IBAction) pullRemote:(id)sender {
472+
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
473+
[self performPullForBranch:ref remote:nil rebase:NO];
474+
}
475+
476+
- (IBAction) pullRebaseRemote:(id)sender {
477+
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
478+
[self performPullForBranch:ref remote:nil rebase:YES];
479+
}
480+
481+
- (IBAction) pullDefaultRemote:(id)sender {
482+
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
483+
[self performPullForBranch:ref remote:nil rebase:NO];
484+
}
485+
486+
- (IBAction) pullRebaseDefaultRemote:(id)sender {
487+
PBGitRef *ref = [self selectedItem].revSpecifier.ref;
488+
[self performPullForBranch:ref remote:nil rebase:YES];
489+
}
490+
470491
- (IBAction) stashSave:(id) sender
471492
{
472493
NSError *error = nil;
@@ -494,28 +515,6 @@ - (IBAction) stashPop:(id) sender
494515
if (!success) [self showErrorSheet:error];
495516
}
496517

497-
498-
- (NSArray <NSURL *> *)selectedURLsFromSender:(id)sender {
499-
NSArray *selectedFiles = [sender representedObject];
500-
if (![selectedFiles isKindOfClass:[NSArray class]] || [selectedFiles count] == 0)
501-
return nil;
502-
503-
NSMutableArray *URLs = [NSMutableArray array];
504-
for (id file in selectedFiles) {
505-
NSString *path = file;
506-
// Those can be PBChangedFiles sent by PBGitIndexController. Get their path.
507-
if ([file respondsToSelector:@selector(path)]) {
508-
path = [file path];
509-
}
510-
511-
if (![path isKindOfClass:[NSString class]])
512-
continue;
513-
[URLs addObject:[self.repository.workingDirectoryURL URLByAppendingPathComponent:path]];
514-
}
515-
516-
return URLs;
517-
}
518-
519518
- (IBAction) openFiles:(id)sender {
520519
NSArray <NSURL *> *fileURLs = [self selectedURLsFromSender:sender];
521520
[self openURLs:fileURLs];

0 commit comments

Comments
 (0)