Re: NSTableView rows and delete key
Re: NSTableView rows and delete key
- Subject: Re: NSTableView rows and delete key
- From: Daryn <email@hidden>
- Date: Sat, 27 Jul 2002 22:55:55 -0500
On Thursday, July 25, 2002, at 04:53 PM, Matt Neuburg wrote:
On Thu, 25 Jul 2002 17:05:04 +0200, =?ISO-8859-1?Q?Rapha=EBl_Delcroix?=
<email@hidden> said:
I can't find anything in the NSTableView documentation about this,
Then you didn't look far enough up the class hierarchy. Always remember
to
do that.
The solution is not immediately obvious to a newbie. The main problem
is the seemingly poor implementation of the table and outline view. The
key events are not interpreted, and the views don't implement the
intended responder methods. My solution was to interpret the keys, and
reimplement arrow up/down in the "proper" way via the responder
methods. This made customization _much_ easier.
Here's part of what I did for an outline view (it's not fully debugged,
your mileage may vary). It should be straightforward to adapt:
- (void)keyDown:(NSEvent *)event {
[self interpretKeyEvents:[NSArray arrayWithObject:event]];
}
- (void)moveDown:(id)sender {
[self scrollLineDown:sender];
}
- (void)moveUp:(id)sender {
[self scrollLineUp:sender];
}
- (void)scrollToRow:(int)row selectRow:(BOOL)select {
if (select) [self selectRow:row byExtendingSelection:NO];
[self scrollRowToVisible:row];
}
- (void)scrollLineUp:(id)sender {
int row = [self selectedRow];
if (row < 0) row = [self numberOfRows];
if (--row >= 0) [self scrollToRow:row selectRow:YES];
}
- (void)scrollLineDown:(id)sender {
int row = [self selectedRow];
if (++row < [self numberOfRows]) [self scrollToRow:row selectRow:YES];
}
- (void)scrollToBeginningOfDocument:(id)sender {
int rows = [self numberOfRows];
if (rows) [self scrollToRow:rows selectRow:NO];
}
- (void)scrollToEndOfDocument:(id)sender {
int rows = [self numberOfRows];
if (rows) [self scrollToRow:rows-1 selectRow:NO];
}
- (void)cancel:(id)sender {
[self abortEditing];
[[self window] makeFirstResponder:self];
}
- (void)moveRight:(id)sender {
id row;
NSEnumerator *enumerator = [self selectedRowEnumerator];
while (row = [enumerator nextObject]) {
[self expandItem:[self itemAtRow:[row intValue]]];
}
}
- (void)moveLeft:(id)sender {
id row;
NSEnumerator *enumerator = [self selectedRowEnumerator];
while (row = [enumerator nextObject]) {
[self collapseItem:[self itemAtRow:[row intValue]]];
}
}
- (void)insertText:(NSString *)insertString {
int i;
NSTimeInterval timestamp = [[[self window] currentEvent] timestamp];
if (!searchPrefix) searchPrefix = [NSMutableString new];
if (timestamp - lastInsertTimestamp > .5) {
[searchPrefix setString:insertString];
} else {
[searchPrefix appendString:insertString];
}
lastInsertTimestamp = timestamp;
for (i=0; i < [self numberOfRows]; i++) {
id string = [[self dataSource] outlineView:self
searchKeyForItem:[self itemAtRow:i]];
if ([string hasPrefix:searchPrefix]) {
[self scrollToRow:i selectRow:YES];
return;
}
}
NSBeep();
}
- (void)deleteForward:(id)sender {
NSMutableArray *items = [NSMutableArray array];
NSEnumerator *enumerator = [self selectedRowEnumerator];
id row;
while (row = [enumerator nextObject]) {
[items addObject:[self itemAtRow:[row intValue]]];
}
[[self dataSource] outlineView:self removeItems:items];
}
Daryn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.