[TxMt] tm_dialog: How to handle several buttons?

Allan Odgaard throw-away-1 at macromates.com
Mon Oct 30 21:43:54 UTC 2006


On 30. Oct 2006, at 22:34, Hans-Joerg Bibiko wrote:

> is there any way to distinguish what button was pressed if I have  
> more of them?
>
> E.g. you want to ask the user; two buttons 'Yes' and 'No'. How can  
> you return that?

If you set the tag (in the attributes part of the Show Inspector  
palette) to a number, that number is returned both as tm_dialog’s  
exit code, and as a returnCode key/value pair in the property list  
which is returned.

In addition the label of the clicked button is returned in this  
property list.

This all assumes you have hooked up the button to the  
performButtonClick: action method in File’s Owner. By default File’s  
Owner will however not have such action method, so one needs to  
double click it, select Subclass from the Classes menu, then name the  
subclass whatever, and in the Show Inspector palette one can add the  
method.

After that, one needs to click the File’s Owner again (in  
theinstances tab) and select the new Subclass we created in the  
Custom Class page of the inspector palette.

It’s easier to show then describe…

Another approach is to make a whatever.h file and have it contain  
these 3 lines:

     @interface NSObject (Category)
     - (id)performButtonClick:(id)sender;
     @end

Then drag that file to IB, and I _think_ the method will appear for  
File’s Owner without you first having to make a subclass etc.





More information about the textmate mailing list