Professional Web Applications Themes

Continuation of NSTextField issues - Mac Programming

I still feel like I'm fighting things here. I have a prefs window with a handful of text fields that should all take positive integers. Before the prefs window is closed I must make sure all values are valid and if not raise an alert panel and reset the invalid values to their previous states. Looking through several apps (photoshop, eudora, acrobat reader), it seems text fields in prefs windows are handled in a fairly consistent manner: the user is allowed to enter any value into the field (including "illegal" characters) until either (a) the text field is deselected by ...

  1. #1

    Default Continuation of NSTextField issues

    I still feel like I'm fighting things here. I have a prefs window with a
    handful of text fields that should all take positive integers. Before
    the prefs window is closed I must make sure all values are valid and if
    not raise an alert panel and reset the invalid values to their previous
    states.

    Looking through several apps (photoshop, eudora, acrobat reader), it
    seems text fields in prefs windows are handled in a fairly consistent
    manner: the user is allowed to enter any value into the field (including
    "illegal" characters) until either (a) the text field is deselected by
    return, tab, mouse click, etc., or (b) the user clicks "OK" to close the
    window. When either (a) or (b) happens and there is an illegal value, an
    alert panel is raised.

    (a) can easily be handled by the text field's action. The problem is how
    to handle (b). I still do not see a way to do this without having to
    poll the text fields inside the button action method before the window
    is closed.

    I tried implementing -controlTextDidChange but then you are forced to
    error check after every keystroke which is not the behavior of the apps
    above and it leads to other problems. For example, I have two text
    fields that represent a range -- min and max. If the user sets the min
    to 7 and then tries to set the max to 15, when the user types the "1" I
    obviously do not want to treat that as an error (yet). However the user
    could click on the "OK" button at this point and then I have to respond
    to the illegal value in that field.

    It seems like maybe I should be using NSNumberFormatter but I am having
    a hard time following the doentation without any code examples, and I
    can't tell if this will solve the problem of a user closing the window
    while a text field is still being edited. If someone can confirm that
    formatters will fix the problem, I will continue down that path.

    I would like to learn a clean way to handle these situations the first
    time so I don't get into bad habits.

    Thanks in advance.

    Jamal Bernhard Guest

  2. #2

    Default Re: Continuation of NSTextField issues

    Tom Harrington <tphpcisys.no.spam.dammit.net> wrote:
    > Is there some reason you don't want to just check the values when the
    > user clicks "OK", and only close the window if they're valid?
    Only because polling all values seemed like a brute force method to me
    and I was looking for something cleaner, and in my first post on the
    subject I received more than one comment stating that I should make
    better use of the AppKit.
    Jamal Bernhard Guest

  3. #3

    Default Re: Continuation of NSTextField issues

    In article
    <jamalbspambegone-1E1E15.23251815082003news.sf.sbcglobal.net>,
    Jamal Bernhard <jamalbspambegonepacbell.goawayspam.net> wrote:
    > Tom Harrington <tphpcisys.no.spam.dammit.net> wrote:
    >
    > > Is there some reason you don't want to just check the values when the
    > > user clicks "OK", and only close the window if they're valid?
    >
    > Only because polling all values seemed like a brute force method to me
    > and I was looking for something cleaner, and in my first post on the
    > subject I received more than one comment stating that I should make
    > better use of the AppKit.
    It's frequently best to let GUI widgets tell you what to do, by
    listening for appropriate delegate callbacks, notifications, etc. But
    this can be taken too far. In the case of a window where the user's
    filling in NSTextFields, and clicking an "OK" button when done, there's
    nothing wrong with just asking all the text fields for their current
    value at the time the button is pressed.

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

  4. #4

    Default Re: Continuation of NSTextField issues

    Tom Harrington wrote:
    >>Only because polling all values seemed like a brute force method to me
    >>and I was looking for something cleaner, and in my first post on the
    >>subject I received more than one comment stating that I should make
    >>better use of the AppKit.
    >
    > It's frequently best to let GUI widgets tell you what to do, by
    > listening for appropriate delegate callbacks, notifications, etc. But
    > this can be taken too far. In the case of a window where the user's
    > filling in NSTextFields, and clicking an "OK" button when done, there's
    > nothing wrong with just asking all the text fields for their current
    > value at the time the button is pressed.
    Ok -- thanks a lot for the feedback...

    Jamal Bernhard Guest

Similar Threads

  1. continuation operator
    By cmmiv in forum Macromedia Director Basics
    Replies: 1
    Last Post: April 13th, 12:39 PM
  2. Green Background Continuation
    By Dick Cordi in forum Adobe Photoshop Elements
    Replies: 0
    Last Post: September 20th, 08:09 PM
  3. NSTextField -- question about when actions are sent
    By Jamal Bernhard in forum Mac Programming
    Replies: 7
    Last Post: August 14th, 10:53 PM
  4. Replies: 2
    Last Post: July 9th, 10:17 AM
  5. Replies: 0
    Last Post: July 9th, 06:28 AM

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