Re: FW: Enabling and Disabling menus
Re: FW: Enabling and Disabling menus
- Subject: Re: FW: Enabling and Disabling menus
- From: Ondra Cada <email@hidden>
- Date: Wed, 22 Aug 2001 22:28:35 +0200
Searle,
>
>>>>> Stuppel, Searle @ San Diego Central (SS) wrote at Wed, 22 Aug 2001
12:07:15 -0700:
SS> this is not the way to do it... let me share with you the code that
SS> actually WORKS
Triple Wow. Work it might, but I would not show it to public ;)))
SS> IBOutlet id menuClear;
SS> IBOutlet id menuGenerate;
SS> IBOutlet id menuSaveHTML;
SS> IBOutlet id menuSaveText;
We both know it, but for newbies perhaps it should be emphasized that those
have to be bound to proper menu items manually in IB.
SS> -(void)awakeFromNib
SS> {
SS> actGenerate = [menuGenerate action];
SS> actClear = [menuClear action];
SS> actSaveText = [menuSaveText action];
SS> actSaveHTML = [menuSaveHTML action];
SS> }
Not needed at all.
SS> - (void)setMenu:(id)sender mG:(BOOL)gen mC:(BOOL)cle mST:(BOOL)mst
SS> mSH:(BOOL)msh
What the 'sender' argument's here for? This is not an action. And the nice
intuitive method name... This should be something like
-(void)setEnabledItemsGenerate:(BOOL)gem clear:(BOOL)cle saveText:(BOOL)mst
saveHTML:(BOOL)msh
SS> {
SS> if (gen) {
SS> [menuGenerate setAction:actGenerate];
SS> }
SS> else {
SS> [menuGenerate setAction:0];
SS> }
[menuGenerate setEnabled:gen];
Now, you perhaps tried that and it did not work? If so, you had the
automatic validation (validateMenuItem:) set for the menu. Use *either*
automatic validation *or* manual one, not both at once.
Well, clearing/setting menu action would work even if the automatic
validation is set, you are right in that, but it is an indecent heap of quite
unnecessary work, and it is an ugly hack which would mightily confuse
anybody who happens to read/maintain/upgrade the code (like you the next year
;)
SS> if (cle) {
SS> [menuClear setAction:actClear];
SS> }
SS> else {
SS> [menuClear setAction:0];
SS> }
Incidentally, I seldom comment a programming style, but... have you ever
heard of the conditional expression? If you *do* want to use such a code, I
guess the following is *SOMEWHAT* more intelligible, not speaking of the five
lines saved:
[menuClear setAction:cle?actClear:0];
SS> let me know if this helps
Sorry, but I guess it would not, rather...
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc