• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Changing default button
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing default button


  • Subject: Re: Changing default button
  • From: Enrico Pancaldi <email@hidden>
  • Date: Tue, 19 Feb 2002 03:06:44 +0100

Changing equivalent key does not change default button.
You can handle default buttons with some window methods (see NSWindow).

Try this:

- (IBAction)makeButtonActive:(id)sender
{
[window setDefaultButtonCell: [(sender == rightButton ? leftButton : rightButton) cell]];
}

Setting a default button in IB seems to override the method.

Enrico


On Monday, February 18, 2002, at 04:09 , Mario Diana wrote:

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.
_______________________________________________
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.

References: 
 >Changing default button (From: Mario Diana <email@hidden>)

  • Prev by Date: Re: Idle Time in a loop
  • Next by Date: Re: Idle Time in a loop
  • Previous by thread: Changing default button
  • Next by thread: Toolbar icons
  • Index(es):
    • Date
    • Thread