Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions Classes/Controllers/PBGitSidebarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ - (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode
[historyViewController.searchController setHistorySearch:searchString mode:mode];
}

- (void) openSubmoduleFromMenuItem:(NSMenuItem *)menuItem
{
[self openSubmodule:[menuItem representedObject]];
}

- (void) openSubmodule:(PBGitSubmodule *)submodule
{
NSURL *submoduleURL = [NSURL fileURLWithPath:[submodule path]];

if (submoduleURL) {
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:submoduleURL display:YES completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {
if (error) {
[NSApp presentError:error];
}
}];
}
}

#pragma mark NSOutlineView delegate methods

- (void)outlineViewSelectionDidChange:(NSNotification *)notification
Expand Down Expand Up @@ -233,12 +251,7 @@ - (void)doubleClicked:(id)object {
if ([[sourceView itemAtRow:rowNumber] isKindOfClass:[PBGitSVSubmoduleItem class]]) {
PBGitSVSubmoduleItem *subModule = [sourceView itemAtRow:rowNumber];

NSURL *url = [NSURL fileURLWithPath:subModule.submodule.path];
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url
display:YES
error:nil];

;
[self openSubmodule:[subModule submodule]];
}
}

Expand Down Expand Up @@ -354,7 +367,7 @@ - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTabl

- (void) updateActionMenu
{
[actionButton setEnabled:([[self selectedItem] ref] != nil)];
[actionButton setEnabled:([[self selectedItem] ref] != nil || [[self selectedItem] isKindOfClass:[PBGitSVSubmoduleItem class]])];
}

- (void) addMenuItemsForRef:(PBGitRef *)ref toMenu:(NSMenu *)menu
Expand All @@ -366,6 +379,17 @@ - (void) addMenuItemsForRef:(PBGitRef *)ref toMenu:(NSMenu *)menu
[menu addItem:menuItem];
}

- (void) addMenuItemsForSubmodule:(PBGitSubmodule *)submodule toMenu:(NSMenu *)menu
{
if (!submodule)
return;

NSMenuItem *menuItem = [menu addItemWithTitle:NSLocalizedString(@"Open Submodule", @"Open Submodule menu item") action:@selector(openSubmoduleFromMenuItem:) keyEquivalent:@""];

[menuItem setTarget:self];
[menuItem setRepresentedObject:submodule];
}

- (NSMenuItem *) actionIconItem
{
NSMenuItem *actionIconItem = [[NSMenuItem alloc] initWithTitle:@"" action:NULL keyEquivalent:@""];
Expand All @@ -379,15 +403,21 @@ - (NSMenuItem *) actionIconItem
- (NSMenu *) menuForRow:(NSInteger)row
{
PBSourceViewItem *viewItem = [sourceView itemAtRow:row];

PBGitRef *ref = [viewItem ref];
if (!ref)
PBGitSubmodule *submodule = nil;

if ([viewItem isKindOfClass:[PBGitSVSubmoduleItem class]]) {
submodule = [(PBGitSVSubmoduleItem *)viewItem submodule];
}

if (!ref && !submodule)
return nil;

NSMenu *menu = [[NSMenu alloc] init];
[menu setAutoenablesItems:NO];
[self addMenuItemsForRef:ref toMenu:menu];

[self addMenuItemsForSubmodule:submodule toMenu:menu];

return menu;
}

Expand All @@ -399,6 +429,10 @@ - (void) menuNeedsUpdate:(NSMenu *)menu

PBGitRef *ref = [[self selectedItem] ref];
[self addMenuItemsForRef:ref toMenu:menu];

if ([[self selectedItem] isKindOfClass:[PBGitSVSubmoduleItem class]]) {
[self addMenuItemsForSubmodule:[(PBGitSVSubmoduleItem *)[self selectedItem] submodule] toMenu:menu];
}
}


Expand Down