Thanks to all who gave advice.

I'll give a description of what I did. If you have any further comments or suggestions please come forth!

In MainMenu.xib

An NSPanel that contains an NSOutlineView
An Application Delegate that has a reference to the NSOutlineView


In MyDocument.m

- (id)init
{
    self = [super init];
    if (self) {

        // Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
                
                m_treeDataSource = [[[TreeDataSource alloc] init] retain];
                m_treeDelegate = [[[TreeDelegate alloc] init] retain];
                
                if(!m_treeDataSource || !m_treeDelegate)
                {
                        [self release];
                        return nil;
                }
                
                m_appDelegate = [NSApp delegate];
                m_tree = m_appDelegate->m_tree;
                [m_tree retain];
                [m_tree setDataSource:m_treeDataSource];
                [m_tree setDelegate:m_treeDelegate];
    }
    return self;
}

- (void)windowDidBecomeKey:(NSNotification *)notification {
        
        [m_tree setDataSource:m_treeDataSource];
        [m_tree setDelegate:m_treeDelegate];

}


MyDocument.m has methods to manage m_treeDataSource

- (IBAction)root:(id)sender {
        
        TreeItem* root = [[[TreeItem alloc] init] retain];
        root->m_parent = nil;
        root->m_itemName = [m_root stringValue];  // m_root is a TextField   
        [m_treeDataSource->m_roots addObject:root];
}


- (IBAction)data:(id)sender {

        [m_tree reloadData];
}

Still have some problems that I'll ask some questions about in a bit.

db






On Dec 30, 2009, at 12:55 AM, Graham Cox wrote:


On 30/12/2009, at 4:23 PM, David Blanton wrote:

In a document based app I want to have some 'inspectors" that reflect what i sgoing on in the document. These inspectors should float.

If I make NSPanel's for the inspector in MyDocument.xib then each instance of a document gets its own set of inspectors.

I would like to have just one set of inspectors whose contents change as different documents are activated.

Putting the inspectors in MainMenu.xib will let me make just 'one set' for all documents but I am unsure as to how to get a reference from the inspector to the document given different xib's.

Suggestion please.


Each document your application opens will be a new instance built from the same nib. So even if there were a way to 'connect' objects in one nib to objects in another, it wouldn't help you - different documents will be made active at different times and your inspectors need to be aware of those activations.

A simple approach is to make your inspectors respond to all window did become main/resign main notifications, and then ask the document controller singleton for -currentDocument at those times. It can then figure out if the document itself has changed as a result of the active window change and do whatever it needs to do to inspect the document contents.

Setting up the notifications is best done in the inspector controller's -awakeFromNib method.

--Graham





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to