Re: setState not working as expected

  • On Tue, 25 Sep 2007 23:39:25 -0400, Bill Allaire <maillist2...> said:
    > I have a NSSearchField which is connected to a NSMenu by way of the
    > searchMenuTemplate in IB (Interface Builder).  The menu is working
    > great in that the recently searched items show up, the two
    > NSMenuItems items created to make use of
    > NSSearchFieldClearRecentsMenuItemTag and
    > NSSearchFieldNoRecentsMenuItemTag all work well and as expected.  I
    > followed "Introduction to Search Fields" to accomplish this.
    >
    > The last feature I wanted to add to this menu is to allow the user to
    > select which column (all or pick an individual column from the menu)
    > to filter content,  somewhat similar to what is in iTunes and its
    > search box with a choice of "All" or "Album" or "Artist", etc.  I
    > added three NSMenuItems to the NSMenu and titled them accordingly and
    > gave each a different tag starting at 1 and ending at 3.  All three
    > share the same target.  The first NSMenuItem is set to a state of
    > "On".  The other two are set to a state of "Off".
    >
    > Here is a sample of state change.  There are three NSMenuItems items
    > (in addition to the above mentioned items):
    > - Search All (initial state set to "On" via IB)
    > - Command (intial state set to "Off" via IB)
    > - Connection (ditto)
    >
    > Run application.  Pull down menu from the search field and choose,
    > say, Connection.  The target method logs the state of "Search All" as
    > NSOnState.  The target method sets the state for "Connection" to
    > NSOnState.  It then sets the state of "Search All" to NSOffState with
    > the intent of removing the check mark beside it, leaving "Connection"
    > as the only item with a check mark. I then log the state of "Search
    > All" after the state change and at this point and it shows
    > NSOffState.  So far so good.  I pull the menu down again and both
    > "Search All" and "Connection" have check marks.  Not good.  I also
    > notice that if I click back on "Search All", to turn it to an on
    > state, the logging, which logs the state before and after the call to
    > setState:, shows no change in state!  Like it's not responding to the
    > message being sent.
    >
    > I suspect there is something going on with how the NSSearchField is
    > using this menu that I don't understand.

    You don't give any code so clearly you don't want (and won't get) specific
    help. But in general, you might find it easiest to set menu item state in
    validateMenuItem:. All menu items arrive here, so you can check the tag and
    the current state of the app and set that menu item's state accordingly. For
    a working example, download my Thucydides app from versiontracker and look
    at the code for the *earlier* versions of the app (Thucydides and
    ThucydidesBinding), where I was using an NSSearchField menu to set search
    options. (In the current version of the app, ThucydidesCoreData, I use a
    different interface involving radio buttons and predicates.) m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    One of the 2007 MacTech Top 25: <http://tinyurl.com/2rh4pf>
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
  • On Sep 26, 2007, at 2:40 PM, Matt Neuburg wrote:

    > You don't give any code so clearly you don't want (and won't get)
    > specific
    > help. But in general, you might find it easiest to set menu item
    > state in
    > validateMenuItem:. All menu items arrive here, so you can check the
    > tag and
    > the current state of the app and set that menu item's state
    > accordingly. For
    > a working example, download my Thucydides app from versiontracker
    > and look
    > at the code for the *earlier* versions of the app (Thucydides and
    > ThucydidesBinding), where I was using an NSSearchField menu to set
    > search
    > options. (In the current version of the app, ThucydidesCoreData, I
    > use a
    > different interface involving radio buttons and predicates.) m.
    >

    Thank you.  validateMenuItem: worked just fine.

    bill
previous month september 2007 next month
MTWTFSS
          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
Go to today