Skip to content

Commit

Permalink
Merge pull request #168 from kettch/contextual-menu
Browse files Browse the repository at this point in the history
Added basic contextual menu support
  • Loading branch information
jwilling committed May 31, 2016
2 parents 9245c26 + 5f493a6 commit b835634
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions JNWCollectionView/JNWCollectionViewFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewScrollPosition) {
/// back into the reuse queue.
- (void)collectionView:(JNWCollectionView *)collectionView didEndDisplayingCell:(JNWCollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath;

// Asks the delegate if a contextual menu should be used for the given event.
- (NSMenu *)collectionView:(JNWCollectionView *)collectionView menuForEvent:(NSEvent *)event;

@end

#pragma mark Reloading and customizing
Expand Down
16 changes: 13 additions & 3 deletions JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ @interface JNWCollectionView() {
unsigned int delegateDidDoubleClick:1;
unsigned int delegateDidRightClick:1;
unsigned int delegateDidEndDisplayingCell:1;
unsigned int delegateMenuForEvent:1;

unsigned int wantsLayout;
} _collectionViewFlags;
Expand Down Expand Up @@ -143,9 +144,10 @@ - (void)setDelegate:(id<JNWCollectionViewDelegate>)delegate {
_collectionViewFlags.delegateDidDeselect = [delegate respondsToSelector:@selector(collectionView:didDeselectItemAtIndexPath:)];
_collectionViewFlags.delegateDidDoubleClick = [delegate respondsToSelector:@selector(collectionView:didDoubleClickItemAtIndexPath:)];
_collectionViewFlags.delegateDidRightClick = [delegate respondsToSelector:@selector(collectionView:didRightClickItemAtIndexPath:)];
_collectionViewFlags.delegateDidEndDisplayingCell = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)];
_collectionViewFlags.delegateShouldScroll = [delegate respondsToSelector:@selector(collectionView:shouldScrollToItemAtIndexPath:)];
_collectionViewFlags.delegateDidScroll = [delegate respondsToSelector:@selector(collectionView:didScrollToItemAtIndexPath:)];
_collectionViewFlags.delegateDidEndDisplayingCell = [delegate respondsToSelector:@selector(collectionView:didEndDisplayingCell:forItemAtIndexPath:)];
_collectionViewFlags.delegateShouldScroll = [delegate respondsToSelector:@selector(collectionView:shouldScrollToItemAtIndexPath:)];
_collectionViewFlags.delegateDidScroll = [delegate respondsToSelector:@selector(collectionView:didScrollToItemAtIndexPath:)];
_collectionViewFlags.delegateMenuForEvent = [delegate respondsToSelector:@selector(collectionView:menuForEvent:)];
}

- (void)setDataSource:(id<JNWCollectionViewDataSource>)dataSource {
Expand Down Expand Up @@ -1103,6 +1105,14 @@ - (void)selectAllItems {
[self selectAll:nil];
}

- (NSMenu *)menuForEvent:(NSEvent *)event {
if (_collectionViewFlags.delegateMenuForEvent) {
NSMenu *menu = [self.delegate collectionView:self menuForEvent:event];
return menu;
}
return nil;
}

#pragma mark NSObject

- (NSString *)description {
Expand Down

0 comments on commit b835634

Please sign in to comment.