How to: NSPopover Refuse First Responder?

  • I'm trying to replicate the NSPopover functionality that the new iTunes has and I'm 99% there.  The las problem I'm facing is when the NSPopover appears it steals the firstResponder status from the NSSearchField so the user's typing gets interrupted when the popover appears.  I tried giving the firstResponser status back after the popover appear but all that does is mess up the user's typing.

    How can I have a popover appear but have the NSSearchField never relinquish it's firstResponder status or have the NSPopover refuse firstResponder?

    Thanks
  • On Mar 20, 2013, at 6:53 AM, Brad Stone wrote:

    > I'm trying to replicate the NSPopover functionality that the new iTunes has and I'm 99% there.  The las problem I'm facing is when the NSPopover appears it steals the firstResponder status from the NSSearchField so the user's typing gets interrupted when the popover appears.  I tried giving the firstResponser status back after the popover appear but all that does is mess up the user's typing.
    >
    > How can I have a popover appear but have the NSSearchField never relinquish it's firstResponder status or have the NSPopover refuse firstResponder?

    Hmm. I can think of reasons why this might not work, but it's worth a shot: Have you tried subclassing NSPopover and returning NO from -acceptsFirstResponder?

    --
    Seth Willits
  • Hmm. I can think of reasons why this might not work, but it's worth a shot: Have you tried subclassing NSPopover and returning NO from -acceptsFirstResponder?

    --
    Seth Willits

    Yes, I tried that and tested that it was returning NO.  It didn't work.
  • On 21/03/2013, at 12:53 AM, Brad Stone <cocoa-dev...> wrote:

    > How can I have a popover appear but have the NSSearchField never relinquish it's firstResponder status or have the NSPopover refuse firstResponder?

    I think you'll need to ensure that none of the views in the popover accept first responder, which is a pain to do (and if they need to become first responder under some circumstances, might be impossible in the current implementation).

    File a bug asking for something like -becomesKeyOnlyIfNeeded on NSPopover. The API is currently too limited.

    --Graham
  • On Mar 20, 2013, at 11:44 PM, Graham Cox <graham.cox...> wrote:

    >
    > On 21/03/2013, at 12:53 AM, Brad Stone <cocoa-dev...> wrote:
    >
    >> How can I have a popover appear but have the NSSearchField never relinquish it's firstResponder status or have the NSPopover refuse firstResponder?
    >
    >
    > I think you'll need to ensure that none of the views in the popover accept first responder, which is a pain to do (and if they need to become first responder under some circumstances, might be impossible in the current implementation).

    Worth a try but I have a feeling even this wouldn't be enough, because the popover's window could still become key window even if no view within accepts first responder. I suspect this is why it didn't help to have the NSPopover object refuse first responder.

    It would be nice if there were a way to get the popover's window to refuse first responder. I fiddled briefly with Apple's NSPopover sample app and haven't found a way yet to do this. Unfortunately, the window is an instance of a private class (_NSPopoverWindow), which means you don't get a chance to subclass it and override canBecomeKeyWindow.

    The opacity of NSPopover is very reminiscent of NSDrawer.

    --Andy

    >
    > File a bug asking for something like -becomesKeyOnlyIfNeeded on NSPopover. The API is currently too limited.
    >
    > --Graham
  • I always think of more to say *after* I hit Send...

    I haven't tried spelunking in iTunes, but I wouldn't be surprised if it doesn't use NSPopover. You might want to try an alternative like Matt Gemmell's MAAttachedWindow: <http://mattgemmell.com/source/>. I don't know if it has the same issues or not, but worth a look I think.

    --Andy

    On Mar 21, 2013, at 12:44 AM, Andy Lee <aglee...> wrote:

    >
    > On Mar 20, 2013, at 11:44 PM, Graham Cox <graham.cox...> wrote:
    >
    >>
    >> On 21/03/2013, at 12:53 AM, Brad Stone <cocoa-dev...> wrote:
    >>
    >>> How can I have a popover appear but have the NSSearchField never relinquish it's firstResponder status or have the NSPopover refuse firstResponder?
    >>
    >>
    >> I think you'll need to ensure that none of the views in the popover accept first responder, which is a pain to do (and if they need to become first responder under some circumstances, might be impossible in the current implementation).
    >
    > Worth a try but I have a feeling even this wouldn't be enough, because the popover's window could still become key window even if no view within accepts first responder. I suspect this is why it didn't help to have the NSPopover object refuse first responder.
    >
    > It would be nice if there were a way to get the popover's window to refuse first responder. I fiddled briefly with Apple's NSPopover sample app and haven't found a way yet to do this. Unfortunately, the window is an instance of a private class (_NSPopoverWindow), which means you don't get a chance to subclass it and override canBecomeKeyWindow.
    >
    > The opacity of NSPopover is very reminiscent of NSDrawer.
    >
    > --Andy
    >
    >
    >>
    >> File a bug asking for something like -becomesKeyOnlyIfNeeded on NSPopover. The API is currently too limited.
    >>
    >> --Graham
    >
previous month march 2013 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 31
Go to today