Skip to content

Commit 64182ea

Browse files
author
Pieter de Bie
committed
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
2 parents a03401d + 7427cbe commit 64182ea

File tree

6 files changed

+139
-24
lines changed

6 files changed

+139
-24
lines changed

PBGitHistoryController.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
- (IBAction) openSelectedFile: sender;
4343
- (void) updateQuicklookForce: (BOOL) force;
4444

45+
// Context menu methods
46+
- (NSMenu *)contextMenuForTreeView;
47+
- (NSArray *)menuItemsForPaths:(NSArray *)paths;
48+
- (void)showCommitsFromTree:(id)sender;
49+
- (void)showInFinderAction:(id)sender;
50+
- (void)openFilesAction:(id)sender;
51+
4552
- (void) copyCommitInfo;
4653

4754
- (BOOL) hasNonlinearPath;

PBGitHistoryController.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ - (void) removeView
203203
[super removeView];
204204
}
205205

206+
#pragma mark Table Column Methods
206207
- (NSMenu *)tableColumnMenu
207208
{
208209
NSMenu *menu = [[NSMenu alloc] initWithTitle:@"Table columns menu"];
@@ -218,4 +219,76 @@ - (NSMenu *)tableColumnMenu
218219
return menu;
219220
}
220221

222+
#pragma mark Tree Context Menu Methods
223+
224+
- (void)showCommitsFromTree:(id)sender
225+
{
226+
// TODO: Enable this from webview as well!
227+
228+
NSMutableArray *filePaths = [NSMutableArray arrayWithObjects:@"HEAD", @"--", NULL];
229+
[filePaths addObjectsFromArray:[sender representedObject]];
230+
231+
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithParameters:filePaths];
232+
233+
repository.currentBranch = [repository addBranch:revSpec];
234+
}
235+
236+
- (void)showInFinderAction:(id)sender
237+
{
238+
NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"];
239+
NSString *path;
240+
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
241+
242+
for (NSString *filePath in [sender representedObject]) {
243+
path = [workingDirectory stringByAppendingPathComponent:filePath];
244+
[ws selectFile: path inFileViewerRootedAtPath:path];
245+
}
246+
247+
}
248+
249+
- (void)openFilesAction:(id)sender
250+
{
251+
NSString *workingDirectory = [[repository workingDirectory] stringByAppendingString:@"/"];
252+
NSString *path;
253+
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
254+
255+
for (NSString *filePath in [sender representedObject]) {
256+
path = [workingDirectory stringByAppendingPathComponent:filePath];
257+
[ws openFile:path];
258+
}
259+
}
260+
261+
262+
- (NSMenu *)contextMenuForTreeView
263+
{
264+
NSArray *filePaths = [[treeController selectedObjects] valueForKey:@"fullPath"];
265+
266+
NSMenu *menu = [[NSMenu alloc] init];
267+
for (NSMenuItem *item in [self menuItemsForPaths:filePaths])
268+
[menu addItem:item];
269+
return menu;
270+
}
271+
272+
- (NSArray *)menuItemsForPaths:(NSArray *)paths
273+
{
274+
BOOL multiple = [paths count] != 1;
275+
NSMenuItem *historyItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show history of files" : @"Show history of file"
276+
action:@selector(showCommitsFromTree:)
277+
keyEquivalent:@""];
278+
NSMenuItem *finderItem = [[NSMenuItem alloc] initWithTitle:@"Show in Finder"
279+
action:@selector(showInFinderAction:)
280+
keyEquivalent:@""];
281+
NSMenuItem *openFilesItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Open Files" : @"Open File"
282+
action:@selector(openFilesAction:)
283+
keyEquivalent:@""];
284+
285+
NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, openFilesItem, nil];
286+
for (NSMenuItem *item in menuItems) {
287+
[item setTarget:self];
288+
[item setRepresentedObject:paths];
289+
}
290+
291+
return menuItems;
292+
}
293+
221294
@end

PBGitHistoryView.xib

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03">
33
<data>
44
<int key="IBDocument.SystemTarget">1050</int>
5-
<string key="IBDocument.SystemVersion">9G55</string>
5+
<string key="IBDocument.SystemVersion">9J61</string>
66
<string key="IBDocument.InterfaceBuilderVersion">677</string>
7-
<string key="IBDocument.AppKitVersion">949.43</string>
7+
<string key="IBDocument.AppKitVersion">949.46</string>
88
<string key="IBDocument.HIToolboxVersion">353.00</string>
99
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
1111
<integer value="237"/>
12-
<integer value="27"/>
12+
<integer value="2"/>
1313
</object>
1414
<object class="NSArray" key="IBDocument.PluginDependencies">
1515
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -345,6 +345,7 @@
345345
<object class="NSMutableArray" key="set.sortedObjects">
346346
<bool key="EncodedWithXMLCoder">YES</bool>
347347
<string>Apple HTML pasteboard type</string>
348+
<string>Apple PDF pasteboard type</string>
348349
<string>Apple PICT pasteboard type</string>
349350
<string>Apple URL pasteboard type</string>
350351
<string>Apple Web Archive pasteboard type</string>
@@ -355,6 +356,7 @@
355356
<string>NeXT Rich Text Format v1.0 pasteboard type</string>
356357
<string>NeXT TIFF v4.0 pasteboard type</string>
357358
<string>WebURLsWithTitlesPboardType</string>
359+
<string>public.png</string>
358360
<string>public.url</string>
359361
<string>public.url-name</string>
360362
</object>
@@ -2978,7 +2980,7 @@
29782980
</object>
29792981
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29802982
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2981-
<string>{{321, 79}, {852, 432}}</string>
2983+
<string>{{358, 67}, {852, 432}}</string>
29822984
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29832985
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29842986
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3013,7 +3015,7 @@
30133015
</object>
30143016
</object>
30153017
<nil key="sourceID"/>
3016-
<int key="maxID">274</int>
3018+
<int key="maxID">286</int>
30173019
</object>
30183020
<object class="IBClassDescriber" key="IBDocument.Classes">
30193021
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3032,7 +3034,7 @@
30323034
<object class="NSMutableArray" key="dict.values">
30333035
<bool key="EncodedWithXMLCoder">YES</bool>
30343036
<string>PBGitHistoryController</string>
3035-
<string>id</string>
3037+
<string>PBWebHistoryController</string>
30363038
<string>WebView</string>
30373039
</object>
30383040
</object>
@@ -3053,6 +3055,8 @@
30533055
<string>setDetailedView:</string>
30543056
<string>setRawView:</string>
30553057
<string>setTreeView:</string>
3058+
<string>showCommitsFromTree:</string>
3059+
<string>showInFinderAction:</string>
30563060
<string>toggleQuickView:</string>
30573061
</object>
30583062
<object class="NSMutableArray" key="dict.values">
@@ -3063,6 +3067,8 @@
30633067
<string>id</string>
30643068
<string>id</string>
30653069
<string>id</string>
3070+
<string>id</string>
3071+
<string>id</string>
30663072
</object>
30673073
</object>
30683074
<object class="NSMutableDictionary" key="outlets">
@@ -3073,6 +3079,7 @@
30733079
<string>commitList</string>
30743080
<string>fileBrowser</string>
30753081
<string>searchField</string>
3082+
<string>treeContextMenu</string>
30763083
<string>treeController</string>
30773084
<string>webView</string>
30783085
</object>
@@ -3082,6 +3089,7 @@
30823089
<string>NSTableView</string>
30833090
<string>NSOutlineView</string>
30843091
<string>NSSearchField</string>
3092+
<string>NSMenu</string>
30853093
<string>NSTreeController</string>
30863094
<string>id</string>
30873095
</object>

PBQLOutlineView.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ - (NSArray *)outlineView:(NSOutlineView *)outlineView namesOfPromisedFilesDroppe
5858
return fileNames;
5959
}
6060

61+
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
62+
{
63+
if ([theEvent type] == NSRightMouseDown)
64+
{
65+
// get the current selections for the outline view.
66+
NSIndexSet *selectedRowIndexes = [self selectedRowIndexes];
67+
68+
// select the row that was clicked before showing the menu for the event
69+
NSPoint mousePoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
70+
int row = [self rowAtPoint:mousePoint];
71+
72+
// figure out if the row that was just clicked on is currently selected
73+
if ([selectedRowIndexes containsIndex:row] == NO)
74+
[self selectRow:row byExtendingSelection:NO];
75+
}
76+
77+
return [controller contextMenuForTreeView];
78+
}
79+
6180
/* Implemented to satisfy datasourcee protocol */
6281
- (BOOL) outlineView: (NSOutlineView *)ov
6382
isItemExpandable: (id)item { return NO; }

PBWebHistoryController.m

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,23 @@ - (NSArray *) webView:(WebView *)sender
7676
{
7777
DOMNode *node = [element valueForKey:@"WebElementDOMNode"];
7878

79-
// If clicked on the text, select the containing div
80-
if ([[node className] isEqualToString:@"DOMText"])
81-
node = [node parentNode];
82-
83-
// Every ref has a class name of 'refs' and some other class. We check on that to see if we pressed on a ref.
84-
if (![[node className] hasPrefix:@"refs "])
85-
return defaultMenuItems;
79+
while (node) {
80+
// Every ref has a class name of 'refs' and some other class. We check on that to see if we pressed on a ref.
81+
if ([[node className] hasPrefix:@"refs "]) {
82+
NSString *selectedRefString = [[[node childNodes] item:0] textContent];
83+
for (PBGitRef *ref in historyController.webCommit.refs)
84+
{
85+
if ([[ref shortName] isEqualToString:selectedRefString])
86+
return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit];
87+
}
88+
NSLog(@"Could not find selected ref!");
89+
return defaultMenuItems;
90+
}
91+
if ([node hasAttributes] && [[node attributes] getNamedItem:@"representedFile"])
92+
return [historyController menuItemsForPaths:[NSArray arrayWithObject:[[[node attributes] getNamedItem:@"representedFile"] value]]];
8693

87-
NSString *selectedRefString = [[[node childNodes] item:0] textContent];
88-
for (PBGitRef *ref in historyController.webCommit.refs)
89-
{
90-
if ([[ref shortName] isEqualToString:selectedRefString])
91-
return [contextMenuDelegate menuItemsForRef:ref commit:historyController.webCommit];
94+
node = [node parentNode];
9295
}
93-
NSLog(@"Could not find selected ref!");
9496

9597
return defaultMenuItems;
9698
}

html/views/history/history.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,26 +205,32 @@ var showDiff = function() {
205205
var link = document.createElement("a");
206206
link.setAttribute("href", "#" + id);
207207
p.appendChild(link);
208-
var buttonType = ""
208+
var buttonType = "";
209+
var finalFile = "";
209210
if (name1 == name2) {
210211
buttonType = "changed"
211-
link.appendChild(document.createTextNode(name1));
212+
finalFile = name1;
212213
if (mode_change)
213214
p.appendChild(document.createTextNode(" mode " + old_mode + " -> " + new_mode));
214215
}
215216
else if (name1 == "/dev/null") {
216217
buttonType = "created";
217-
link.appendChild(document.createTextNode(name2));
218+
finalFile = name2;
218219
}
219220
else if (name2 == "/dev/null") {
220221
buttonType = "deleted";
221-
link.appendChild(document.createTextNode(name1));
222+
finalFile = name1;
222223
}
223224
else {
224225
buttonType = "renamed";
225-
link.appendChild(document.createTextNode(name2));
226+
finalFile = name2;
226227
p.insertBefore(document.createTextNode(name1 + " -> "), link);
227228
}
229+
230+
link.appendChild(document.createTextNode(finalFile));
231+
button.setAttribute("representedFile", finalFile);
232+
link.setAttribute("representedFile", finalFile);
233+
228234
button.setAttribute("class", "button " + buttonType);
229235
button.appendChild(document.createTextNode(buttonType));
230236
$("files").appendChild(button);

0 commit comments

Comments
 (0)