Permalink
Browse files

* Implement target/action

  • Loading branch information...
1 parent 3b04cce commit ce71fbe9acc1350c937885a6838859965f83a609 @mattball committed Apr 29, 2009
Showing with 31 additions and 1 deletion.
  1. +20 −0 MBCoverFlowView.h
  2. +11 −1 MBCoverFlowView.m
View
@@ -66,6 +66,10 @@
// Bindings
NSMutableDictionary *_bindingInfo;
+
+ // Actions
+ id _target;
+ SEL _action;
}
/**
@@ -137,6 +141,22 @@
@property (nonatomic, assign) id selectedObject;
/**
+ * @name The Target/Action Mechanism
+ */
+
+/**
+ * @brief The target object that receives action messages from the view.
+ */
+@property (nonatomic, assign) id target;
+
+/**
+ * @brief The selector associated with the view.
+ * @details The action will be called when the user double-clicks an item
+ * or presses the Return key.
+ */
+@property (nonatomic, assign) SEL action;
+
+/**
* @name Layout Support
*/
View
@@ -64,6 +64,7 @@ of this software and associated documentation files (the "Software"), to deal
// Key Codes
#define MBLeftArrowKeyCode 123
#define MBRightArrowKeyCode 124
+#define MBReturnKeyCode 36
@interface MBCoverFlowView ()
- (float)_positionOfSelectedItem;
@@ -82,7 +83,7 @@ @implementation MBCoverFlowView
@synthesize accessoryController=_accessoryController, selectedIndex=_selectedIndex,
itemSize=_itemSize, content=_content, showsScrollbar=_showsScrollbar,
autoresizesItems=_autoresizesItems, imageKeyPath=_imageKeyPath,
- placeholderIcon=_placeholderIcon;
+ placeholderIcon=_placeholderIcon, target=_target, action=_action;
@dynamic selectedObject;
@@ -300,6 +301,11 @@ - (void)keyDown:(NSEvent *)theEvent
case MBRightArrowKeyCode:
[self _setSelectionIndex:(self.selectedIndex + 1)];
break;
+ case MBReturnKeyCode:
+ if (self.target && self.action) {
+ [self.target performSelector:self.action withObject:self];
+ }
+ break;
default:
[super keyDown:theEvent];
break;
@@ -308,6 +314,10 @@ - (void)keyDown:(NSEvent *)theEvent
- (void)mouseDown:(NSEvent *)theEvent
{
+ if ([theEvent clickCount] == 2 && self.target && self.action) {
+ [self.target performSelector:self.action withObject:self];
+ }
+
NSPoint mouseLocation = [self convertPoint:[theEvent locationInWindow] fromView:nil];
NSInteger clickedIndex = [self indexOfItemAtPoint:mouseLocation];
if (clickedIndex != NSNotFound) {

0 comments on commit ce71fbe

Please sign in to comment.