46 BOOL _shouldCloseDocument;
47 BOOL _supportsMultipleDocuments;
54 CPView _viewControllerContainerView;
89 - (id)initWithWindowCibName:(
CPString)aWindowCibName
100 - (id)initWithWindowCibName:(
CPString)aWindowCibName owner:(
id)anOwner
107 _windowCibName = aWindowCibName;
113 - (id)initWithWindowCibPath:(
CPString)aWindowCibPath owner:(
id)anOwner
120 _windowCibPath = aWindowCibPath;
142 - (@action)showWindow:(
id)aSender
144 var theWindow = [
self window];
146 if ([theWindow respondsToSelector:
@selector(becomesKeyOnlyIfNeeded)] && [theWindow becomesKeyOnlyIfNeeded])
147 [theWindow orderFront:aSender];
149 [theWindow makeKeyAndOrderFront:aSender];
156 - (BOOL)isWindowLoaded
158 return _window !== nil;
170 [_document windowControllerWillLoadCib:self];
174 if (_window === nil && [_cibOwner isKindOfClass:[
CPDocument class]])
175 [
self setWindow:[_cibOwner valueForKey:@"window"]];
179 var reason = [
CPString stringWithFormat:@"Window for %@ could not be loaded from Cib or no window specified. Override loadWindow to load the window manually.", self];
185 [_document windowControllerDidLoadCib:self];
199 [_window setWindowController:nil];
203 [_window setWindowController:self];
204 [_window setNextResponder:self];
210 - (void)windowDidLoad
217 - (void)windowWillLoad
227 if (_document === aDocument)
234 if (![
self supportsMultipleDocuments])
237 [defaultCenter removeObserver:self
238 name:CPDocumentWillSaveNotification
241 [defaultCenter removeObserver:self
242 name:CPDocumentDidSaveNotification
245 [defaultCenter removeObserver:self
246 name:CPDocumentDidFailToSaveNotification
250 _document = aDocument;
256 [defaultCenter addObserver:self
257 selector:@selector(_documentWillSave:)
258 name:CPDocumentWillSaveNotification
261 [defaultCenter addObserver:self
262 selector:@selector(_documentDidSave:)
263 name:CPDocumentDidSaveNotification
266 [defaultCenter addObserver:self
267 selector:@selector(_documentDidFailToSave:)
268 name:CPDocumentDidFailToSaveNotification
274 var viewController = [_document viewControllerForWindowController:self];
286 - (void)setSupportsMultipleDocuments:(BOOL)shouldSupportMultipleDocuments
288 _supportsMultipleDocuments = shouldSupportMultipleDocuments;
291 - (BOOL)supportsMultipleDocuments
293 return _supportsMultipleDocuments;
298 if (aDocument && ![_documents containsObject:aDocument])
299 [_documents addObject:aDocument];
304 var index = [_documents indexOfObjectIdenticalTo:aDocument];
309 [_documents removeObjectAtIndex:index];
311 if (_document === aDocument && [_documents count])
312 [
self setDocument:[_documents objectAtIndex:MIN(index, [_documents count] - 1)]];
315 - (void)removeDocumentAndCloseIfNecessary:(
CPDocument)aDocument
319 if (![_documents count])
328 - (void)setViewControllerContainerView:(
CPView)aView
330 if (!_viewControllerContainerView && !aView)
339 [aView
setFrame:[contentView frame]];
342 if (viewControllerView)
344 [viewControllerView removeFromSuperview];
350 else if (viewControllerView)
352 [viewControllerView removeFromSuperview];
353 [viewControllerView setFrame:[contentView frame]];
354 [viewControllerView setAutoresizingMask:[contentView autoresizingMask]]
360 [view setFrame:[contentView frame]];
361 [view setAutoresizingMask:[contentView autoresizingMask]];
365 _viewControllerContainerView = aView;
368 - (void)viewControllerContainerView
370 return _viewControllerContainerView;
375 if (!_viewController && !aViewController)
383 var oldView = [_viewController isViewLoaded] ? [_viewController view] : nil;
387 [newView setFrame:[oldView frame]];
388 [newView setAutoresizingMask:[oldView autoresizingMask]];
391 if (oldView && newView)
392 [containerView replaceSubview:oldView with:newView];
394 [oldView removeFromSuperview];
396 [containerView addSubview:newView];
401 [newView setFrame:[contentView frame]];
402 [newView setAutoresizingMask:[contentView autoresizingMask]];
410 [view setFrame:[contentView frame]];
411 [view setAutoresizingMask:[contentView autoresizingMask]];
415 _viewController = aViewController;
420 return _viewController;
426 [[
self window] setDocumentSaving:YES];
432 [[
self window] setDocumentSaving:NO];
438 [[
self window] setDocumentSaving:NO];
453 - (void)setDocumentEdited:(BOOL)isEdited
463 - (void)setShouldCloseDocument:(BOOL)shouldCloseDocument
465 _shouldCloseDocument = shouldCloseDocument;
468 - (BOOL)shouldCloseDocument
470 return _shouldCloseDocument;
481 return _windowCibName;
483 return [[_windowCibPath lastPathComponent] stringByDeletingPathExtension];
489 return _windowCibPath;
499 - (void)synchronizeWindowTitleWithDocumentName
501 if (!_document || !_window)