Who owns the field editor?

  • I'm trying to figure out which NSTextField in my window is currently
    being edited; this is from a callback function and I don't want to
    drastically rearchitect the window's code to constantly keep track of
    what the user is doing.

    I've found that [myWindow firstResponder] returns the field editor, an
    NSTextView, instead of the window's NSTextField. This makes sense to me,
    but I can't figure out how to turn this information back into my
    NSTextField object. I also can't figure out any other way to figure out
    who owns the field editor, or what is currently being edited.

    Any clues?
  • On Dec 12, 2007, at 2:15 PM, John Stiles wrote:

    > I'm trying to figure out which NSTextField in my window is
    > currently being edited; this is from a callback function and I
    > don't want to drastically rearchitect the window's code to
    > constantly keep track of what the user is doing.
    >
    > I've found that [myWindow firstResponder] returns the field editor,
    > an NSTextView, instead of the window's NSTextField. This makes
    > sense to me, but I can't figure out how to turn this information
    > back into my NSTextField object. I also can't figure out any other
    > way to figure out who owns the field editor, or what is currently
    > being edited.

    The field editor's delegate should be the control being edited.

    <http://developer.apple.com/documentation/Cocoa/Conceptual/
    TextEditing/Tasks/FieldEditor.html
    >

    Jim
  • Great, that's easy. Thanks.
    I had looked at that document already but didn't see that crucial line.
    Out of curiosity, how about when editing a cell in a table view? Is the
    field editor's delegate going to be the table view, some mystery NSCell,
    or something else…?

    Jim Correia wrote:
    > On Dec 12, 2007, at 2:15 PM, John Stiles wrote:
    >
    >> I'm trying to figure out which NSTextField in my window is currently
    >> being edited; this is from a callback function and I don't want to
    >> drastically rearchitect the window's code to constantly keep track of
    >> what the user is doing.
    >>
    >> I've found that [myWindow firstResponder] returns the field editor,
    >> an NSTextView, instead of the window's NSTextField. This makes sense
    >> to me, but I can't figure out how to turn this information back into
    >> my NSTextField object. I also can't figure out any other way to
    >> figure out who owns the field editor, or what is currently being edited.
    >
    > The field editor's delegate should be the control being edited.
    >
    > <http://developer.apple.com/documentation/Cocoa/Conceptual/TextEditing/Tasks
    /FieldEditor.html
    >
    >
    >
    > Jim
  • > I'm trying to figure out which NSTextField in my window is currently
    > being edited

    I usually do something like the following (typed in mail):

    NSText *fe = [myWindow fieldEditor:NO ForObject:nil];
    if(nil!=fe){
        NSTextField *fieldBeingEdited = [fe delegate];
    }

    AFAIK, the thing being edited is always the delegate. I assume the
    delegate of an "unattached" field editor is nil, but haven't tested it.

    Cheers,
    -Joshua Emmons
  • On Dec 12, 2007, at 2:23 PM, John Stiles wrote:

    > Great, that's easy. Thanks.
    > I had looked at that document already but didn't see that crucial
    > line.
    > Out of curiosity, how about when editing a cell in a table view? Is
    > the field editor's delegate going to be the table view, some
    > mystery NSCell, or something else…?

    NSTableView is the control being edited in that case.

    Jim
previous month december 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
31            
Go to today