Permalink
Browse files

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.
  • Loading branch information...
pieter committed Jun 16, 2009
1 parent c9609f2 commit 1199c56e932a91bd4bd4154f47635787ef3bb893
Showing with 42 additions and 83 deletions.
  1. +4 −0 PBGitHistoryController.h
  2. +32 −4 PBGitHistoryController.m
  3. +5 −78 PBGitHistoryView.xib
  4. +1 −1 PBQLOutlineView.m
View
@@ -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;
View
@@ -226,8 +226,8 @@ - (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]];
+ [filePaths addObjectsFromArray:[sender representedObject]];
+
PBGitRevSpecifier *revSpec = [[PBGitRevSpecifier alloc] initWithParameters:filePaths];
repository.currentBranch = [repository addBranch:revSpec];
@@ -239,12 +239,40 @@ - (void)showInFinderAction:(id)sender
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
View
@@ -8,9 +8,8 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="276"/>
<integer value="237"/>
- <integer value="9"/>
+ <integer value="2"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1518,28 +1517,6 @@
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
- <object class="NSMenu" id="500542810">
- <string key="NSTitle"/>
- <object class="NSMutableArray" key="NSMenuItems">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSMenuItem" id="661418857">
- <reference key="NSMenu" ref="500542810"/>
- <string key="NSTitle">Show history of file(s)</string>
- <string key="NSKeyEquiv"/>
- <int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSOnImage" ref="908677745"/>
- <reference key="NSMixedImage" ref="746375230"/>
- </object>
- <object class="NSMenuItem" id="85225954">
- <reference key="NSMenu" ref="500542810"/>
- <string key="NSTitle">Show in Finder</string>
- <string key="NSKeyEquiv"/>
- <int key="NSMnemonicLoc">2147483647</int>
- <reference key="NSOnImage" ref="908677745"/>
- <reference key="NSMixedImage" ref="746375230"/>
- </object>
- </object>
- </object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
@@ -2130,30 +2107,6 @@
</object>
<int key="connectionID">274</int>
</object>
- <object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">showCommitsFromTree:</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="661418857"/>
- </object>
- <int key="connectionID">281</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBOutletConnection" key="connection">
- <string key="label">menu</string>
- <reference key="source" ref="216928480"/>
- <reference key="destination" ref="500542810"/>
- </object>
- <int key="connectionID">282</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBActionConnection" key="connection">
- <string key="label">showInFinderAction:</string>
- <reference key="source" ref="1001"/>
- <reference key="destination" ref="85225954"/>
- </object>
- <int key="connectionID">285</int>
- </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -2784,26 +2737,6 @@
<reference key="object" ref="217429948"/>
<reference key="parent" ref="27300806"/>
</object>
- <object class="IBObjectRecord">
- <int key="objectID">276</int>
- <reference key="object" ref="500542810"/>
- <object class="NSMutableArray" key="children">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="661418857"/>
- <reference ref="85225954"/>
- </object>
- <reference key="parent" ref="1002"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">275</int>
- <reference key="object" ref="661418857"/>
- <reference key="parent" ref="500542810"/>
- </object>
- <object class="IBObjectRecord">
- <int key="objectID">284</int>
- <reference key="object" ref="85225954"/>
- <reference key="parent" ref="500542810"/>
- </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -2883,12 +2816,8 @@
<string>27.ImportedFromIB2</string>
<string>272.IBPluginDependency</string>
<string>273.IBPluginDependency</string>
- <string>275.IBPluginDependency</string>
- <string>276.IBEditorWindowLastContentRect</string>
- <string>276.IBPluginDependency</string>
<string>28.IBPluginDependency</string>
<string>28.IBShouldRemoveOnLegacySave</string>
- <string>284.IBPluginDependency</string>
<string>29.IBPluginDependency</string>
<string>29.IBShouldRemoveOnLegacySave</string>
<string>3.IBPluginDependency</string>
@@ -3018,12 +2947,8 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{225, 683}, {202, 43}}</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
@@ -3055,7 +2980,7 @@
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{76, 44}, {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>
@@ -3090,7 +3015,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">285</int>
+ <int key="maxID">286</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3154,6 +3079,7 @@
<string>commitList</string>
<string>fileBrowser</string>
<string>searchField</string>
+ <string>treeContextMenu</string>
<string>treeController</string>
<string>webView</string>
</object>
@@ -3163,6 +3089,7 @@
<string>NSTableView</string>
<string>NSOutlineView</string>
<string>NSSearchField</string>
+ <string>NSMenu</string>
<string>NSTreeController</string>
<string>id</string>
</object>
View
@@ -74,7 +74,7 @@ - (NSMenu *)menuForEvent:(NSEvent *)theEvent
[self selectRow:row byExtendingSelection:NO];
}
- return [super menuForEvent:theEvent];
+ return [controller contextMenuForTreeView];
}
/* Implemented to satisfy datasourcee protocol */

0 comments on commit 1199c56

Please sign in to comment.