Created
November 17, 2010 07:21
-
-
Save luciuskwok/703100 to your computer and use it in GitHub Desktop.
DeletableTableView, an NSTableView subclass which supports delete.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Cocoa/Cocoa.h> | |
| @interface DeletableTableView : NSTableView { | |
| } | |
| @end | |
| @protocol DeletableTableViewDelegate | |
| - (void)tableViewDelete:(DeletableTableView *)aView; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "DeletableTableView.h" | |
| @implementation DeletableTableView | |
| - (IBAction)delete:(id)sender { | |
| if ([self numberOfSelectedRows] > 0) | |
| [[self delegate] tableViewDelete:self]; | |
| } | |
| - (void)deleteBackward:(id)sender { | |
| [self delete:nil]; | |
| } | |
| - (void)deleteForward:(id)sender { | |
| [self delete:nil]; | |
| } | |
| - (void)keyDown:(NSEvent *)event { | |
| NSString* chars = [event charactersIgnoringModifiers]; | |
| if ([chars length] == 1) { | |
| unichar c = [chars characterAtIndex:0]; | |
| if (c == NSDeleteCharacter || c == NSDeleteFunctionKey) { | |
| [self delete:nil]; | |
| } | |
| } | |
| } | |
| - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem { | |
| BOOL result = NO; | |
| if ([anItem action] == @selector(delete:)) { | |
| result = ([self numberOfSelectedRows] > 0); | |
| } else { | |
| result = [super validateUserInterfaceItem:anItem]; | |
| } | |
| return result; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment