From d04362ba824ce60bb12115330a0aa86e3bdce176 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sun, 29 Mar 2009 00:46:18 +0000 Subject: [PATCH 1/8] History fileview: select current item on rightclick --- PBQLOutlineView.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/PBQLOutlineView.m b/PBQLOutlineView.m index 4e620bd..24f43e1 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 [super menuForEvent:theEvent]; +} + /* Implemented to satisfy datasourcee protocol */ - (BOOL) outlineView: (NSOutlineView *)ov isItemExpandable: (id)item { return NO; } From d973dc5ba7cc4a33efbb79d5b3e429f12a5fabc0 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Sun, 29 Mar 2009 00:44:58 +0000 Subject: [PATCH 2/8] Display context menu in the history tree to show related commits Signed-off-by: Johannes Gilger --- PBGitHistoryController.h | 1 + PBGitHistoryController.m | 12 ++++++++ PBGitHistoryView.xib | 65 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h index f87c462..f9b7f8f 100644 --- a/PBGitHistoryController.h +++ b/PBGitHistoryController.h @@ -41,6 +41,7 @@ - (IBAction) toggleQuickView: sender; - (IBAction) openSelectedFile: sender; - (void) updateQuicklookForce: (BOOL) force; +- (void) showCommitsFromTree:(id) sender; - (void) copyCommitInfo; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index 9c18b72..6562465 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -218,4 +218,16 @@ return menu; } +- (void) showCommitsFromTree:(id) sender +{ + // TODO: Enable this from webview as well! + + NSMutableArray *filePaths = [NSMutableArray arrayWithObjects:@"HEAD", @"--", NULL]; + for (PBGitTree *tree in [treeController selectedObjects]) + [filePaths addObject:[tree fullPath]]; + PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithParameters:filePaths]; + + repository.currentBranch = [repository addBranch:revSpec]; +} + @end diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index 1a06286..2fdd4fa 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -2,12 +2,13 @@ 1050 - 9G55 + 9J61 677 - 949.43 + 949.46 353.00 YES + @@ -345,6 +346,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 +357,7 @@ NeXT Rich Text Format v1.0 pasteboard type NeXT TIFF v4.0 pasteboard type WebURLsWithTitlesPboardType + public.png public.url public.url-name @@ -1515,6 +1518,20 @@ YES + + + + YES + + + Commits touching paths + + 2147483647 + + + + + @@ -2105,6 +2122,22 @@ 274 + + + showCommitsFromTree: + + + + 281 + + + + menu + + + + 282 + @@ -2735,6 +2768,20 @@ + + 276 + + + YES + + + + + + 275 + + + @@ -2814,6 +2861,9 @@ 27.ImportedFromIB2 272.IBPluginDependency 273.IBPluginDependency + 275.IBPluginDependency + 276.IBEditorWindowLastContentRect + 276.IBPluginDependency 28.IBPluginDependency 28.IBShouldRemoveOnLegacySave 29.IBPluginDependency @@ -2945,6 +2995,9 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + {{126, 715}, {223, 23}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2978,7 +3031,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{321, 79}, {852, 432}} + {{59, 317}, {852, 432}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3013,7 +3066,7 @@ - 274 + 282 @@ -3032,7 +3085,7 @@ YES PBGitHistoryController - id + PBWebHistoryController WebView @@ -3053,6 +3106,7 @@ setDetailedView: setRawView: setTreeView: + showCommitsFromTree: toggleQuickView: @@ -3063,6 +3117,7 @@ id id id + id From dc234cfdc9de05cb0c81a968412f76ef9204e33f Mon Sep 17 00:00:00 2001 From: Johannes Gilger Date: Sat, 13 Jun 2009 11:08:01 +0200 Subject: [PATCH 3/8] PBGitHistory: Add "Show in Finder" to files This adds the "Show in Finder" menu-entry and logic to files in the tree-view of the history. Also the button "Show commits touching paths" was renamed to "Show history of files". Signed-off-by: Johannes Gilger --- PBGitHistoryController.h | 3 ++- PBGitHistoryController.m | 16 +++++++++++++++- PBGitHistoryView.xib | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h index f9b7f8f..0007760 100644 --- a/PBGitHistoryController.h +++ b/PBGitHistoryController.h @@ -41,7 +41,8 @@ - (IBAction) toggleQuickView: sender; - (IBAction) openSelectedFile: sender; - (void) updateQuicklookForce: (BOOL) force; -- (void) showCommitsFromTree:(id) sender; +- (void)showCommitsFromTree:(id)sender; +- (void)showInFinderAction:(id)sender; - (void) copyCommitInfo; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index 6562465..bdfb843 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -218,7 +218,7 @@ return menu; } -- (void) showCommitsFromTree:(id) sender +- (void)showCommitsFromTree:(id)sender { // TODO: Enable this from webview as well! @@ -230,4 +230,18 @@ repository.currentBranch = [repository addBranch:revSpec]; } +- (void)showInFinderAction:(id)sender +{ + NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"]; + NSString *path; + NSWorkspace *ws = [NSWorkspace sharedWorkspace]; + + for (PBGitTree *tree in [treeController selectedObjects]) { + path = [workingDirectory stringByAppendingPathComponent:[tree fullPath]]; + [ws selectFile: path inFileViewerRootedAtPath:path]; + } + +} + + @end diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index 2fdd4fa..6e44446 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -8,9 +8,9 @@ 353.00 YES - + - + YES @@ -1524,7 +1524,15 @@ YES - Commits touching paths + Show history of file(s) + + 2147483647 + + + + + + Show in Finder 2147483647 @@ -2138,6 +2146,14 @@ 282 + + + showInFinderAction: + + + + 285 + @@ -2774,6 +2790,7 @@ YES + @@ -2782,6 +2799,11 @@ + + 284 + + + @@ -2866,6 +2888,7 @@ 276.IBPluginDependency 28.IBPluginDependency 28.IBShouldRemoveOnLegacySave + 284.IBPluginDependency 29.IBPluginDependency 29.IBShouldRemoveOnLegacySave 3.IBPluginDependency @@ -2995,11 +3018,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{126, 715}, {223, 23}} + {{225, 683}, {202, 43}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3031,7 +3055,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{59, 317}, {852, 432}} + {{76, 44}, {852, 432}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3066,7 +3090,7 @@ - 282 + 285 @@ -3107,6 +3131,7 @@ setRawView: setTreeView: showCommitsFromTree: + showInFinderAction: toggleQuickView: @@ -3118,6 +3143,7 @@ id id id + id From 47e182a9109cd055c0910370739ce2d71bef3513 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 16 Jun 2009 18:10:31 +0100 Subject: [PATCH 4/8] HistoryController: Add some marks --- PBGitHistoryController.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index bdfb843..00a09c7 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,6 +219,8 @@ return menu; } +#pragma mark Tree Context Menu Methods + - (void)showCommitsFromTree:(id)sender { // TODO: Enable this from webview as well! From c9609f22b69260928b5f7979f6944116a5b8b424 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 16 Jun 2009 18:49:24 +0100 Subject: [PATCH 5/8] WebHistoryController: Refactor menu search to be recursive This way it doesn't matter where in an element you click, as long as one of its parents has the required attributes, you get the menu --- PBWebHistoryController.m | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index 0f553b3..ca8bac7 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -76,21 +76,21 @@ 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; + } + 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; } From 1199c56e932a91bd4bd4154f47635787ef3bb893 Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 16 Jun 2009 18:28:37 +0100 Subject: [PATCH 6/8] HistoryController: Use a programatically created context menu This allows us to differentiate between one or multiple files, and will also come in use when we want to create a context menu from the webview later on We now use representedObjects to store the selected paths. That should make it possible to reuse the menu's from somewhere else. --- PBGitHistoryController.h | 4 ++ PBGitHistoryController.m | 36 +++++++++++++++-- PBGitHistoryView.xib | 83 +++------------------------------------- PBQLOutlineView.m | 2 +- 4 files changed, 42 insertions(+), 83 deletions(-) diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h index 0007760..f7298c4 100644 --- a/PBGitHistoryController.h +++ b/PBGitHistoryController.h @@ -41,6 +41,10 @@ - (IBAction) toggleQuickView: sender; - (IBAction) openSelectedFile: sender; - (void) updateQuicklookForce: (BOOL) force; + +// Context menu methods +- (NSMenu *)contextMenuForTreeView; +- (NSArray *)menuItemsForPaths:(NSArray *)paths; - (void)showCommitsFromTree:(id)sender; - (void)showInFinderAction:(id)sender; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index 00a09c7..a02c041 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -226,8 +226,8 @@ // TODO: Enable this from webview as well! NSMutableArray *filePaths = [NSMutableArray arrayWithObjects:@"HEAD", @"--", NULL]; - for (PBGitTree *tree in [treeController selectedObjects]) - [filePaths addObject:[tree fullPath]]; + [filePaths addObjectsFromArray:[sender representedObject]]; + PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithParameters:filePaths]; repository.currentBranch = [repository addBranch:revSpec]; @@ -239,12 +239,40 @@ NSString *path; NSWorkspace *ws = [NSWorkspace sharedWorkspace]; - for (PBGitTree *tree in [treeController selectedObjects]) { - path = [workingDirectory stringByAppendingPathComponent:[tree fullPath]]; + for (NSString *filePath in [sender representedObject]) { + path = [workingDirectory stringByAppendingPathComponent:filePath]; [ws selectFile: path inFileViewerRootedAtPath: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 *finderItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show items in Finder" : @"Show item in Finder" + action:@selector(showInFinderAction:) + keyEquivalent:@""]; + NSMenuItem *historyItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show history of files" : @"Show history of file" + action:@selector(showCommitsFromTree:) + keyEquivalent:@""]; + + NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, nil]; + for (NSMenuItem *item in menuItems) { + [item setTarget:self]; + [item setRepresentedObject:paths]; + } + + return menuItems; +} @end diff --git a/PBGitHistoryView.xib b/PBGitHistoryView.xib index 6e44446..329d003 100644 --- a/PBGitHistoryView.xib +++ b/PBGitHistoryView.xib @@ -8,9 +8,8 @@ 353.00 YES - - + YES @@ -1518,28 +1517,6 @@ YES - - - - YES - - - Show history of file(s) - - 2147483647 - - - - - - Show in Finder - - 2147483647 - - - - - @@ -2130,30 +2107,6 @@ 274 - - - showCommitsFromTree: - - - - 281 - - - - menu - - - - 282 - - - - showInFinderAction: - - - - 285 - @@ -2784,26 +2737,6 @@ - - 276 - - - YES - - - - - - - 275 - - - - - 284 - - - @@ -2883,12 +2816,8 @@ 27.ImportedFromIB2 272.IBPluginDependency 273.IBPluginDependency - 275.IBPluginDependency - 276.IBEditorWindowLastContentRect - 276.IBPluginDependency 28.IBPluginDependency 28.IBShouldRemoveOnLegacySave - 284.IBPluginDependency 29.IBPluginDependency 29.IBShouldRemoveOnLegacySave 3.IBPluginDependency @@ -3018,12 +2947,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{225, 683}, {202, 43}} - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3055,7 +2980,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{76, 44}, {852, 432}} + {{358, 67}, {852, 432}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3090,7 +3015,7 @@ - 285 + 286 @@ -3154,6 +3079,7 @@ commitList fileBrowser searchField + treeContextMenu treeController webView @@ -3163,6 +3089,7 @@ NSTableView NSOutlineView NSSearchField + NSMenu NSTreeController id diff --git a/PBQLOutlineView.m b/PBQLOutlineView.m index 24f43e1..459d908 100644 --- a/PBQLOutlineView.m +++ b/PBQLOutlineView.m @@ -74,7 +74,7 @@ [self selectRow:row byExtendingSelection:NO]; } - return [super menuForEvent:theEvent]; + return [controller contextMenuForTreeView]; } /* Implemented to satisfy datasourcee protocol */ From a002e3316cd5ec6149ac63849050c9fb667fc35d Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 16 Jun 2009 19:29:43 +0100 Subject: [PATCH 7/8] WebHistoryView: Also use the tree context menu --- PBWebHistoryController.m | 2 ++ html/views/history/history.js | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index ca8bac7..35979a4 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -88,6 +88,8 @@ contextMenuItemsForElement:(NSDictionary *)element 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]; } diff --git a/html/views/history/history.js b/html/views/history/history.js index 087f802..b5270cd 100644 --- a/html/views/history/history.js +++ b/html/views/history/history.js @@ -202,26 +202,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); From 7427cbe05d1d96490c18d642d5ea613d0f8b4caf Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Tue, 16 Jun 2009 19:40:18 +0100 Subject: [PATCH 8/8] HistoryController: Add "Open Files" menu item --- PBGitHistoryController.h | 1 + PBGitHistoryController.m | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h index f7298c4..6c99a20 100644 --- a/PBGitHistoryController.h +++ b/PBGitHistoryController.h @@ -47,6 +47,7 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths; - (void)showCommitsFromTree:(id)sender; - (void)showInFinderAction:(id)sender; +- (void)openFilesAction:(id)sender; - (void) copyCommitInfo; diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index a02c041..c4d2679 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -246,6 +246,19 @@ } +- (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"]; @@ -259,14 +272,17 @@ - (NSArray *)menuItemsForPaths:(NSArray *)paths { BOOL multiple = [paths count] != 1; - NSMenuItem *finderItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show items in Finder" : @"Show item in Finder" - action:@selector(showInFinderAction:) - keyEquivalent:@""]; 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, nil]; + NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, openFilesItem, nil]; for (NSMenuItem *item in menuItems) { [item setTarget:self]; [item setRepresentedObject:paths];