Re: setKeyEquivalent trouble
Re: setKeyEquivalent trouble
- Subject: Re: setKeyEquivalent trouble
- From: Paolo Bertani <email@hidden>
- Date: Mon, 15 May 2006 15:53:58 +0200
On May 14, 2006, at 12:58 PM, Paolo Bertani wrote:
Hi,
in an NSPanel I have 2 standard buttons, one of them is the
"default" button with "return" as key equivalent.
If some user action take place I need the other button to be the
default one.
So I call
[buttonA setKeyEquivalent:@""]; // this is the old button that
was default
[buttonB setKeyEquivalent:@"\r"]; // this is the button becoming
the default one
buttonA becomes not-default but buttonB doesn't become default.
I can force the whole thing to work if I add
[myPanel close];
[myPanelController showWindow:self];
but this is a hack of course.
What I'm missing?
Thanks in advance,
Paolo.
Instead of trying to change this in your button, use some of the
NSWindow methods for default button behavior.
In particular, take a look at setDefaultButtonCell,
enableKeyEquivalentForDefaultButtonCell, and
disableKeyEquivalentForDefaultButtonCell.
- Andrew Bowman
Andrew, I've done what you suggested. Things still doesn't work
properly but I've isolated the cause.
I'll explain quickly what happen in my code:
//default button A is pressed by user, IBAction is invoked. A sheet
for selecting a file is presented to the user
-(IBAction)selectFileA:(id)sender
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
SEL theSelector = @selector
(fileASelectionDidEnd:returnCode:contextInfo:);
[openPanel beginSheetForDirectory:@"~/Desktop"
file:nil
types:nil
modalForWindow:[sender window]
modalDelegate:self
didEndSelector:theSelector
contextInfo:nil];
}
// user made the choice, the selector is invoked. This method saves
the filename choosen and changes the default button
-(void) fileASelectionDidEnd:(NSOpenPanel *)sheet returnCode:(int)
returnCode contextInfo:(void *)context
{
if( returnCode == NSOKButton )
{
// File A selection is saved here (....some code....)
// then button B becomes the default button
[myWindow disableKeyEquivalentForDefaultButtonCell];
[myWindow setDefaultButtonCell:buttonB];
[myWindow enableKeyEquivalentForDefaultButtonCell];
}
}
// ----------------------------
It seems that the default button doesn't change because the sheet is
still closing.
If the code for changing the button is invoked somewhere else in the
program without as sheet-closing in progress everything works fine.
Thank you,
Paolo.
_______________________________________________
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