intercepting NSBrowser multiple selection extension with shift down/up arrow

  • I've got an NSBrowser, and a secondary view whose value depends on the
    current selection in the NSBrowser.

    When only one item is selected, the secondary view shows the path of
    the selected item. When multiple items are selected, the secondary
    view should show nothing.

    I've set up a notification, that gets posted (currently) from

    -[NSMatrix selectCellAtRow:column:]
    -[NSMatrix mouseDown:]
    -[NSMatrix selectAll:]

    The observer for the notification updates the secondary view.

    I seem to be capturing everything so far, except for the case where
    the selection is extended by holding down shift and the up or down
    arrow key. Can anyone point me to a suitable method to hopefully
    overide as follows:

    - (void) someMethod:(id)someArg
    {
          [super someMethod:someArg];
          NSBrowser *browser = [self someMethodThatReturnsTheBrowser];
    [[NSNotificationCenter defaultCenter]
    postNotificationName:kMyBrowserSelectionWillChangeNotification
    object:browser];
    }

    I've tried

    -[NSMatrix setSelectionFrom:to:anchor:highlight:]

    and most of the other likely candidates, but they didn't seem to work.

        cheers,
              Martin

    --
    http://www.mildmanneredindustries.com/
  • On Oct 13, 2008, at 11:16 PM, Martin Redington wrote:
    > I've got an NSBrowser, and a secondary view whose value depends on the
    > current selection in the NSBrowser.
    [...]
    > I seem to be capturing everything so far, except for the case where
    > the selection is extended by holding down shift and the up or down
    > arrow key.

    It sounds like you're subclassing NSMatrix and using -setMatrixClass:
    on the browser?  You might be able to get it to work by also
    overriding -highlightCell:atRow:column:, but this seems like a lot of
    work.

    How about if you leave the matrix class alone and do [myBrowser
    setSendsActionOnArrowKeys:YES]?  Then give the browser a target and
    action, and in the action method do whatever you have to do.

    I would think there's an even simpler solution using bindings, but I
    don't know bindings so I can't help you there.

    --Andy
  • On Tue, Oct 14, 2008 at 5:25 AM, Andy Lee <aglee...> wrote:
    > On Oct 13, 2008, at 11:16 PM, Martin Redington wrote:
    >>
    >> I've got an NSBrowser, and a secondary view whose value depends on the
    >> current selection in the NSBrowser.
    >
    > [...]
    >>
    >> I seem to be capturing everything so far, except for the case where
    >> the selection is extended by holding down shift and the up or down
    >> arrow key.
    >
    > It sounds like you're subclassing NSMatrix and using -setMatrixClass: on the
    > browser?

    Yep. Sorry, I should have made that clearer. I have a custom NSMatrix class.

    It was more by trial and error than anything else that I ended up
    over-riding the NSMatrix methods - they were just the ones that seemed
    to work.

    > You might be able to get it to work by also overriding
    > -highlightCell:atRow:column:, but this seems like a lot of work.

    That sounds nasty. I really just want to post this notification
    whenever the selection changes.

    > How about if you leave the matrix class alone and do [myBrowser
    > setSendsActionOnArrowKeys:YES]?  Then give the browser a target and action,
    > and in the action method do whatever you have to do.

    That sounds promising, although a bit disappointing and possibly still
    a tiny bit hacky.

    Surely it shouldn't really be that hard to capture/intercept selection
    changes - to have to resort to trial and error over-riding of
    selectXXX, et al. methods is a bit irksome.

    I'd kind of hoped that I'd simply missed some method that I could
    over-ride to cover my broken cases.

    > I would think there's an even simpler solution using bindings, but I don't
    > know bindings so I can't help you there.

    I'm not using bindings in this context, although if anyone does know
    it might be of interest for the record.

      cheers,
                m.

    >
    > --Andy
    >
    >
    >
    >

    --
    http://www.mildmanneredindustries.com/
  • On Oct 14, 2008, at 12:45 AM, Martin Redington wrote:
    > On Tue, Oct 14, 2008 at 5:25 AM, Andy Lee <aglee...> wrote:
    >> How about if you leave the matrix class alone and do [myBrowser
    >> setSendsActionOnArrowKeys:YES]?  Then give the browser a target and
    >> action,
    >> and in the action method do whatever you have to do.
    >
    > That sounds promising, although a bit disappointing and possibly still
    > a tiny bit hacky.

    It works for me.  I did a quick test and it caught all the cases I
    tried, though I may have missed something.  If it helps with the ick
    factor, I would say that it's much less hacky to take advantage of one
    method's documented purpose -- "do something when the selection
    changes, even if it's via keyboard" -- than to do trivial overrides of
    multiple methods that you select by trial and error.

    The only possible issue I found with this approach is that it also
    catches at least one case where the selection *isn't* changing: if you
    have just one cell selected and you click it, the action method will
    be called even though the selection hasn't changed.  That should be
    easy to work around if it causes a problem.

    > Surely it shouldn't really be that hard to capture/intercept selection
    > changes - to have to resort to trial and error over-riding of
    > selectXXX, et al. methods is a bit irksome.

    I agree, it seems a weird omission, given that with NSTableView you
    have a choice of using either a delegate method or a notification for
    that very purpose.

    --Andy
  • On Tue, Oct 14, 2008 at 8:12 AM, Andy Lee <aglee...> wrote:
    > On Oct 14, 2008, at 12:45 AM, Martin Redington wrote:
    >>
    >> On Tue, Oct 14, 2008 at 5:25 AM, Andy Lee <aglee...> wrote:
    >>>
    >>> How about if you leave the matrix class alone and do [myBrowser
    >>> setSendsActionOnArrowKeys:YES]?  Then give the browser a target and
    >>> action,
    >>> and in the action method do whatever you have to do.
    >>
    >> That sounds promising, although a bit disappointing and possibly still
    >> a tiny bit hacky.
    >
    > It works for me.

    Me too :-) with a couple of exceptions ... see below ...

    > I did a quick test and it caught all the cases I tried,
    > though I may have missed something.

    I managed to remove all of my other notification posts, apart from

    selectAll:

    I also found that when modifying the selection programmatically, I
    needed to post the notification manually, so a more general mechanism
    than I require would need to post from at least a subset of the
    selectXXX: methods.

    > If it helps with the ick factor, I
    > would say that it's much less hacky to take advantage of one method's
    > documented purpose -- "do something when the selection changes, even if it's
    > via keyboard" -- than to do trivial overrides of multiple methods that you
    > select by trial and error.

    Fair comment, although the documentation for setSendsActionOnArrowKeys
    doesn't really state that explicitly - it probably wouldn't have
    occurred to me to try that for a long time.

    >> Surely it shouldn't really be that hard to capture/intercept selection
    >> changes - to have to resort to trial and error over-riding of
    >> selectXXX, et al. methods is a bit irksome.
    >
    > I agree, it seems a weird omission, given that with NSTableView you have a
    > choice of using either a delegate method or a notification for that very
    > purpose.
    >
    > --Andy
    >

    --
    http://www.mildmanneredindustries.com/
  • On Oct 14, 2008, at 8:11 AM, Martin Redington wrote:
    > On Tue, Oct 14, 2008 at 8:12 AM, Andy Lee <aglee...> wrote:
    >> If it helps with the ick factor, I
    >> would say that it's much less hacky to take advantage of one method's
    >> documented purpose -- "do something when the selection changes,
    >> even if it's
    >> via keyboard" -- than to do trivial overrides of multiple methods
    >> that you
    >> select by trial and error.
    >
    > Fair comment, although the documentation for setSendsActionOnArrowKeys
    > doesn't really state that explicitly - it probably wouldn't have
    > occurred to me to try that for a long time.

    Yeah, I was stretching for the interpretation my conscience would be
    most comfortable with :).  I think it's worth filing a Radar
    requesting notifications analogous to
    NSTableViewSelectionIsChangingNotification and
    NSTableViewSelectionDidChangeNotification.

    I did a quick search for a third-party alternative to NSBrowser, along
    the lines of what Rainer Brockerhoff did with RBSplitView.  I thought
    maybe there would be something at Cocoatech <http://www.cocoatech.com/opensource.php>.  But I haven't found anything.

    --Andy
  • On Tue, Oct 14, 2008 at 2:04 PM, Andy Lee <aglee...> wrote:
    > On Oct 14, 2008, at 8:11 AM, Martin Redington wrote:
    >>
    >> On Tue, Oct 14, 2008 at 8:12 AM, Andy Lee <aglee...> wrote:
    >>>
    >>> If it helps with the ick factor, I
    >>> would say that it's much less hacky to take advantage of one method's
    >>> documented purpose -- "do something when the selection changes, even if
    >>> it's
    >>> via keyboard" -- than to do trivial overrides of multiple methods that
    >>> you
    >>> select by trial and error.
    >>
    >> Fair comment, although the documentation for setSendsActionOnArrowKeys
    >> doesn't really state that explicitly - it probably wouldn't have
    >> occurred to me to try that for a long time.
    >
    > Yeah, I was stretching for the interpretation my conscience would be most
    > comfortable with :).  I think it's worth filing a Radar requesting
    > notifications analogous to NSTableViewSelectionIsChangingNotification and
    > NSTableViewSelectionDidChangeNotification.

    rdar://6290957

    > I did a quick search for a third-party alternative to NSBrowser, along the
    > lines of what Rainer Brockerhoff did with RBSplitView.  I thought maybe
    > there would be something at Cocoatech
    > <http://www.cocoatech.com/opensource.php>.  But I haven't found anything.

    Koders seems to have some NSBrowser code in its index, which might
    have something relevant, but I didn't look too closely.

    http://www.koders.com/default.aspx?s=NSBRowser&btn=&la=ObjectiveC&a
    mp;li=
    *

    >
    > --Andy
    >

    --
    http://www.mildmanneredindustries.com/
previous month october 2008 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