Re: iTunes-like single-click table cell editing
Re: iTunes-like single-click table cell editing
- Subject: Re: iTunes-like single-click table cell editing
- From: Benjámin Salánki <email@hidden>
- Date: Wed, 19 Jan 2005 01:13:44 +0100
Hi,
thx for the code.
it works great, but my problem is that I want it to only start the edit if the row was already selected, so I added in some code, that works well.
i also have my table set up to run a selector on a doubleclick.
now the problem is that my table starts editing right after the first click of the double click. i tried looking for [theEvent clickCount], but it turns out mouseDown is called after every click, so when I NSLog it I get 1 (editing code starts) and 2, which starts the doubleAction for the table.
do you know how to fix this?
thx
ben
PS: here's my code
- (void)mouseDown:(NSEvent *)theEvent
{
NSLog(@"%d", [theEvent clickCount]);
if([theEvent clickCount]>1)
{
[super mouseDown:theEvent];
}
else
{
NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
int columnIndex = [self columnAtPoint:mouseLoc];
int rowIndex = [self rowAtPoint:mouseLoc];
if ((rowIndex >= 0) && ([[[[self tableColumns] objectAtIndex:columnIndex] identifier] isEqualTo:[NSString stringWithString:@"theName"]]) && [self isRowSelected:rowIndex])
{
NSLog(@"wtf? - should edit");
// [self selectRow:rowIndex byExtendingSelection:NO];
[self editColumn:columnIndex row:rowIndex withEvent:theEvent select:YES];
}
else
{
[super mouseDown:theEvent];
}
}
}
stupidFish23
http://www.stupidfish23.com
On Jan 19, 2005, at 0:12, Camillo Lugaresi wrote:
On 18/gen/05, at 23:39, Benjámin Salánki wrote:
Hi all,
I was searching through the archives for the last hour but couldn't find anything, so let me ask you:
how can I implement single-click (or delayed double-click) editing like the one in iTunes?
does anyone have some code example?
I assume you're talking about single-click editing of text cells in an NSTableView. I wanted to do that a while ago, and the method I came up with was to make a custom subclass of NSTableView which overrides mouseDown:
- (void)mouseDown:(NSEvent *)event
{
NSPoint location = [self convertPoint:[event locationInWindow] fromView:nil];
int columnIndex = [self columnAtPoint:location];
int rowIndex = [self rowAtPoint:location];
if ((rowIndex >= 0) && ([[[[self tableColumns] objectAtIndex:columnIndex] dataCellForRow:rowIndex] isKindOfClass:[NSTextFieldCell class]])) {
[self selectRow:rowIndex byExtendingSelection:NO];
[self editColumn:columnIndex row:rowIndex withEvent:event select:YES];
} else [super mouseDown:event];
}
It's not exactly the same interface as iTunes, but it should be easy to adapt this code to your needs.
Note, however, that I wrote this code for my first or second Cocoa program ever and never touched it again; it could well be that there are better ways to do the same thing.
HTH
Camillo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden