Any examples of how to implement an inspector window?

  • I'm new to Cocoa (long time Carbon), and don't yet know where to look
    for many things.

    I've pulled a few examples of some UI techniques from the Apple dev
    pages, but I haven't come across something that shows me how to
    trigger the changes to a window when the selection changes.

    In this case, I need to know when the main window changes. At the very
    least, I need to change the title of my Inspector window to indicate
    which document it's targeting. My main windows (my documents' windows)
    typically have a single custom view, so changes to the selected object
    within a window will be obvious, I think (when I finally get to
    implementing it).

    But for now, where would I add code to change the appearance of my
    inspector window when the main window changes?

    TIA,
    Rick
  • You should get Aaron Hillegass's book on Cocoa. It will save you hours.

    Apple's docs are actually quite good so that's where you can look for
    things. Also good places are the list archives for this list <http://
    www.cocoabuilder.com>, and <http://www.cocoadev.com/>.

    A more directed hint is to read up on "notifications" and
    "delegation". Then look at the docs for NSWindow. Windows post
    notifications when they become resign "key" or "main" (note that
    there is a difference between being "key" and being "main". You will
    probably be interested in knowing when your windows become or resign
    "main"). They also call delegate methods. Which technique you use is
    up to you.

    _murat

    On Nov 15, 2007, at 9:39 AM, Rick Mann wrote:

    > I'm new to Cocoa (long time Carbon), and don't yet know where to
    > look for many things.
    >
    > I've pulled a few examples of some UI techniques from the Apple dev
    > pages, but I haven't come across something that shows me how to
    > trigger the changes to a window when the selection changes.
    >
    > In this case, I need to know when the main window changes. At the
    > very least, I need to change the title of my Inspector window to
    > indicate which document it's targeting. My main windows (my
    > documents' windows) typically have a single custom view, so changes
    > to the selected object within a window will be obvious, I think
    > (when I finally get to implementing it).
    >
    > But for now, where would I add code to change the appearance of my
    > inspector window when the main window changes?
  • On Thu, November 15, 2007 12:39 pm, Rick Mann said:
    > I'm new to Cocoa (long time Carbon), and don't yet know where to look
    > for many things.
    >
    > I've pulled a few examples of some UI techniques from the Apple dev
    > pages, but I haven't come across something that shows me how to
    > trigger the changes to a window when the selection changes.
    >
    > In this case, I need to know when the main window changes. At the very
    > least, I need to change the title of my Inspector window to indicate
    > which document it's targeting. My main windows (my documents' windows)
    > typically have a single custom view, so changes to the selected object
    > within a window will be obvious, I think (when I finally get to
    > implementing it).
    >
    > But for now, where would I add code to change the appearance of my
    > inspector window when the main window changes?

    I don't have examples for you, but the basic procedure would be to
    register for notifications an all possible main windows, and change the
    inspector's appearence on 'windowDidBecomeKey:' or 'windowDidBecomeMain:'
    as approprate.  Read up on Notifications:
    http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/ind
    ex.html


    And then take a look at NSWindow's documentation for the above methods.

    Daniel T. Staal

    ---------------------------------------------------------------
    This email copyright the author.  Unless otherwise noted, you
    are expressly allowed to retransmit, quote, or otherwise use
    the contents for non-commercial purposes.  This copyright will
    expire 5 years after the author's death, or in 30 years,
    whichever is longer, unless such a period is in excess of
    local copyright law.
    ---------------------------------------------------------------
  • The Sketch example application on your hard disk includes an inspector I believe.

      In addition, a search of cocoabuilder is revealing: <A href="http://www.cocoabuilder.com/archive/message/cocoa/2002/8/7/68068">http://www.cocoabuilder.com/archive/message/cocoa/2002/8/7/68068


      There are at least two popular approaches:

      1) Send a notification whenever selection changes and observe the notification in the inspector's controller

      2) Use the applicationDidUpdate: delegate method or notification that already exists, and then use the keyWindow, mainWindow, and firstResponder methods to get detailed selection status

      2.5) I like to use applicationDidUpdate: and sendAction:(SEL)anAction to:(id)aTarget from:(id)sender

      - (void)setObjectToInspect:(id)someObject
      {
        // remember someObject and update the inspector...
      }


      - (void)applicationDidUpdate:(NSNotification *)aNotification
      {
        [[NSApplication sharedApplication] sendAction:@selector(updateSendersObjectToInspect:) to:nil from:self];
      }

      Then, the first object in the responder chain that responds to updateSendersObjectToInspect: will simply call [sender setObjectToInspect:] passing whatever object should be inspected.

      Coming from Carbon, you may need to educate yourself about basic Cocoa concepts such as the responder chain, targets, actions, notifications, key window, and main window.
  • On Nov 15, 2007, at 9:39 AM, Rick Mann wrote:

    > In this case, I need to know when the main window changes. At the
    > very least, I need to change the title of my Inspector window to
    > indicate which document it's targeting. My main windows (my
    > documents' windows) typically have a single custom view, so changes
    > to the selected object within a window will be obvious, I think
    > (when I finally get to implementing it).
    >
    <file:///Developer/Examples/AppKit/TextEdit/>
    <http://homepage.mac.com/mmalc/CocoaExamples/BindingsDocumentInspector.zip>

    mmalc
  • On Nov 15, 2007, at 10:30 AM, Murat Konar wrote:

    > You should get Aaron Hillegass's book on Cocoa. It will save you
    > hours.

    I have it. I'm actually not that happy with it.

    > Apple's docs are actually quite good so that's where you can look
    > for things. Also good places are the list archives for this list <http://www.cocoabuilder.com
    > >, and <http://www.cocoadev.com/>.

    Thanks, but it can take a lot of time just navigating the TOC trying
    to zero in on the right area to read.

    > A more directed hint is to read up on "notifications" and
    > "delegation". Then look at the docs for NSWindow. Windows post
    > notifications when they become resign "key" or "main" (note that
    > there is a difference between being "key" and being "main". You will
    > probably be interested in knowing when your windows become or resign
    > "main"). They also call delegate methods. Which technique you use is
    > up to you.

    That's exactly what I was looking for...now I know where to look/what
    to look for. Thank you!

    --
    Rick
  • On Nov 15, 2007, at 11:09 AM, mmalc crawford wrote:

    > On Nov 15, 2007, at 9:39 AM, Rick Mann wrote:
    >
    >> In this case, I need to know when the main window changes. At the
    >> very least, I need to change the title of my Inspector window to
    >> indicate which document it's targeting. My main windows (my
    >> documents' windows) typically have a single custom view, so changes
    >> to the selected object within a window will be obvious, I think
    >> (when I finally get to implementing it).
    >>
    > <file:///Developer/Examples/AppKit/TextEdit/>
    > <http://homepage.mac.com/mmalc/CocoaExamples/BindingsDocumentInspector.zip
    > >

    Oh! Thank you! Perfect. (I assume these examples use the currently
    most-sanctioned way of doing this.)

    Thanks!
  • On Nov 15, 2007, at 11:41 AM, Rick Mann wrote:

    >> <file:///Developer/Examples/AppKit/TextEdit/>
    >> <http://homepage.mac.com/mmalc/CocoaExamples/BindingsDocumentInspector.zip
    >> >
    >
    > Oh! Thank you! Perfect. (I assume these examples use the currently
    > most-sanctioned way of doing this.)
    >
    Yes, the latter is an inspector-specific distillation of the former
    (with some tweaks, IIRC).

    mmalc
  • On Nov 15, 2007, at 11:05 AM, Erik Buck wrote:

    > Coming from Carbon, you may need to educate yourself about basic
    > Cocoa concepts such as the responder chain, targets, actions,
    > notifications, key window, and main window.

    Thanks. Already there on most of that, except notifications.
previous month november 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