Hi,I have a table view in my application. One of the cell of the table view is
editable. When my application window appears on screen the first row is by
default added in table view and the cell is in editable mode. On Enter or Esc
key press the user input from the cell is accepted and the data of whole row is
saved to some other data structure. I capture the key depressions in following
method (BOOL)control:(NSControl *)control textView:(NSTextView *)textView
doCommandBySelector:(SEL)commandWhat i am trying to do now is when user try to
click on some other row while the current row is in edit mode I want to ask him
that the "current record is not saved yet . do you want to save it?". If he
says yes then i want to save it. For that I need to simulate the Esc key press
so that my routine on Esc key press gets called.And if user says NO then i just
want to discard the current row.I tried to simulate Esc key press when table
view selection is changing in following code but it do
esn't simulates the Esc or any other key press." (BOOL)control:(NSControl
*)control textView:(NSTextView *)textView
doCommandBySelector:(SEL)command"never gets called.
(void)tableViewSelectionIsChanging:(NSNotification *)aNotification { int item1,
item2; int rc;//Check items in wlarray is equal to items in worklistdata
arrayitem1 = [wlarray count];for(item2 = 0; item2 < MAXSAMPLES; item2++) {
if(worklistdata[item2].sampleid[0] == '\0') break; }if(item1 > item2) { rc =
NSRunAlertPanel(@"Current worklist item is not saved yet. Do you want to save
it?",@"",@"Yes",@"No", nil); if(rc == NSAlertDefaultReturn) { CGEventSourceRef
source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef saveCommandDown = CGEventCreateKeyboardEvent(source, (CGKeyCode)53,
YES);//53 is keycode for Esc CGEventSetFlags(saveCommandDown,
kCGEventFlagMaskCommand); CGEventRef saveCommandUp =
CGEventCreateKeyboardEvent(source, (CGKeyCode)53,
NO);CGEventPost(kCGAnnotatedSessionEventTap,
saveCommandDown); CGEventPost(kCGAnnotatedSessionEventTap,
saveCommandUp);CFRelease(saveCommandUp); CFRelease(saveCommandDown);
CFRelease(source); } } }Please help.Thanks & RegardsAbhijeetDear cocoadev ! Get
Yourself a cool, short @in.com Email ID now!
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]