diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h index f87c462..6c99a20 100644 --- a/PBGitHistoryController.h +++ b/PBGitHistoryController.h @@ -42,6 +42,13 @@ - (IBAction) openSelectedFile: sender; - (void) updateQuicklookForce: (BOOL) force; +// Context menu methods +- (NSMenu *)contextMenuForTreeView; +- (NSArray *)menuItemsForPaths:(NSArray *)paths; +- (void)showCommitsFromTree:(id)sender; +- (void)showInFinderAction:(id)sender; +- (void)openFilesAction:(id)sender; + - (void) copyCommitInfo; - (BOOL) hasNonlinearPath; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index 9c18b72..c4d2679 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -203,6 +203,7 @@ [super removeView]; } +#pragma mark Table Column Methods - (NSMenu *)tableColumnMenu { NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Table columns menu"]; @@ -218,4 +219,76 @@ return menu; } +#pragma mark Tree Context Menu Methods + +- (void)showCommitsFromTree:(id)sender +{ + // TODO: Enable this from webview as well! + + NSMutableArray *filePaths = [NSMutableArray arrayWithObjects:@"HEAD", @"--", NULL]; + [filePaths addObjectsFromArray:[sender representedObject]]; + + PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithParameters:filePaths]; + + repository.currentBranch = [repository addBranch:revSpec]; +} + +- (void)showInFinderAction:(id)sender +{ + NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"]; + NSString *path; + NSWorkspace *ws = [NSWorkspace sharedWorkspace]; + + for (NSString *filePath in [sender representedObject]) { + path = [workingDirectory stringByAppendingPathComponent:filePath]; + [ws selectFile: path inFileViewerRootedAtPath:path]; + } + +} + +- (void)openFilesAction:(id)sender +{ + NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"]; + NSString *path; + NSWorkspace *ws = [NSWorkspace sharedWorkspace]; + + for (NSString *filePath in [sender representedObject]) { + path = [workingDirectory stringByAppendingPathComponent:filePath]; + [ws openFile:path]; + } +} + + +- (NSMenu *)contextMenuForTreeView +{ + NSArray *filePaths = [[treeController selectedObjects] valueForKey:@"fullPath"]; + + NSMenu *menu = [[NSMenu alloc] init]; + for (NSMenuItem *item in [self menuItemsForPaths:filePaths]) + [menu addItem:item]; + return menu; +} + +- (NSArray *)menuItemsForPaths:(NSArray *)paths +{ + BOOL multiple = [paths count] != 1; + NSMenuItem *historyItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show history of files" : @"Show history of file" + action:@selector(showCommitsFromTree:) + keyEquivalent:@""]; + NSMenuItem *finderItem = [[NSMenuItem alloc] initWithTitle:@"Show in Finder" + action:@selector(showInFinderAction:) + keyEquivalent:@""]; + NSMenuItem *openFilesItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Open Files" : @"Open File" + action:@selector(openFilesAction:) + keyEquivalent:@""]; + + NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, openFilesItem, nil]; + for (NSMenuItem *item in menuItems) { + [item setTarget:self]; + [item setRepresentedObject:paths]; + } + + return menuItems; +} + @end diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index 1a06286..329d003 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -2,14 +2,14 @@ 1050 - 9G55 + 9J61 677 - 949.43 + 949.46 353.00 YES - + YES @@ -345,6 +345,7 @@ YES Apple HTML pasteboard type + Apple PDF pasteboard type Apple PICT pasteboard type Apple URL pasteboard type Apple Web Archive pasteboard type @@ -355,6 +356,7 @@ NeXT Rich Text Format v1.0 pasteboard type NeXT TIFF v4.0 pasteboard type WebURLsWithTitlesPboardType + public.png public.url public.url-name @@ -2978,7 +2980,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{321, 79}, {852, 432}} + {{358, 67}, {852, 432}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3013,7 +3015,7 @@ - 274 + 286 @@ -3032,7 +3034,7 @@ YES PBGitHistoryController - id + PBWebHistoryController WebView @@ -3053,6 +3055,8 @@ setDetailedView: setRawView: setTreeView: + showCommitsFromTree: + showInFinderAction: toggleQuickView: @@ -3063,6 +3067,8 @@ id id id + id + id @@ -3073,6 +3079,7 @@ commitList fileBrowser searchField + treeContextMenu treeController webView @@ -3082,6 +3089,7 @@ NSTableView NSOutlineView NSSearchField + NSMenu NSTreeController id diff --git a/PBQLOutlineView.m b/PBQLOutlineView.m index 4e620bd..459d908 100644 --- a/PBQLOutlineView.m +++ b/PBQLOutlineView.m @@ -58,6 +58,25 @@ return fileNames; } +- (NSMenu *)menuForEvent:(NSEvent *)theEvent +{ + if ([theEvent type] == NSRightMouseDown) + { + // get the current selections for the outline view. + NSIndexSet *selectedRowIndexes = [self selectedRowIndexes]; + + // select the row that was clicked before showing the menu for the event + NSPoint mousePoint = [self convertPoint:[theEvent locationInWindow] fromView:nil]; + int row = [self rowAtPoint:mousePoint]; + + // figure out if the row that was just clicked on is currently selected + if ([selectedRowIndexes containsIndex:row] == NO) + [self selectRow:row byExtendingSelection:NO]; + } + + return [controller contextMenuForTreeView]; +} + /* Implemented to satisfy datasourcee protocol */ - (BOOL) outlineView: (NSOutlineView *)ov isItemExpandable: (id)item { return NO; } diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index 0f553b3..35979a4 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -76,21 +76,23 @@ contextMenuItemsForElement:(NSDictionary *)element { DOMNode *node = [element valueForKey:@"WebElementDOMNode"]; - // If clicked on the text, select the containing div - if ([[node className] isEqualToString:@"DOMText"]) + while (node) { + // Every ref has a class name of 'refs' and some other class. We check on that to see if we pressed on a ref. + if ([[node className] hasPrefix:@"refs "]) { + NSString *selectedRefString = [[[node childNodes] item:0] textContent]; + for (PBGitRef *ref in historyController.webCommit.refs) + { + if ([[ref shortName] isEqualToString:selectedRefString]) + return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit]; + } + NSLog(@"Could not find selected ref!"); + return defaultMenuItems; + } + if ([node hasAttributes] && [[node attributes] getNamedItem:@"representedFile"]) + return [historyController menuItemsForPaths:[NSArray arrayWithObject:[[[node attributes] getNamedItem:@"representedFile"] value]]]; + node = [node parentNode]; - - // Every ref has a class name of 'refs' and some other class. We check on that to see if we pressed on a ref. - if (![[node className] hasPrefix:@"refs "]) - return defaultMenuItems; - - NSString *selectedRefString = [[[node childNodes] item:0] textContent]; - for (PBGitRef *ref in historyController.webCommit.refs) - { - if ([[ref shortName] isEqualToString:selectedRefString]) - return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit]; } - NSLog(@"Could not find selected ref!"); return defaultMenuItems; } diff --git a/html/views/history/history.js b/html/views/history/history.js index b2e6b67..df2a2b0 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -205,26 +205,32 @@ var showDiff = function() { var link = document.createElement("a"); link.setAttribute("href", "#" + id); p.appendChild(link); - var buttonType = "" + var buttonType = ""; + var finalFile = ""; if (name1 == name2) { buttonType = "changed" - link.appendChild(document.createTextNode(name1)); + finalFile = name1; if (mode_change) p.appendChild(document.createTextNode(" mode " + old_mode + " -> " + new_mode)); } else if (name1 == "/dev/null") { buttonType = "created"; - link.appendChild(document.createTextNode(name2)); + finalFile = name2; } else if (name2 == "/dev/null") { buttonType = "deleted"; - link.appendChild(document.createTextNode(name1)); + finalFile = name1; } else { buttonType = "renamed"; - link.appendChild(document.createTextNode(name2)); + finalFile = name2; p.insertBefore(document.createTextNode(name1 + " -> "), link); } + + link.appendChild(document.createTextNode(finalFile)); + button.setAttribute("representedFile", finalFile); + link.setAttribute("representedFile", finalFile); + button.setAttribute("class", "button " + buttonType); button.appendChild(document.createTextNode(buttonType)); $("files").appendChild(button);