Professional Web Applications Themes

NSTextField -- question about when actions are sent - Mac Programming

I have a prefs window with a few NSTextFields. I am noticing two things: 1. Every time the prefs window is opened, the NSTextField that is the initial responder immediately sends its action to the target. 2. If I edit data in one of the text fields but don't deselect the text field (via tab, return, clicking on another control, etc) before I click on my "OK" button to close the window, no action is sent. Then, the next time I open the window, the action is immediately sent (and the text field reflects the updated value). Number 1 doesn't ...

  1. #1

    Default NSTextField -- question about when actions are sent

    I have a prefs window with a few NSTextFields. I am noticing two things:

    1. Every time the prefs window is opened, the NSTextField that is the
    initial responder immediately sends its action to the target.

    2. If I edit data in one of the text fields but don't deselect the text
    field (via tab, return, clicking on another control, etc) before I click
    on my "OK" button to close the window, no action is sent. Then, the next
    time I open the window, the action is immediately sent (and the text
    field reflects the updated value).


    Number 1 doesn't affect my program negatively -- it just forces my prefs
    controller object to do some un-needed processing. However, is there a
    way to prevent this, or should I just not worry about it?

    Number 2 is more troublesome, because you should be able to edit a text
    field in a prefs window and then immediately click on "OK" to close the
    window and have the new prefs stick. Just wondering if there is a
    commonly preferred way to handle this. I could add code to the method
    that closes the window which polls all text fields for their value
    before closing, but that hardly seems like a clean solution.

    Thanks in advance for any help.

    Jamal Bernhard Guest

  2. #2

    Default Re: NSTextField -- question about when actions are sent

    In <1060811321.698956sj-nntpcache-5> Jamal Bernhard wrote:
    > 2. If I edit data in one of the text fields but don't deselect the
    > text field (via tab, return, clicking on another control, etc) before
    > I click on my "OK" button to close the window, no action is sent.
    Don't *fight* the AppKit - *use* it. You don't get an action message
    from a textfield under those cirstances, so don't set things up in
    such a way that you rely on this. That is not what an action message in
    a textfield is for.

    What you want to do (keep track of the values of the textfields without
    polling them all as the window closes) is perfectly reasonable. But you
    need to drop back ten yards and punt. There are many, many perfectly
    good ways to do this - implement windowDidUpdate:, implement
    controlTextDidChange, use an NSFormatter, etc., etc. - but you aren't
    going to think of *any* of them if you keep trying to use the AppKit in
    a way that's not intended.

    m.

    --
    matt neuburg, phd = [email]matttidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
    REALbasic: The Definitive Guide! 2nd edition!
    [url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
    Subscribe to TidBITS. It's free and smart.
    matt neuburg Guest

  3. Moderated Post

    Default Re: NSTextField -- question about when actions are sent

    Removed by Administrator
    Jamal Bernhard Guest
    Moderated Post

  4. Moderated Post

    Default Re: NSTextField -- question about when actions are sent

    Removed by Administrator
    Eric Pepke Guest
    Moderated Post

  5. #5

    Default Re: NSTextField -- question about when actions are sent

    In <1060832382.254766sj-nntpcache-3> Jamal Bernhard wrote:
    > matt neuburg wrote:
    >
    >> What you want to do (keep track of the values of the textfields
    >> without polling them all as the window closes) is perfectly
    >> reasonable. But you need to drop back ten yards and punt. There are
    >> many, many perfectly good ways to do this - implement
    >> windowDidUpdate:, implement controlTextDidChange, use an NSFormatter,
    >> etc., etc. - but you aren't going to think of *any* of them if you
    >> keep trying to use the AppKit in a way that's not intended.
    >
    > And, for the record, I *am* a good programmer and don't want to use
    > the AppKit in unintended ways
    I didn't say anything about your programming abilities. I am giving you
    a very valuable piece of insight ("*use* the AppKit, don't *fight* it",
    is what I said). I am a teacher, and I'm telling you that if you can
    wrap your head around this little philosophical nugget (or koan) you
    will find Cocoa much easier (and better) than you ever dreamed. Instead,
    now you choose to fight not just Cocoa, but me. Ah, well. You can lead a
    horticulture but you can't make her think. m.

    --
    matt neuburg, phd = [email]matttidbits.com[/email], [url]http://www.tidbits.com/matt[/url]
    REALbasic: The Definitive Guide! 2nd edition!
    [url]http://www.amazon.com/exec/obidos/ASIN/0596001770/somethingsbymatt[/url]
    Subscribe to TidBITS. It's free and smart.
    matt neuburg Guest

  6. #6

    Default Re: NSTextField -- question about when actions are sent

    In article <20030814064402584-0700news.la.sbcglobal.net>,
    matt neuburg <matttidbits.com> wrote:
    > I didn't say anything about your programming abilities. I am giving you
    > a very valuable piece of insight ("*use* the AppKit, don't *fight* it",
    > is what I said). I am a teacher, and I'm telling you that if you can
    > wrap your head around this little philosophical nugget (or koan) you
    > will find Cocoa much easier (and better) than you ever dreamed.
    It's sometimes easier said than done, for people new to Cocoa. Sure,
    it's better to work with it than against it, but until you grok how it
    likes to work, it's not always apparent how to do that.

    --
    Tom "Tom" Harrington
    Macaroni, Automated System Maintenance for Mac OS X.
    Version 1.4: Best cleanup yet, gets files other tools miss.
    See [url]http://www.atomicbird.com/[/url]
    Tom Harrington Guest

  7. #7

    Default Re: NSTextField -- question about when actions are sent

    Jamal Bernhard <jamalb.spambegonepacbell.goodbyespam.net> wrote:
    > matt neuburg wrote:
    >
    > > What you want to do (keep track of the values of the textfields without
    > > polling them all as the window closes) is perfectly reasonable. But you
    > > need to drop back ten yards and punt. There are many, many perfectly
    > > good ways to do this - implement windowDidUpdate:, implement
    > > controlTextDidChange, use an NSFormatter, etc., etc. - but you aren't
    > > going to think of *any* of them if you keep trying to use the AppKit in
    > > a way that's not intended.
    >
    > Thanks for the pointers to areas I can check out. I'm a newbie to OOP
    > and Cocoa (about 25 hours put in thus far), so I haven't gotten to
    > -windowDidUpdate or -controlTextDidChange yet. But, I knew that either
    > (a) I was missing something obvious about NSTextField actions (in which
    > case someone here could straighten me out), or (b) I needed to learn
    > more (in which case someone here could point me in the right direction).
    > You have confirmed that it is (b). :-)
    There's a great little freeware application out there called Cocoa
    Browser. It turns the built-in Cocoa doentation into an
    easily-browseable heirarchical window (as many windows as you want,
    actually; I usually have one for appkit and one for foundation). Get it
    here: <http://makeashorterlink.com/?C2D052895>

    If you get it, you can run it, click on AppKit/Classes, and click on
    NSTextField. You'll see it doesn't have any delegate methods, and is a
    subclass of NSControl. So click on NSControl, and there's a list of all
    the delegate methods NSTextField inherits from NSControl, including
    -controlTextDidChange. Click on the methods for a description.

    I've learned more quickly about Cocoa by virtue of using Cocoa Browser
    than I would have with just the HTML doentation. Get it. :-)
    Paul Mitchum Guest

  8. #8

    Default Re: NSTextField -- question about when actions are sent

    Paul Mitchum wrote:
    > There's a great little freeware application out there called Cocoa
    > Browser. It turns the built-in Cocoa doentation into an
    > easily-browseable heirarchical window (as many windows as you want,
    > actually; I usually have one for appkit and one for foundation). Get it
    > here: <http://makeashorterlink.com/?C2D052895>
    awesome -- thanks!

    Jamal Bernhard Guest

Similar Threads

  1. Concurrent actions in Flex question
    By crzymnmchl in forum Macromedia Flex General Discussion
    Replies: 5
    Last Post: April 6th, 07:42 PM
  2. Tough actions/droplet/scripting question
    By Scott_Haneda@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 2
    Last Post: February 13th, 02:04 AM
  3. Actions - loading actions by opening .atn action file
    By Danny Raphael in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 8
    Last Post: September 1st, 05:34 PM
  4. Continuation of NSTextField issues
    By Jamal Bernhard in forum Mac Programming
    Replies: 3
    Last Post: August 18th, 08:11 PM
  5. question about actions in PS 5.5
    By Erik McCarthy in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 2
    Last Post: July 8th, 11:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139