Skip to content

Commit 1199c56

Browse files
committed
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.
1 parent c9609f2 commit 1199c56

File tree

4 files changed

+42
-83
lines changed

4 files changed

+42
-83
lines changed

PBGitHistoryController.h

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
- (IBAction) toggleQuickView: sender;
4242
- (IBAction) openSelectedFile: sender;
4343
- (void) updateQuicklookForce: (BOOL) force;
44+
45+
// Context menu methods
46+
- (NSMenu *)contextMenuForTreeView;
47+
- (NSArray *)menuItemsForPaths:(NSArray *)paths;
4448
- (void)showCommitsFromTree:(id)sender;
4549
- (void)showInFinderAction:(id)sender;
4650

PBGitHistoryController.m

+32-4
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ - (void)showCommitsFromTree:(id)sender
226226
// TODO: Enable this from webview as well!
227227

228228
NSMutableArray *filePaths = [NSMutableArray arrayWithObjects:@"HEAD", @"--", NULL];
229-
for (PBGitTree *tree in [treeController selectedObjects])
230-
[filePaths addObject:[tree fullPath]];
229+
[filePaths addObjectsFromArray:[sender representedObject]];
230+
231231
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithParameters:filePaths];
232232

233233
repository.currentBranch = [repository addBranch:revSpec];
@@ -239,12 +239,40 @@ - (void)showInFinderAction:(id)sender
239239
NSString *path;
240240
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
241241

242-
for (PBGitTree *tree in [treeController selectedObjects]) {
243-
path = [workingDirectory stringByAppendingPathComponent:[tree fullPath]];
242+
for (NSString *filePath in [sender representedObject]) {
243+
path = [workingDirectory stringByAppendingPathComponent:filePath];
244244
[ws selectFile: path inFileViewerRootedAtPath:path];
245245
}
246246

247247
}
248248

249+
- (NSMenu *)contextMenuForTreeView
250+
{
251+
NSArray *filePaths = [[treeController selectedObjects] valueForKey:@"fullPath"];
252+
253+
NSMenu *menu = [[NSMenu alloc] init];
254+
for (NSMenuItem *item in [self menuItemsForPaths:filePaths])
255+
[menu addItem:item];
256+
return menu;
257+
}
258+
259+
- (NSArray *)menuItemsForPaths:(NSArray *)paths
260+
{
261+
BOOL multiple = [paths count] != 1;
262+
NSMenuItem *finderItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show items in Finder" : @"Show item in Finder"
263+
action:@selector(showInFinderAction:)
264+
keyEquivalent:@""];
265+
NSMenuItem *historyItem = [[NSMenuItem alloc] initWithTitle:multiple? @"Show history of files" : @"Show history of file"
266+
action:@selector(showCommitsFromTree:)
267+
keyEquivalent:@""];
268+
269+
NSArray *menuItems = [NSArray arrayWithObjects:historyItem, finderItem, nil];
270+
for (NSMenuItem *item in menuItems) {
271+
[item setTarget:self];
272+
[item setRepresentedObject:paths];
273+
}
274+
275+
return menuItems;
276+
}
249277

250278
@end

PBGitHistoryView.xib

+5-78
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
<string key="IBDocument.HIToolboxVersion">353.00</string>
99
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
11-
<integer value="276"/>
1211
<integer value="237"/>
13-
<integer value="9"/>
12+
<integer value="2"/>
1413
</object>
1514
<object class="NSArray" key="IBDocument.PluginDependencies">
1615
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1518,28 +1517,6 @@
15181517
<bool key="EncodedWithXMLCoder">YES</bool>
15191518
</object>
15201519
</object>
1521-
<object class="NSMenu" id="500542810">
1522-
<string key="NSTitle"/>
1523-
<object class="NSMutableArray" key="NSMenuItems">
1524-
<bool key="EncodedWithXMLCoder">YES</bool>
1525-
<object class="NSMenuItem" id="661418857">
1526-
<reference key="NSMenu" ref="500542810"/>
1527-
<string key="NSTitle">Show history of file(s)</string>
1528-
<string key="NSKeyEquiv"/>
1529-
<int key="NSMnemonicLoc">2147483647</int>
1530-
<reference key="NSOnImage" ref="908677745"/>
1531-
<reference key="NSMixedImage" ref="746375230"/>
1532-
</object>
1533-
<object class="NSMenuItem" id="85225954">
1534-
<reference key="NSMenu" ref="500542810"/>
1535-
<string key="NSTitle">Show in Finder</string>
1536-
<string key="NSKeyEquiv"/>
1537-
<int key="NSMnemonicLoc">2147483647</int>
1538-
<reference key="NSOnImage" ref="908677745"/>
1539-
<reference key="NSMixedImage" ref="746375230"/>
1540-
</object>
1541-
</object>
1542-
</object>
15431520
</object>
15441521
<object class="IBObjectContainer" key="IBDocument.Objects">
15451522
<object class="NSMutableArray" key="connectionRecords">
@@ -2130,30 +2107,6 @@
21302107
</object>
21312108
<int key="connectionID">274</int>
21322109
</object>
2133-
<object class="IBConnectionRecord">
2134-
<object class="IBActionConnection" key="connection">
2135-
<string key="label">showCommitsFromTree:</string>
2136-
<reference key="source" ref="1001"/>
2137-
<reference key="destination" ref="661418857"/>
2138-
</object>
2139-
<int key="connectionID">281</int>
2140-
</object>
2141-
<object class="IBConnectionRecord">
2142-
<object class="IBOutletConnection" key="connection">
2143-
<string key="label">menu</string>
2144-
<reference key="source" ref="216928480"/>
2145-
<reference key="destination" ref="500542810"/>
2146-
</object>
2147-
<int key="connectionID">282</int>
2148-
</object>
2149-
<object class="IBConnectionRecord">
2150-
<object class="IBActionConnection" key="connection">
2151-
<string key="label">showInFinderAction:</string>
2152-
<reference key="source" ref="1001"/>
2153-
<reference key="destination" ref="85225954"/>
2154-
</object>
2155-
<int key="connectionID">285</int>
2156-
</object>
21572110
</object>
21582111
<object class="IBMutableOrderedSet" key="objectRecords">
21592112
<object class="NSArray" key="orderedObjects">
@@ -2784,26 +2737,6 @@
27842737
<reference key="object" ref="217429948"/>
27852738
<reference key="parent" ref="27300806"/>
27862739
</object>
2787-
<object class="IBObjectRecord">
2788-
<int key="objectID">276</int>
2789-
<reference key="object" ref="500542810"/>
2790-
<object class="NSMutableArray" key="children">
2791-
<bool key="EncodedWithXMLCoder">YES</bool>
2792-
<reference ref="661418857"/>
2793-
<reference ref="85225954"/>
2794-
</object>
2795-
<reference key="parent" ref="1002"/>
2796-
</object>
2797-
<object class="IBObjectRecord">
2798-
<int key="objectID">275</int>
2799-
<reference key="object" ref="661418857"/>
2800-
<reference key="parent" ref="500542810"/>
2801-
</object>
2802-
<object class="IBObjectRecord">
2803-
<int key="objectID">284</int>
2804-
<reference key="object" ref="85225954"/>
2805-
<reference key="parent" ref="500542810"/>
2806-
</object>
28072740
</object>
28082741
</object>
28092742
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -2883,12 +2816,8 @@
28832816
<string>27.ImportedFromIB2</string>
28842817
<string>272.IBPluginDependency</string>
28852818
<string>273.IBPluginDependency</string>
2886-
<string>275.IBPluginDependency</string>
2887-
<string>276.IBEditorWindowLastContentRect</string>
2888-
<string>276.IBPluginDependency</string>
28892819
<string>28.IBPluginDependency</string>
28902820
<string>28.IBShouldRemoveOnLegacySave</string>
2891-
<string>284.IBPluginDependency</string>
28922821
<string>29.IBPluginDependency</string>
28932822
<string>29.IBShouldRemoveOnLegacySave</string>
28942823
<string>3.IBPluginDependency</string>
@@ -3018,12 +2947,8 @@
30182947
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
30192948
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
30202949
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
3021-
<string>{{225, 683}, {202, 43}}</string>
3022-
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
3023-
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
30242950
<reference ref="9"/>
30252951
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
3026-
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
30272952
<reference ref="9"/>
30282953
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
30292954
<reference ref="9"/>
@@ -3055,7 +2980,7 @@
30552980
</object>
30562981
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
30572982
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
3058-
<string>{{76, 44}, {852, 432}}</string>
2983+
<string>{{358, 67}, {852, 432}}</string>
30592984
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
30602985
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
30612986
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3090,7 +3015,7 @@
30903015
</object>
30913016
</object>
30923017
<nil key="sourceID"/>
3093-
<int key="maxID">285</int>
3018+
<int key="maxID">286</int>
30943019
</object>
30953020
<object class="IBClassDescriber" key="IBDocument.Classes">
30963021
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3154,6 +3079,7 @@
31543079
<string>commitList</string>
31553080
<string>fileBrowser</string>
31563081
<string>searchField</string>
3082+
<string>treeContextMenu</string>
31573083
<string>treeController</string>
31583084
<string>webView</string>
31593085
</object>
@@ -3163,6 +3089,7 @@
31633089
<string>NSTableView</string>
31643090
<string>NSOutlineView</string>
31653091
<string>NSSearchField</string>
3092+
<string>NSMenu</string>
31663093
<string>NSTreeController</string>
31673094
<string>id</string>
31683095
</object>

PBQLOutlineView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ - (NSMenu *)menuForEvent:(NSEvent *)theEvent
7474
[self selectRow:row byExtendingSelection:NO];
7575
}
7676

77-
return [super menuForEvent:theEvent];
77+
return [controller contextMenuForTreeView];
7878
}
7979

8080
/* Implemented to satisfy datasourcee protocol */

0 commit comments

Comments
 (0)