Changing default button
Changing default button
- Subject: Changing default button
- From: Mario Diana <email@hidden>
- Date: Mon, 18 Feb 2002 10:09:01 -0500
Hello,
I'd like to change the default button while my application is running,
but the whole thing seems rather buggy. I made a little toy application
to test this. (The code is short, so I'm including it for the sake of
illustration -- after my description in English.)
The application is one little window with two buttons and a text field.
The buttons alternate being the default button, and the text field
announces which button is the default. When the application launches,
awakeFromNib sets the button on the right as the default.
Hitting ENTER on the keyboard calls one of two methods:
activateRightButton or activateLeftButton. These methods change the text
in the text field and then call makeButtonActive, which switches the
buttons, removing default status from the current button and making the
other the default.
PROBLEM: The first button to be made the default is the only button that
will ever pulse (or throb). Both buttons work normally, otherwise. The
default button will be highlighted and hitting ENTER will activate it.
As I understand it, I remove default by setting the key equivalent to an
empty string. That's correct, isn't it?
What gives? Is this a bug, or is only one button ever supposed to be the
default from beginning to end? I'd appreciate any insight.
Thanks,
Mario
=========================================
@implementation Controller
- (IBAction)activateLeftButton:(id)sender
{
[textField setStringValue:@"Left button active"];
[self makeButtonActive:sender];
}
- (IBAction)activateRightButton:(id)sender
{
[textField setStringValue:@"Right button active"];
[self makeButtonActive:sender];
}
- (IBAction)makeButtonActive:(id)sender
{
NSButton *activeButton;
NSButton *otherButton;
// Buttons switch places
otherButton = (sender == rightButton ? rightButton : leftButton);
activeButton = (sender == rightButton ? leftButton : rightButton);
[otherButton setKeyEquivalent:@""];
[activeButton setKeyEquivalent:@"\r"];
}
- (void)awakeFromNib
{
[self activateRightButton:leftButton]; // "dummy" parameter
}
@end
=========================================
_______________________________________________
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.