Welcome to MacForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Respond to modifier key press in Preference Pane

 
   Macintosh computer (Home) -> Programmer Help RSS
Next:  load two Kext with same CFBundleIdentifier  
Author Message
Heath Raftery

External


Since: Jul 10, 2003
Posts: 164



(Msg. 1) Posted: Fri Feb 22, 2008 11:21 am
Post subject: Respond to modifier key press in Preference Pane
Archived from groups: comp>sys>mac>programmer>help (more info?)

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?

--
*--------------------------------------------------------*
| ^Nothing is foolproof to a sufficiently talented fool^ |
| Heath Raftery, HRSoftWorks _\|/_ |
*______________________________________m_('.')_m_________*

 >> Stay informed about: Respond to modifier key press in Preference Pane 
Back to top
Login to vote
noreply

External


Since: Dec 02, 2004
Posts: 160



(Msg. 2) Posted: Fri Feb 22, 2008 11:21 am
Post subject: Re: Respond to modifier key press in Preference Pane [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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. 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

 >> Stay informed about: Respond to modifier key press in Preference Pane 
Back to top
Login to vote
Heath Raftery

External


Since: Jul 10, 2003
Posts: 164



(Msg. 3) Posted: Sun Feb 24, 2008 11:47 pm
Post subject: Re: Respond to modifier key press in Preference Pane [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to "add" a modifier to a keycode? - I am trying to figure out a way to get the charCode result when a certain modifier is applied to a keyCode. I know that KeyTranslate will go from keyCode to charCode, but I wasn't sure how to add modifiers (option, shift, etc) to that equation. For..

POSTEVENT and modifier keys - I have been using postevent in realbasic to send key down events to the event queu. Does anyone know how to include modifier keys in the routine? I am sending a keycode/ascii character as the eventmsg. Is there a way to specify the combination of the..

Warning: 'Class' does not respond to 'method' - I have three classes: Map, which accumulates NSMutableArrays of the other two classes, Surface and Vertex. Communication between Map and the other two classes works fine. But Surface and Vertex needs to keep pointers to instances of each other. The..

How to get builds to respond to updates to files contained.. - I'm using Folder references to add folders for html help files to various targets in my Xcode projects. It would be nice if modifications to files inside the referenced folders forced a build of dependent targets, but this does not seem to happen. Is i...

Finder pane - Hi, Is there a way to have a pane in my app that works just like the finder? I've seen that you can bundle TextEdit-like features into your program with ease. I know Finder is carbon, not cocoa, but is it possible to do this with Finder as well? Cheers...
   Macintosh computer (Home) -> Programmer Help All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]