how to instantiate MyDocument with file from open panel?

  • I've run an open panel and called the openPanelDidEnd: selector, and I
    have the file the user has chosen in an array.  Now I'm a little stuck
    because I want to do something with that file; I want a new MyDocument
    instance to be created  and load the data from the file into a
    QTMovieView I've set up in IB.  I'm unsure how to do this, in
    particular instantiating MyDocument.  Googling for it indicates very
    few hits, so I'm probably approaching the problem the wrong way.
    Thanks for the help, all.

    ---------------------------------
    Nathaniel Gottlieb-Graham
    <sladuuch...>
    techpaladin.com
  • On Dec 6, 2007, at 11:59 AM, Nathaniel Gottlieb-Graham wrote:

    > I've run an open panel and called the openPanelDidEnd: selector, and
    > I have the file the user has chosen in an array.  Now I'm a little
    > stuck because I want to do something with that file; I want a new
    > MyDocument instance to be created  and load the data from the file
    > into a QTMovieView I've set up in IB.  I'm unsure how to do this, in
    > particular instantiating MyDocument.  Googling for it indicates very
    > few hits, so I'm probably approaching the problem the wrong way.
    > Thanks for the help, all.

    I'm assuming each new document has it's own QTMovieView, correct?

    If so, then you can instantiate a new document (using "[[ MyDocument
    alloc ] init ]" for example) from within openPanelDidEnd and either
    pass in the file via a parameter in your init method or some kind of
    setter.

    When the document is created, you should have it load the data from
    that file.

    In other words, if your "MyDocument" class have an standard init method:

    - (id) init

    You can follow up the

    MyDocument *newDocument;

    newDoc = [[ MyDocument alloc ] init ];
    if( newDoc ) // make sure newDoc isn't null
    {
    // set the document to point to that file
    [ newDoc setFile: [ arrayOfFiles objectAtIndex: indexOfFile ]];
    }

    Does this help??
  • Okay, I've made initWithMovie that calls a setMovie method.
    Everything gets called correctly, but my MyDocument's NIB never loads,
    or at least that's what it seems because windowControllerDidLoadNib
    never gets called.  Is there something special I have to to do get its
    NIB to load?

    Apologies for the basic questions, but I'm still quite new to this.

    On Dec 6, 2007, at 8:38 PM, Michael Dautermann wrote:

    >
    > On Dec 6, 2007, at 4:12 PM, Nathaniel Gottlieb-Graham wrote:
    >
    >> Do you think I should make my own init method?  I'm not going to
    >> need to ever change the movie in the QTMovieView, so maybe I should
    >> just make init into something like initWithMovie:(QTMovie) *movie.
    >> Does that sound like an okay idea, or would it be better to init
    >> with nothing and then put the movie into the view manually?
    >
    >
    > sure, "initWIthMovie: (QTMovie *) movie" would work just fine.
    >
    > As long as you handle a possible case when movie is NULL.
    >
  • On Dec 6, 2007, at 11:59 AM, Nathaniel Gottlieb-Graham wrote:

    > I've run an open panel and called the openPanelDidEnd: selector, and
    > I have the file the user has chosen in an array.  Now I'm a little
    > stuck because I want to do something with that file; I want a new
    > MyDocument instance to be created  and load the data from the file
    > into a QTMovieView I've set up in IB.
    >
    Are you using the document architecture (i.e. are you subclassing
    NSDocument)?
    If so, it's not clear why you are trying to run your own open panel or
    instantiate your own document instance.  Typically you simply let the
    framework take care of all the details for you -- see <http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Tasks/I
    mplementingDocApp.html
    >.

    mmalc
  • I am using the document architecture, and I had suspected that I was
    doing something dumb.  My situation is this:  On my application's
    launch, I want it to display a "welcome screen" of sorts, one of whose
    buttons triggers an open panel and prompts the user to choose a movie.
    A new document containing the movie in a player on that document's
    window will then be created.

    At the moment, I have the welcome screen, and a button does prompt the
    user to select a file and then packages it up into a QTMovie.  What I
    need to do next is simply create a new document and put that movie
    into one of its instance variables (the QTMovieView, I think).  To
    this end, I was trying to manually instantiate a MyDocument subclass
    in the openPanelDidEnd: selector.  If there's a better way to
    accomplish what I want, I'm all ears.

    On Dec 6, 2007, at 10:06 PM, mmalc crawford wrote:

    >
    > On Dec 6, 2007, at 11:59 AM, Nathaniel Gottlieb-Graham wrote:
    >
    >> I've run an open panel and called the openPanelDidEnd: selector,
    >> and I have the file the user has chosen in an array.  Now I'm a
    >> little stuck because I want to do something with that file; I want
    >> a new MyDocument instance to be created  and load the data from the
    >> file into a QTMovieView I've set up in IB.
    >>
    > Are you using the document architecture (i.e. are you subclassing
    > NSDocument)?
    > If so, it's not clear why you are trying to run your own open panel
    > or instantiate your own document instance.  Typically you simply let
    > the framework take care of all the details for you -- see <http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Tasks/I
    mplementingDocApp.html
    > >.
    >
    > mmalc
    >

    ---------------------------------
    Nathaniel Gottlieb-Graham
    Mac specialist
    <sladuuch...>
    techpaladin.com
  • I am using the document architecture, and I had suspected that I was
    doing something dumb.  My situation is this:  On my application's
    launch, I want it to display a "welcome screen" of sorts, one of whose
    buttons triggers an open panel and prompts the user to choose a movie.
    A new document containing the movie in a player on that document's
    window will then be created.

    At the moment, I have the welcome screen, and a button does prompt the
    user to select a file and then packages it up into a QTMovie.  What I
    need to do next is simply create a new document and put that movie
    into one of its instance variables (the QTMovieView, I think).  To
    this end, I was trying to manually instantiate a MyDocument subclass
    in the openPanelDidEnd: selector.  If there's a better way to
    accomplish what I want, I'm all ears.

    On Dec 6, 2007, at 10:06 PM, mmalc crawford wrote:

    >
    > On Dec 6, 2007, at 11:59 AM, Nathaniel Gottlieb-Graham wrote:
    >
    >> I've run an open panel and called the openPanelDidEnd: selector,
    >> and I have the file the user has chosen in an array.  Now I'm a
    >> little stuck because I want to do something with that file; I want
    >> a new MyDocument instance to be created  and load the data from the
    >> file into a QTMovieView I've set up in IB.
    >>
    > Are you using the document architecture (i.e. are you subclassing
    > NSDocument)?
    > If so, it's not clear why you are trying to run your own open panel
    > or instantiate your own document instance.  Typically you simply let
    > the framework take care of all the details for you -- see <http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Tasks/I
    mplementingDocApp.html
    > >.
    >
    > mmalc
    >

    ---------------------------------
    Nathaniel Gottlieb-Graham
    Mac specialist
    <sladuuch...>
    techpaladin.com
  • On Dec 6, 2007, at 9:32 PM, Nathaniel Gottlieb-Graham wrote:

    > What I need to do next is simply create a new document and put that
    > movie into one of its instance variables (the QTMovieView, I
    > think).  To this end, I was trying to manually instantiate a
    > MyDocument subclass in the openPanelDidEnd: selector.
    >
    If you need to create a document instance, you typically go through
    the shared document controller ([NSDocumentController
    sharedDocumentController]) and then invoke one of the document
    creation methods.  In your situation, it's likely to be
    makeUntitledDocumentOfType:error:.  You can then send that instance
    whatever messages you want to initialise its contents.

    mmalc
  • On 06.12.2007, at 20:59, Nathaniel Gottlieb-Graham wrote:

    > I've run an open panel and called the openPanelDidEnd: selector, and
    > I have the file the user has chosen in an array.  Now I'm a little
    > stuck because I want to do something with that file; I want a new
    > MyDocument instance to be created  and load the data from the file
    > into a QTMovieView I've set up in IB.  I'm unsure how to do this, in
    > particular instantiating MyDocument.  Googling for it indicates very
    > few hits, so I'm probably approaching the problem the wrong way.
    > Thanks for the help, all.

    you'll need to specify the file-type -> class mapping in the Info.plist.
    The easiest way is to go to your application target's "Properties"
    pane and define a new Document Type there. Once you've associated the
    document type with your MyDocument class, AppKit will instantiate your
    class when an appropriate document is opened.

    HTH,
    </jum>
  • On Dec 7, 2007, at 08:46, Jens Miltner wrote:

    >
    > On 06.12.2007, at 20:59, Nathaniel Gottlieb-Graham wrote:
    >
    >> I've run an open panel and called the openPanelDidEnd: selector,
    >> and I have the file the user has chosen in an array.  Now I'm a
    >> little stuck because I want to do something with that file; I want
    >> a new MyDocument instance to be created  and load the data from the
    >> file into a QTMovieView I've set up in IB.  I'm unsure how to do
    >> this, in particular instantiating MyDocument.  Googling for it
    >> indicates very few hits, so I'm probably approaching the problem
    >> the wrong way.
    >> Thanks for the help, all.
    >
    > you'll need to specify the file-type -> class mapping in the
    > Info.plist.
    > The easiest way is to go to your application target's "Properties"
    > pane and define a new Document Type there. Once you've associated
    > the document type with your MyDocument class, AppKit will
    > instantiate your class when an appropriate document is opened.

    Then, implement -readFromData:ofType:error:, -
    readFromFileWrapper:ofType:error:, or -readFromURL:ofType:error: to
    initialize your document from the opened file. Finally, connect the
    button on your Welcome screen to First Responder's openDocument:. The
    document architecture should take care of the rest for you.

    -Jacob
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