Skip navigation.
 
mlRe: Adding a new type of NSButton
FROM : P Teeson
DATE : Wed Jun 25 23:44:44 2008

On 25-Jun-08, at 3:22 PM, I. Savant wrote:

>> I need a new type of NSButton/NSButtonCell that I am calling an
>> NSLatchButton.
>> Once it is pushed it stays pushed - pushing it again does not 
>> revert it back
>> to unpushed state.
>> (Of course there would be a method to set it to it's unlatched 
>> state but
>> pushing the button would not
>> invoke that action)
>>
>> However I'm not sure how to approach this. Should I use categories,
>> extensions, or subclass or what?

>
>  Why do you need a new button type? No matter how you want it to
> look, the behavior should be dictated by the controller layer. When
> its action is fired, simply force its state to be NSOnState.


Thanks for that idea - I hadn't thought of it. It's not as clean as I 
would like but
it would work.

>>
>> If I were dealing with the source code I would add to the button 
>> types enums
>> and add a method or case to deal with that type.

>
>  Yes, and I would snarf the freezlehopper until it is within one
> tenth of a hoptzit of the specified framulator.  But that's also
> unnecessary. ;-)

I guess your smile indicates humour.

> Yes, of course you can subclass NSButton/Cell and add
> a new type, then override all the drawing routines, etc. to handle
> that case, but you *still* shouldn't force the button to take on the
> responsibility of application-specific logic (see "MVC design
> pattern").

I am familiar with the pattern having used Smalltalk.
If I did add a subclass there would be no need to ovveride everything.
Only specific set state methods.

> It's your application's idea that a button can't be
> "unpushed" once it's pushed; it's your application's responsibility to
> enforce such a state once set.

True which is why I asked for suggestions.

>> But what suggestions do you have?

>  Read the NSButton documentation *and* the target/action mechanism
> documentation (both easily searchable in Apple's reference library).
> You're making a mountain out of a mole hill.

Perhaps... But for future posts of mine please be so kind as to assume
that I've always read the available Apple documentation.
I lived by RTFM since 360 Assembler days!
In this case the references for NSButton/NSButtonCell plus Button 
Programming topics.

I appreciate your comments.
respect...

Peter

Related mailsAuthorDate
mlAdding a new type of NSButton P Teeson Jun 25, 21:12
mlRe: Adding a new type of NSButton Marco Masser Jun 25, 21:21
mlRe: Adding a new type of NSButton I. Savant Jun 25, 21:22
mlRe: Adding a new type of NSButton I. Savant Jun 25, 21:24
mlRe: Adding a new type of NSButton Kevin Elliott Jun 25, 22:13
mlRe: Adding a new type of NSButton I. Savant Jun 25, 22:26
mlRe: Adding a new type of NSButton Andy Lee Jun 25, 22:32
mlRe: Adding a new type of NSButton Andy Lee Jun 25, 23:10
mlRe: Adding a new type of NSButton P Teeson Jun 25, 23:44
mlRe: Adding a new type of NSButton P Teeson Jun 25, 23:54
mlRe: Adding a new type of NSButton P Teeson Jun 26, 00:01
mlRe: Adding a new type of NSButton Hamish Allan Jun 26, 00:37
mlRe: Adding a new type of NSButton P Teeson Jun 26, 01:16
mlRe: Adding a new type of NSButton I. Savant Jun 26, 15:29
mlRe: Adding a new type of NSButton I. Savant Jun 26, 15:33
mlRe: Adding a new type of NSButton Andy Lee Jun 26, 16:51
mlRe: Adding a new type of NSButton I. Savant Jun 26, 17:02
mlRe: Adding a new type of NSButton Kevin Elliott Jun 26, 18:13
mlRe: Adding a new type of NSButton I. Savant Jun 26, 18:33