How can I access NSDocument?

Ask a Question related to Mac Programming, Design and Development.

  1. #1

    Default How can I access NSDocument?

    I have a window that is up all the time from the main nib when the
    application is launched. This window will process the data and
    depending which document is active, I want to update the document from
    the data in this window. I am having problem trying to get it to
    work. I can easily access the main window from the document by
    setting the delegate to the main window and call [NSApp delegate], but
    I can't to it the other way around. For example, if I have a
    NSTextField in my NSDocument. How do I update that data with the data
    from the main window?
    Toan Guest

  2. Similar Questions and Discussions

    1. Web Service + Anon Access, but getting 401 Access Denied Error
      I have a simple webservice that just returns a string. The security for this is set to windows authentication in IIS (XP Professional) and anonymous...
    2. Access 2002 PDFWriter VBA Code w/WinXP does not work like Access 2000
      I am trying to print an Access 2002 report (Windows XP OS) as a PDF. I had success with Access 2000 in a Windows 2000 environment, but as soon as I...
    3. Access Violation when using Visual Interdev to access Oracle
      I am running Windows 200 Pro, IIS 5.0 and trying to connect to an Oracle 8.1 database. Prior to applying a security patch to W2k, the ASP...
    4. one NSDocument, multiple windows; no focus change
      I've poked around a bit on getting multiple windows working under the NSDocument architecture, and have chosen the multiple NSWindowControllers...
    5. Getting NSDocument to load a file into current window
      Hi!, I am new to Cocoa, and was hopeing someone could help me with a little problem I was having. I am writing a simple hex editor, and would like...
  3. #2

    Default Re: How can I access NSDocument?

    Toan <toan@asianboxoffice.com> wrote:
    > I have a window that is up all the time from the main nib when the
    > application is launched. This window will process the data and
    > depending which document is active, I want to update the document from
    > the data in this window. I am having problem trying to get it to
    > work. I can easily access the main window from the document by
    > setting the delegate to the main window and call [NSApp delegate], but
    > I can't to it the other way around. For example, if I have a
    > NSTextField in my NSDocument. How do I update that data with the data
    > from the main window?
    If you are using the document framework (that is, you started with a
    Document-Based Cocoa app project), then from an interface item you can
    get its window and from a window you can get its windowController and
    from a windowController you can get the document. For further reading:

    ...TasksAndConcepts/ProgrammingTopics/Documents/index.html

    m.


    --
    matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    matt neuburg Guest

  4. #3

    Default Re: How can I access NSDocument?

    On Wed, 17 Sep 2003 22:03:39 GMT, [email]matt@tidbits.com[/email] (matt neuburg)
    wrote:
    >Toan <toan@asianboxoffice.com> wrote:
    >
    >> I have a window that is up all the time from the main nib when the
    >> application is launched. This window will process the data and
    >> depending which document is active, I want to update the document from
    >> the data in this window. I am having problem trying to get it to
    >> work. I can easily access the main window from the document by
    >> setting the delegate to the main window and call [NSApp delegate], but
    >> I can't to it the other way around. For example, if I have a
    >> NSTextField in my NSDocument. How do I update that data with the data
    >> from the main window?
    >
    >If you are using the document framework (that is, you started with a
    >Document-Based Cocoa app project), then from an interface item you can
    >get its window and from a window you can get its windowController and
    >from a windowController you can get the document. For further reading:
    >
    > ...TasksAndConcepts/ProgrammingTopics/Documents/index.html
    >
    >m.
    >
    >
    >--
    >matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    >Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    Thanks for the quick response. So, would this be the correct way to
    do it?

    - (MyDocument *)getDocument
    {
    MyDocument *currentDoc;
    NSArray *windows = [NSApp windows];

    unsigned count = [windows count];
    while (count--)
    {
    NSWindow *window = [windows objectAtIndex:count];
    if (window)
    {
    MyDocument *currentDoc = [[window windowController]
    document];
    }
    }

    return currentDoc;
    }
    Toan Guest

  5. #4

    Default Re: How can I access NSDocument?

    Toan <toan@asianboxoffice.com> wrote:
    >So, would this be the correct way to
    > do it?
    >
    > - (MyDocument *)getDocument
    > {
    > MyDocument *currentDoc;
    > NSArray *windows = [NSApp windows];
    >
    > unsigned count = [windows count];
    > while (count--)
    > {
    > NSWindow *window = [windows objectAtIndex:count];
    > if (window)
    > {
    > MyDocument *currentDoc = [[window windowController]
    > document];
    > }
    > }
    >
    > return currentDoc;
    > }
    Sorry, it isn't obvious to me what problem that code is trying to solve.
    m.

    --
    matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    matt neuburg Guest

  6. #5

    Default Re: How can I access NSDocument?

    On Wed, 17 Sep 2003 23:01:51 GMT, [email]matt@tidbits.com[/email] (matt neuburg)
    wrote:
    >Toan <toan@asianboxoffice.com> wrote:
    >
    >>So, would this be the correct way to
    >> do it?
    >>
    >> - (MyDocument *)getDocument
    >> {
    >> MyDocument *currentDoc;
    >> NSArray *windows = [NSApp windows];
    >>
    >> unsigned count = [windows count];
    >> while (count--)
    >> {
    >> NSWindow *window = [windows objectAtIndex:count];
    >> if (window)
    >> {
    >> MyDocument *currentDoc = [[window windowController]
    >> document];
    >> }
    >> }
    >>
    >> return currentDoc;
    >> }
    >
    >Sorry, it isn't obvious to me what problem that code is trying to solve.
    >m.
    >
    >--
    >matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    >Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    I'm trying to access the document from a different file. What I am
    trying to do is to create a function that will allow me to get a
    handle to the document. So, I was hoping that I can simply do the
    following with that.

    MyDocument *doc = [self getDocument];
    [doc [setTextData str]];

    setTextData would be a function define inside the document.



    Toan Guest

  7. #6

    Default Re: How can I access NSDocument?

    Toan <toan@asianboxoffice.com> wrote:
    > I'm trying to access the document from a different file
    I'm sorry, the words "from a different file" don't convey anything to
    me. Your desire is to say [self getDocument] but I don't understand who
    "self" is or how he can fail to know what the document is. Who is self
    and what document is he trying to obtain? m.


    --
    matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    matt neuburg Guest

  8. #7

    Default Re: How can I access NSDocument?

    On Thu, 18 Sep 2003 00:10:55 GMT, [email]matt@tidbits.com[/email] (matt neuburg)
    wrote:
    >Toan <toan@asianboxoffice.com> wrote:
    >
    >> I'm trying to access the document from a different file
    >
    >I'm sorry, the words "from a different file" don't convey anything to
    >me. Your desire is to say [self getDocument] but I don't understand who
    >"self" is or how he can fail to know what the document is. Who is self
    >and what document is he trying to obtain? m.
    >
    >
    >--
    >matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    >Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    Since I'm used to program in C, maybe I might confuse myself. Here's
    how it is.

    I have a file maincontroller.m and MyMainController is connected to
    the window in the main.nib

    @interface MyMainController : NSObject
    {
    }

    - (MyDocument *)getDocument

    @end

    So, if I was calling the function within the maincontroller.m, that is
    MyMainController, don't I have to do a [self getDocument] ?

    So, what it's trying to access is the MyDocument's records or
    tableView that is define inside the document.nib

    @interface MyDocument : NSDocument
    {
    NSMutableArray *records;
    IBOutlet id tableView;
    }

    @end


    Toan Guest

  9. #8

    Default Re: How can I access NSDocument?

    Toan <toan@asianboxoffice.com> wrote:

    [..]
    > I'm trying to access the document from a different file. What I am trying
    > to do is to create a function that will allow me to get a handle to the
    > document. So, I was hoping that I can simply do the following with that.
    >
    > MyDocument *doc = [self getDocument];
    > [doc [setTextData str]];
    >
    > setTextData would be a function define inside the document.
    It probably won't solve your problem, but if you look at the
    documentation for NSDocumentController's -documents method, things might
    become more clear. Or more confused. :-)

    You can get an array of all documents this way:

    NSArray *allTheDocuments = [[NSDocumentController
    sharedDocumentController] documents];

    Then you'll be able to search and sort through the documents however you
    want.
    Paul Mitchum Guest

  10. #9

    Default Re: How can I access NSDocument?

    Toan <toan@asianboxoffice.com> wrote:
    > So, if I was calling the function within the maincontroller.m, that is
    > MyMainController, don't I have to do a [self getDocument] ?
    >
    > So, what it's trying to access is the MyDocument's records or
    > tableView that is define inside the document.nib
    How about using NSDocumentController's - (id) currentDocument ?

    Per
    Per Bull Holmen Guest

  11. #10

    Default Re: How can I access NSDocument?

    Per Bull Holmen <pbh_news@yahoo.com> wrote:
    > Toan <toan@asianboxoffice.com> wrote:
    >
    > > So, if I was calling the function within the maincontroller.m, that is
    > > MyMainController, don't I have to do a [self getDocument] ?
    > >
    > > So, what it's trying to access is the MyDocument's records or
    > > tableView that is define inside the document.nib
    >
    > How about using NSDocumentController's - (id) currentDocument ?
    By the way, this would be the code:

    id theDocument = [[NSDocumentController sharedDocumentController]
    currentDocument];

    I have never tried it, so I don't know if it works.

    Per
    Per Bull Holmen Guest

  12. #11

    Default Re: How can I access NSDocument?

    On Wed, 17 Sep 2003 18:30:17 -0700, [email]usenet@mile23.com[/email].r3m0v3 (Paul
    Mitchum) wrote:
    >Toan <toan@asianboxoffice.com> wrote:
    >
    >[..]
    >> I'm trying to access the document from a different file. What I am trying
    >> to do is to create a function that will allow me to get a handle to the
    >> document. So, I was hoping that I can simply do the following with that.
    >>
    >> MyDocument *doc = [self getDocument];
    >> [doc [setTextData str]];
    >>
    >> setTextData would be a function define inside the document.
    >
    >It probably won't solve your problem, but if you look at the
    >documentation for NSDocumentController's -documents method, things might
    >become more clear. Or more confused. :-)
    >
    >You can get an array of all documents this way:
    >
    >NSArray *allTheDocuments = [[NSDocumentController
    >sharedDocumentController] documents];
    >
    >Then you'll be able to search and sort through the documents however you
    >want.

    Okay, I'll try these method. I was surprised that the function I
    define in the message ealier also worked. Although I am not exactly
    sure if it's getting the current active document or not.
    Toan Guest

  13. #12

    Default Re: How can I access NSDocument?

    Toan <toan@asianboxoffice.com> wrote:
    > what it's trying to access is the MyDocument's records or
    > tableView that is define inside the document.nib
    >
    > @interface MyDocument : NSDocument
    > {
    > NSMutableArray *records;
    > IBOutlet id tableView;
    > }
    You do not "define" an NSDocument inside a nib. (The nib is where you
    draw the windows.) The framework will create an NSDocument each time one
    is needed (either because the user said New or because the user said
    Open). There can be many NSDocuments (because the user can open many
    documents at a time). So I still do not know which one you want. If I
    don't know which NSDocument you want, I can't tell you how to access it.
    You should read the explanation of the document architecture I pointed
    you to earlier. m.


    --
    matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    matt neuburg Guest

  14. #13

    Default Re: How can I access NSDocument?

    On Thu, 18 Sep 2003 04:20:50 +0200, [email]pbh_news@yahoo.com[/email] (Per Bull
    Holmen) wrote:
    >Per Bull Holmen <pbh_news@yahoo.com> wrote:
    >
    >> Toan <toan@asianboxoffice.com> wrote:
    >>
    >> > So, if I was calling the function within the maincontroller.m, that is
    >> > MyMainController, don't I have to do a [self getDocument] ?
    >> >
    >> > So, what it's trying to access is the MyDocument's records or
    >> > tableView that is define inside the document.nib
    >>
    >> How about using NSDocumentController's - (id) currentDocument ?
    >
    >By the way, this would be the code:
    >
    >id theDocument = [[NSDocumentController sharedDocumentController]
    >currentDocument];
    >
    >I have never tried it, so I don't know if it works.
    >
    >Per
    I tried this method and it didn't work. theDocument became 0, the
    function I define actually worked.
    Toan Guest

  15. #14

    Default Re: How can I access NSDocument?

    Toan <toan@asianboxoffice.com> wrote:
    > On Thu, 18 Sep 2003 04:20:50 +0200, [email]pbh_news@yahoo.com[/email] (Per Bull
    > Holmen) wrote:
    >
    > >Per Bull Holmen <pbh_news@yahoo.com> wrote:
    > >
    > >> Toan <toan@asianboxoffice.com> wrote:
    > >>
    > >> > So, if I was calling the function within the maincontroller.m, that is
    > >> > MyMainController, don't I have to do a [self getDocument] ?
    > >> >
    > >> > So, what it's trying to access is the MyDocument's records or
    > >> > tableView that is define inside the document.nib
    > >>
    > >> How about using NSDocumentController's - (id) currentDocument ?
    > >
    > >By the way, this would be the code:
    > >
    > >id theDocument = [[NSDocumentController sharedDocumentController]
    > >currentDocument];
    > >
    > >I have never tried it, so I don't know if it works.
    > >
    > >Per
    >
    > I tried this method and it didn't work. theDocument became 0, the
    > function I define actually worked.
    My guess is that at the time you call the function, the main document is
    not your main window, because the "shared" window is, and so
    +currentDocument returns nil.

    You must have a method wich always points to the current document and no
    other document. My suggestion is you keep a static reference that always
    points to the main document:

    @implementation MainController

    static id currentDocument = nil;

    +(void)setCurrentDocument:(id)newDoc {

    currentDocument = newDoc;

    }

    +(id)currentDocument {

    return currentDocument;

    }

    +(void)documentGotClosed:(id)closeDoc {

    if( closeDoc == currentDocument )
    currentDocument = nil; // To avoid keeping references to
    invalid objects

    }

    // insert the rest of your code here

    Now you can always retrieve the current document this way:
    [MainController currentDocument];

    Set current document like this:
    [MainController setCurrentDocument:theDoc];

    In setCurrentDocument:, you should define the actions to update the
    shared window, so it always keeps the "shared" window updated, no matter
    if it's active or not etc...

    Now what you have to do, is make sure the appropriate methods always get
    called at the right time.... this requires a little investigation from
    your part:

    * You may use NSNotifications, to have MainController always get
    notified when a new document is current.
    * Override methods in either the documents window class (which must be
    subclassed), or the document (if NSDocument has defined methods for a
    document to become current).

    This is by far the best approach, because (if implemented correctly) it
    ALWAYS makes sure the maincontroller knows what document is active, and
    it ensures immediate update of the shared window. Also, the method for
    retrieving the shared window (via MainController) should be:

    static id sharedWindow = nil;

    +(void)setSharedWindow:(id)theWin {

    sharedWindow = theWin;

    }

    +(id)sharedWindow {

    return sharedWindow;

    }

    This is better than "weird" solutions like setting the NSApp's delegate
    if it's not needed for other reasons. Sorry this requires you to read
    and investigate a little if you're new to Objectve-C/Cocoa, but then
    again you learn the right way to do things... :)

    Per
    Per Bull Holmen Guest

  16. #15

    Default Re: How can I access NSDocument?

    On Thu, 18 Sep 2003 03:05:27 GMT, [email]matt@tidbits.com[/email] (matt neuburg)
    wrote:
    >Toan <toan@asianboxoffice.com> wrote:
    >
    >> what it's trying to access is the MyDocument's records or
    >> tableView that is define inside the document.nib
    >>
    >> @interface MyDocument : NSDocument
    >> {
    >> NSMutableArray *records;
    >> IBOutlet id tableView;
    >> }
    >
    >You do not "define" an NSDocument inside a nib. (The nib is where you
    >draw the windows.) The framework will create an NSDocument each time one
    >is needed (either because the user said New or because the user said
    >Open). There can be many NSDocuments (because the user can open many
    >documents at a time). So I still do not know which one you want. If I
    >don't know which NSDocument you want, I can't tell you how to access it.
    >You should read the explanation of the document architecture I pointed
    >you to earlier. m.
    >
    >
    >--
    >matt neuburg, phd = [email]matt@tidbits.com[/email], [url]http://www.tidbits.com/matt/[/url]
    >Read TidBITS! It's free and smart. [url]http://www.tidbits.com[/url]
    The main controller will always try to access the active document.
    So, if there are 10 documents open, the main controller will access
    the last selected one (could be the first opened one).
    Toan Guest

  17. #16

    Default Re: How can I access NSDocument?

    On Thu, 18 Sep 2003 12:16:02 +0200, [email]pbh_news@yahoo.com[/email] (Per Bull
    Holmen) wrote:
    >Toan <toan@asianboxoffice.com> wrote:
    >
    >> On Thu, 18 Sep 2003 04:20:50 +0200, [email]pbh_news@yahoo.com[/email] (Per Bull
    >> Holmen) wrote:
    >>
    >> >Per Bull Holmen <pbh_news@yahoo.com> wrote:
    >> >
    >> >> Toan <toan@asianboxoffice.com> wrote:
    >> >>
    >> >> > So, if I was calling the function within the maincontroller.m, that is
    >> >> > MyMainController, don't I have to do a [self getDocument] ?
    >> >> >
    >> >> > So, what it's trying to access is the MyDocument's records or
    >> >> > tableView that is define inside the document.nib
    >> >>
    >> >> How about using NSDocumentController's - (id) currentDocument ?
    >> >
    >> >By the way, this would be the code:
    >> >
    >> >id theDocument = [[NSDocumentController sharedDocumentController]
    >> >currentDocument];
    >> >
    >> >I have never tried it, so I don't know if it works.
    >> >
    >> >Per
    >>
    >> I tried this method and it didn't work. theDocument became 0, the
    >> function I define actually worked.
    >
    >My guess is that at the time you call the function, the main document is
    >not your main window, because the "shared" window is, and so
    >+currentDocument returns nil.
    >
    >You must have a method wich always points to the current document and no
    >other document. My suggestion is you keep a static reference that always
    >points to the main document:
    >
    >@implementation MainController
    >
    > static id currentDocument = nil;
    >
    > +(void)setCurrentDocument:(id)newDoc {
    >
    > currentDocument = newDoc;
    >
    > }
    >
    > +(id)currentDocument {
    >
    > return currentDocument;
    >
    > }
    >
    > +(void)documentGotClosed:(id)closeDoc {
    >
    > if( closeDoc == currentDocument )
    > currentDocument = nil; // To avoid keeping references to
    >invalid objects
    >
    > }
    >
    > // insert the rest of your code here
    >
    >Now you can always retrieve the current document this way:
    >[MainController currentDocument];
    >
    >Set current document like this:
    >[MainController setCurrentDocument:theDoc];
    >
    >In setCurrentDocument:, you should define the actions to update the
    >shared window, so it always keeps the "shared" window updated, no matter
    >if it's active or not etc...
    >
    >Now what you have to do, is make sure the appropriate methods always get
    >called at the right time.... this requires a little investigation from
    >your part:
    >
    >* You may use NSNotifications, to have MainController always get
    >notified when a new document is current.
    >* Override methods in either the documents window class (which must be
    >subclassed), or the document (if NSDocument has defined methods for a
    >document to become current).
    >
    >This is by far the best approach, because (if implemented correctly) it
    >ALWAYS makes sure the maincontroller knows what document is active, and
    >it ensures immediate update of the shared window. Also, the method for
    >retrieving the shared window (via MainController) should be:
    >
    > static id sharedWindow = nil;
    >
    > +(void)setSharedWindow:(id)theWin {
    >
    > sharedWindow = theWin;
    >
    > }
    >
    > +(id)sharedWindow {
    >
    > return sharedWindow;
    >
    > }
    >
    >This is better than "weird" solutions like setting the NSApp's delegate
    >if it's not needed for other reasons. Sorry this requires you to read
    >and investigate a little if you're new to Objectve-C/Cocoa, but then
    >again you learn the right way to do things... :)
    >
    >Per
    I thought about doing it that way because that's how I used to do it
    on the Windows side. Except that I also need to call [MainController
    setCurrentDocument:this]; whenever a document gets focus. What I
    really want to do is to make the maincontroller like a tool window
    that never gets focus. You can click on the action you want and it
    will always perform on your current active document. So, of course
    the best would be able to just cycle through all the windows, find the
    top most one or the active one. Check to see if it's a document type.

    Also, can you tell me what's the difference between the + and -
    infront of the function?
    Toan Guest

  18. #17

    Default Re: How can I access NSDocument?


    [email]toan@asianboxoffice.com[/email] (Toan) writes:
    > I thought about doing it that way because that's how I used to do it
    > on the Windows side. Except that I also need to call [MainController
    > setCurrentDocument:this]; whenever a document gets focus. What I
    > really want to do is to make the maincontroller like a tool window
    > that never gets focus. You can click on the action you want and it
    > will always perform on your current active document. So, of course
    > the best would be able to just cycle through all the windows, find the
    > top most one or the active one. Check to see if it's a document type.
    In that case you probably want to use a panel rather than a
    window. I haven't done this myself, but the documentation on
    Apple's site suggests that.

    [url]http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/index.html#//apple_ref/doc/uid/10000031i[/url]

    Btw, CocoaBrowser is a really great tool for looking at the
    documentation.

    [url]http://homepage2.nifty.com/hoshi-takanori/cocoa-browser/[/url]
    > Also, can you tell me what's the difference between the + and -
    > infront of the function?
    The + means it's a class method, - means it's an instance
    method. For example, alloc is a class method because you invoke it
    on the class object to create a new instance of that class. Init
    is an instance method because you invoke it on a particular
    object.

    id a = [NSArray array]; // class method
    [a objectAtIndex: i]; // instance method

    Check out Apple's Objective-C documentation for more.

    Also, cycling though array elements based on index works, but I
    believe the preferred way of doing this is to use NSEnumerator.

    [url]http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSArray.html#//apple_ref/doc/uid/20000137/BABCDDIC[/url]

    Hope this helps,

    Peter

    -- Peter Ilberg <peter.ilberg@ni.com>
    Peter Ilberg Guest

  19. #18

    Default Re: How can I access NSDocument?

    [email]toan@asianboxoffice.com[/email] (Toan) wrote in message news:<3f68d2ea.452947824@news.dslindiana.com>...
    > I have a window that is up all the time from the main nib when the
    > application is launched. This window will process the data and
    > depending which document is active, I want to update the document from
    > the data in this window. I am having problem trying to get it to
    > work. I can easily access the main window from the document by
    > setting the delegate to the main window and call [NSApp delegate], but
    > I can't to it the other way around. For example, if I have a
    > NSTextField in my NSDocument. How do I update that data with the data
    > from the main window?
    I'm not sure exactly what you're asking. I'm not sure what exactly
    you're
    calling the main window, because that term has another meaning in
    Cocoa.

    Is this, like, the tools window in Interface Builder? In that case,
    this is
    an NSPanel, which should never be the main window. The main window
    is, roughly, the topmost regular window, usually a document window.

    If this is what you're doing, it's simple. Give your NSPanel a custom
    subclass of NSWindowController. When this needs to find out what
    the main (i.e. topmost document window), it can do [[NSApplication
    sharedApplication] mainWindow]; to find out what the document
    window is. It can also be notified when the main window changes,
    so that it can stay up-to-date, like this:

    [[NSNotificationCenter defaultCenter]addObserver:self
    selector:@selector(loadObserver:)
    name:(NSString *)NSWindowDidBecomeMainNotification
    object:nil];

    [[NSNotificationCenter defaultCenter]addObserver:self
    selector:@selector(loadObserver:)
    name:(NSString *)NSWindowDidResignMainNotification
    object:nil];

    This is a quote from some of my code, where loadObserver (you'd maybe
    want to call it loadDocument) is declared like this:

    - (void)loadObserver:(id)notification;

    This method is responsible for getting information from the document.

    Your subclassed controller will keep track of the main (document)
    window.
    As the user moves controls or it computes or whatever, it can use this
    information to stuff everything back into the main (document) window.

    If this *isn't* what you're doing, such as if you're trying to make
    this
    common window a regular window rather than a panel, I suggest
    rethinking the design, because that window can become main as
    well, and it may confuse the user, who will be unable to tell at a
    glance which is the main window.
    Eric Pepke Guest

  20. #19

    Default Re: How can I access NSDocument?

    On 18 Sep 2003 10:38:39 -0500, Peter Ilberg <peter.ilberg@ni.com>
    wrote:

    >In that case you probably want to use a panel rather than a
    >window. I haven't done this myself, but the documentation on
    >Apple's site suggests that.
    >
    Hmmm, I should think about doing that. So, can I put a whole
    quicktime video control inside a panel? Currently, my main window is
    where all the video process the data.
    >[url]http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/index.html#//apple_ref/doc/uid/10000031i[/url]
    >
    >Btw, CocoaBrowser is a really great tool for looking at the
    >documentation.
    >
    >[url]http://homepage2.nifty.com/hoshi-takanori/cocoa-browser/[/url]
    >
    >> Also, can you tell me what's the difference between the + and -
    >> infront of the function?
    >
    >The + means it's a class method, - means it's an instance
    >method. For example, alloc is a class method because you invoke it
    >on the class object to create a new instance of that class. Init
    >is an instance method because you invoke it on a particular
    >object.
    I see. For a while, I thought that was just a way Objective C define
    it's function.
    >
    > id a = [NSArray array]; // class method
    > [a objectAtIndex: i]; // instance method
    >
    >Check out Apple's Objective-C documentation for more.
    >
    >Also, cycling though array elements based on index works, but I
    >believe the preferred way of doing this is to use NSEnumerator.
    >
    >[url]http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSArray.html#//apple_ref/doc/uid/20000137/BABCDDIC[/url]
    >
    >Hope this helps,
    >
    >Peter
    >
    >-- Peter Ilberg <peter.ilberg@ni.com>
    Toan Guest

  21. #20

    Default Re: How can I access NSDocument?


    [email]toan@asianboxoffice.com[/email] (Toan) writes:
    > Hmmm, maybe I need to redesign the application. What I am trying to
    > do in this common window is to run quicktime connected to a capture
    > card. Since that is done at the start of the application, the window
    > will never close until you exit the application. Now, depending on
    > which document you have open, clicking on the grab button in the
    > common window will automatically save an image and display it to the
    > appropriate document (that is the active one).
    Why not simply create a new document window when the user clicks
    grab and display the image in there? Otherwise the user has to
    create a new empty window first and then grab the image. That
    seems wrong.

    Then, if you intend to allow the user to manipulate the captured
    image, you can implement a tools palette in a separate NSPanel.
    (separate from your quicktime window)

    -- Peter Ilberg <peter.ilberg@ni.com>
    Peter Ilberg Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139