Merge commit 'origin/jg/tree_context'

* commit 'origin/jg/tree_context':
  HistoryController: Add "Open Files" menu item
  WebHistoryView: Also use the tree context menu
  HistoryController: Use a programatically created context menu
  WebHistoryController: Refactor menu search to be recursive
  HistoryController: Add some marks
  PBGitHistory: Add "Show in Finder" to files
  Display context menu in the history tree to show related commits
  History fileview: select current item on rightclick
This commit is contained in:
Pieter de Bie
2009-06-20 22:28:19 +01:00
6 changed files with 139 additions and 24 deletions
+7
View File
@@ -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;
+73
View File
@@ -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
+14 -6
View File
@@ -2,14 +2,14 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03">
<data>
<int key="IBDocument.SystemTarget">1050</int>
<string key="IBDocument.SystemVersion">9G55</string>
<string key="IBDocument.SystemVersion">9J61</string>
<string key="IBDocument.InterfaceBuilderVersion">677</string>
<string key="IBDocument.AppKitVersion">949.43</string>
<string key="IBDocument.AppKitVersion">949.46</string>
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="237"/>
<integer value="27"/>
<integer value="2"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -345,6 +345,7 @@
<object class="NSMutableArray" key="set.sortedObjects">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>Apple HTML pasteboard type</string>
<string>Apple PDF pasteboard type</string>
<string>Apple PICT pasteboard type</string>
<string>Apple URL pasteboard type</string>
<string>Apple Web Archive pasteboard type</string>
@@ -355,6 +356,7 @@
<string>NeXT Rich Text Format v1.0 pasteboard type</string>
<string>NeXT TIFF v4.0 pasteboard type</string>
<string>WebURLsWithTitlesPboardType</string>
<string>public.png</string>
<string>public.url</string>
<string>public.url-name</string>
</object>
@@ -2978,7 +2980,7 @@
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{321, 79}, {852, 432}}</string>
<string>{{358, 67}, {852, 432}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3013,7 +3015,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">274</int>
<int key="maxID">286</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3032,7 +3034,7 @@
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>PBGitHistoryController</string>
<string>id</string>
<string>PBWebHistoryController</string>
<string>WebView</string>
</object>
</object>
@@ -3053,6 +3055,8 @@
<string>setDetailedView:</string>
<string>setRawView:</string>
<string>setTreeView:</string>
<string>showCommitsFromTree:</string>
<string>showInFinderAction:</string>
<string>toggleQuickView:</string>
</object>
<object class="NSMutableArray" key="dict.values">
@@ -3063,6 +3067,8 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
@@ -3073,6 +3079,7 @@
<string>commitList</string>
<string>fileBrowser</string>
<string>searchField</string>
<string>treeContextMenu</string>
<string>treeController</string>
<string>webView</string>
</object>
@@ -3082,6 +3089,7 @@
<string>NSTableView</string>
<string>NSOutlineView</string>
<string>NSSearchField</string>
<string>NSMenu</string>
<string>NSTreeController</string>
<string>id</string>
</object>
+19
View File
@@ -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; }
+15 -13
View File
@@ -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;
}
+11 -5
View File
@@ -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);