Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / February 2008



Tip: Looking for answers? Try searching our database.

Respond to modifier key press in Preference Pane

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Heath Raftery - 22 Feb 2008 13:21 GMT
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).

Any other suggestions for getting my PrefPane to respond to the
Option key? This idea is that if the user holds option, the
function of a button in the pane changes. The text on the
button should dynamically update and the action of the button
should pick up the modifier key press.

Surely I don't have to subclass NSWindow as well, set the NIB's
window to that subclass and implement the function in there?

Signature

*--------------------------------------------------------*

| ^Nothing is foolproof to a sufficiently talented fool^ |
|    Heath Raftery, HRSoftWorks          _\|/_           |
*______________________________________m_('.')_m_________*
Patrick Machielse - 22 Feb 2008 13:41 GMT
> 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
[quoted text clipped - 10 lines]
> 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. 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).

2) making your NSPreferencePane subclass a delegate of the System
Preferences window at runtime. Try 'mainViewDidLoad' or 'didSelect'.

Not sure which approach works (best) so you'll have to experiment a bit.

patrick
Heath Raftery - 25 Feb 2008 03:50 GMT
>> 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
[quoted text clipped - 15 lines]
> 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.

Signature

*--------------------------------------------------------*

| ^Nothing is foolproof to a sufficiently talented fool^ |
|    Heath Raftery, HRSoftWorks          _\|/_           |
*______________________________________m_('.')_m_________*
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.