Patrick Machielse wrote:
> Heath Raftery wrote:
>
>> I've been trying to get my NSPreferencePane to change the text on a
>> button in response to the user pressing the option key. From my
>> understanding of the documentation, the best way to do this in
>> Cocoa is to implement the
>>
>> - (void)flagsChanged:(NSEvent *)theEvent
>>
>> method of the relevant responder. I've added this method to my
>> NSPreferencePane subclass, set the Custom Class of my nib file
>> to my subclass, and wired the delegate of the Pref Pane window
>> to the File's Owner of that nib.
>>
>> Stil, my flagsChanged method doesn't get called (as tested by
>> NSLog call amongst other things).
>
> The thing to remember about pref panes is that the 'window' that
> contains your UI in the nib won't be shown in the System Preferences
> application. Instead its content (view?) will be displayed in the System
> Preferences app's window.
Aye, I think that's the clincher.
> You might try:
>
> 1) creating a custom view implementing flagsChanged: and set that as
> your nib window's content view. (you can do this in IB).
This is essentially what I ended up doing. Was pretty simple in IB to
subclass NSView, set the Custom Class of the NSView of the NSWindow
(visible in IB's tree view) to the subclass, and finally, add an
outlet to the subclass to point back at my NSPreferencePane
subclass.
That way the only code in the NSView subclass is the -flagsChanged
method with a call to the NSPreferencePane outlet. This is working
well now.
> 2) making your NSPreferencePane subclass a delegate of the System
> Preferences window at runtime. Try 'mainViewDidLoad' or 'didSelect'.
I tried a few variations of this but didn't get far.
I'm up and running now, but am trying to deal with the very annoying
behaviour of System Preferences to retain focus (in the search text
field) when a Pane is opened. That means when my Pref Pane is
clicked, it wont start receiving flagsChanges messages until the
user clicks in one of the pane's elements.
--
*--------------------------------------------------------*
| ^Nothing is foolproof to a sufficiently talented fool^ |
| Heath Raftery, HRSoftWorks _\|/_ |
*______________________________________m_('.')_m_________*
>> Stay informed about: Respond to modifier key press in Preference Pane