• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Programatically opening an NSDocument subclass ??
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programatically opening an NSDocument subclass ??


  • Subject: Re: Programatically opening an NSDocument subclass ??
  • From: Robert Miller <email@hidden>
  • Date: Mon, 17 Sep 2001 12:04:42 -0400
  • Organization: RFM & Associates

Thanks for the info. Here is a code snippet of what I've implemented and it
works OK, Whether it is the optimum solution is still a question.

-(IBAction) openYourDocument:(id)sender
{
int result;
NSOpenPanel *oPanel = [NSOpenPanel openPanel];

[oPanel setAllowsMultipleSelection:YES];
// present the user with an open file dialog that allows multiple file
selection
// note our 'types' array is nil, allowing for all file types to be
selectable
result = [oPanel runModalForDirectory:NSHomeDirectory() file:nil types:nil];


if (result == NSOKButton)
{
NSArray *filesToOpen = [oPanel filenames];
int count = [filesToOpen count];
int i;

// loop through the files selected and create a YourDocument for each.
for (i = 0; i < count; i++)
{
YourDocument *newDoc =
[[YourDocument alloc]
initWithContentsOfFile:[filesToOpen objectAtIndex: i]
ofType:@"YourDocument"];
// this tells the document to load the nib window
[newDoc makeWindowControllers];
// now display the window
[newDoc showWindows];
}
}
}

Robert S Goldsmith wrote:

> Hi :)
>
> I don't know much about NSDocument applications but I do
> know the following:
>
> You can open the open and save dialogs, either as modal
> sheets or as sheets not attached to a window, using the
> NSOpenPanel calls. Create an NSOpenPanel object with certian
> settings will give it as a seperate window and if you want
> it as a sheet appearing attached to a window, you use a
> similar method that uses a callback to return the result of
> what the user selects. Examples are in the documentation for
> NSOpenPanel.
>
> NSOpenPanel returns an NSString object which you can pass in
> a call to your NSDocumentController's methods such as
> OpenDocumentWithContentsOfFile:display: (and others).
>
> as a side note, if you don't want to use the
> NSDocumentController, NSApplication can be delegated to
> respond to application:openFile:. This is also the method
> called when a user doubleclicks on a file or drag-drops a
> file onto your application (at least if you don't have an
> NSDocumentController - I think).
>
> Robert
>
> Robert Miller wrote:
>
> > Hello,
> >
> > This is probably a very basic question but, I have an application
> > that opens different types of subclassed NSDocuments. I want to be able
> > to select a file to open (NOT using the standard File/Open... menu item)
> > and displays its contents in the appropriate NSDocument subclass. I have
> > an IBAction stub implemented which calls a method in my AppController
> > class. At tha point I'de like to present the user with a file selection
> > dialog and then open a doc if the user selects a file. The example code
> > provided seems to assume that any application has a matching nib file
> > for the document and its window. The execution of this default behaviore
> > seems to happen 'magically' through the NSApplication object when the
> > standard File/Open menu item is used. How would I go about implementing
> > the same standard behavior in my own custom menu item ? are there any
> > eamples available ?
> >
> > Thanks in advance,
> > Regards,
> > Bob M.
> > _______________________________________________
> > cocoa-dev mailing list
> > email@hidden
> > http://www.lists.apple.com/mailman/listinfo/cocoa-dev


  • Follow-Ups:
    • Re: Programatically opening an NSDocument subclass ??
      • From: Mark Piccirelli <email@hidden>
References: 
 >Programatically opening an NSDocument subclass ?? (From: Robert Miller <email@hidden>)
 >Re: Programatically opening an NSDocument subclass ?? (From: Robert S Goldsmith <email@hidden>)

  • Prev by Date: Re: Moving File to Trash Problem
  • Next by Date: Re: distributed processing ad multiThreading
  • Previous by thread: Re: Programatically opening an NSDocument subclass ??
  • Next by thread: Re: Programatically opening an NSDocument subclass ??
  • Index(es):
    • Date
    • Thread