title: Access main window from a NSDocument class
body: <p>I have a NSDocument class, where I'd need to access the main menu window, the one that gets opened when the app start. When I operate in that window from the app all seems to work, but when trying to do the same operations from <code>readFromFileWrapper:ofType:error:</code> the window I access seems to be nil. Why this happens?</p>
  
  <h3>EDIT: Some code which deals with this:</h3>
  
  <pre><code>- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
  {
      if([[NSFileManager alloc] fileExistsAtPath:[NSString stringWithFormat:@"%@/Project.plist",[[self fileURL] path]]]) {
          NSLog(@"%@", [[self fileURL] path]);
  
          NSDictionary *project = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Project.plist",[[self fileURL] path]]];
  
          if([[project objectForKey:@"type"] isEqualToString:@"vote"]) {
  
              [self openProject:[[self fileURL] path] type:@"vote"];
  
              return YES;
  
          } else if([[project objectForKey:@"type"] isEqualToString:@"quiz"]) {
  
              [self openProject:[[self fileURL] path] type:@"quiz"];
  
              return YES; 
  
          } else {
              return NO;
          }
      } else {
          return NO;
      }
  }
  </code></pre>
  
  <p>That is my <code>readFromFileWrapper:ofType:error:</code> method. Here is my <code>openProject:type:</code> method:</p>
  
  <pre><code>-(void)openProject:(NSString *)filepath type:(NSString *)type 
  {
      NSLog(@"Opening project @ %@",filepath);
      NSLog(@"%@", [MainWindow description]);
      [projectDesignerView setFrame:[[[[MainWindow contentView] subviews] objectAtIndex:0] frame]];
      [projectDesignerToolbar setFrame:[MainWindow frame] display:FALSE];
      [[MainWindow contentView] replaceSubview:[[[MainWindow contentView] subviews]objectAtIndex:0] with:projectDesignerView];
      [[projectDesignerToolbar toolbar] setShowsBaselineSeparator:YES];
      [MainWindow setToolbar:[projectDesignerToolbar toolbar]];
      [MainWindow setRepresentedFilename:filepath];
      [MainWindow setTitle:[NSString stringWithFormat:@"%@ - %@", [[filepath lastPathComponent] stringByDeletingPathExtension], [projectDesignerToolbar title]]];
      NSString *path = [[NSBundle mainBundle] pathForResource:@"projectDesigner" ofType:@"html"];
      NSURL *url = [NSURL fileURLWithPath:path];
      [[projectDesignerWebview mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
  }
  </code></pre>
  
  <p><code>NSLog(@"%@", [MainWindow description]);</code> returns nil, when <code>MainWindow</code> should be the Main App Window. I think the problem is that double-clicking on a file reallocs all, and hence is failing.</p>