51 BOOL _shouldCloseDocument;
52 BOOL _supportsMultipleDocuments;
59 CPView _viewControllerContainerView;
94 - (id)initWithWindowCibName:(
CPString)aWindowCibName
105 - (id)initWithWindowCibName:(
CPString)aWindowCibName owner:(
id)anOwner
112 _windowCibName = aWindowCibName;
118 - (id)initWithWindowCibPath:(
CPString)aWindowCibPath owner:(
id)anOwner
125 _windowCibPath = aWindowCibPath;
147 - (@action)showWindow:(
id)aSender
149 var theWindow = [
self window];
151 if ([theWindow respondsToSelector:
@selector(becomesKeyOnlyIfNeeded)] && [theWindow becomesKeyOnlyIfNeeded])
152 [theWindow orderFront:aSender];
154 [theWindow makeKeyAndOrderFront:aSender];
161 - (BOOL)isWindowLoaded
163 return _window !== nil;
175 [_document windowControllerWillLoadCib:self];
179 if (_window === nil && [_cibOwner isKindOfClass:[
CPDocument class]])
180 [
self setWindow:[_cibOwner valueForKey:@"window"]];
184 var reason = [
CPString stringWithFormat:@"Window for %@ could not be loaded from Cib or no window specified. Override loadWindow to load the window manually.", self];
190 [_document windowControllerDidLoadCib:self];
204 [_window setWindowController:nil];
208 [_window setWindowController:self];
209 [_window setNextResponder:self];
215 - (void)windowDidLoad
222 - (void)windowWillLoad
232 if (_document === aDocument)
239 if (![
self supportsMultipleDocuments])
242 [defaultCenter removeObserver:self
243 name:CPDocumentWillSaveNotification
246 [defaultCenter removeObserver:self
247 name:CPDocumentDidSaveNotification
250 [defaultCenter removeObserver:self
251 name:CPDocumentDidFailToSaveNotification
255 _document = aDocument;
261 [defaultCenter addObserver:self
262 selector:@selector(_documentWillSave:)
263 name:CPDocumentWillSaveNotification
266 [defaultCenter addObserver:self
267 selector:@selector(_documentDidSave:)
268 name:CPDocumentDidSaveNotification
271 [defaultCenter addObserver:self
272 selector:@selector(_documentDidFailToSave:)
273 name:CPDocumentDidFailToSaveNotification
279 var viewController = [_document viewControllerForWindowController:self];
291 - (void)setSupportsMultipleDocuments:(BOOL)shouldSupportMultipleDocuments
293 _supportsMultipleDocuments = shouldSupportMultipleDocuments;
296 - (BOOL)supportsMultipleDocuments
298 return _supportsMultipleDocuments;
303 if (aDocument && ![_documents containsObject:aDocument])
304 [_documents addObject:aDocument];
309 var index = [_documents indexOfObjectIdenticalTo:aDocument];
314 [_documents removeObjectAtIndex:index];
316 if (_document === aDocument && [_documents count])
317 [
self setDocument:[_documents objectAtIndex:MIN(index, [_documents count] - 1)]];
320 - (void)removeDocumentAndCloseIfNecessary:(
CPDocument)aDocument
324 if (![_documents count])
333 - (void)setViewControllerContainerView:(
CPView)aView
335 if (!_viewControllerContainerView && !aView)
344 [aView
setFrame:[contentView frame]];
347 if (viewControllerView)
349 [viewControllerView removeFromSuperview];
355 else if (viewControllerView)
357 [viewControllerView removeFromSuperview];
358 [viewControllerView setFrame:[contentView frame]];
359 [viewControllerView setAutoresizingMask:[contentView autoresizingMask]];
364 var view = [[
CPView alloc] init];
365 [view setFrame:[contentView frame]];
366 [view setAutoresizingMask:[contentView autoresizingMask]];
370 _viewControllerContainerView = aView;
373 - (void)viewControllerContainerView
375 return _viewControllerContainerView;
380 if (!_viewController && !aViewController)
388 var oldView = [_viewController isViewLoaded] ? [_viewController view] : nil;
392 [newView setFrame:[oldView frame]];
393 [newView setAutoresizingMask:[oldView autoresizingMask]];
396 if (oldView && newView)
397 [containerView replaceSubview:oldView with:newView];
399 [oldView removeFromSuperview];
401 [containerView addSubview:newView];
406 [newView setFrame:[contentView frame]];
407 [newView setAutoresizingMask:[contentView autoresizingMask]];
412 var view = [[
CPView alloc] init],
415 [view setFrame:[contentView frame]];
416 [view setAutoresizingMask:[contentView autoresizingMask]];
420 _viewController = aViewController;
425 return _viewController;
431 [[
self window] setDocumentSaving:YES];
437 [[
self window] setDocumentSaving:NO];
443 [[
self window] setDocumentSaving:NO];
458 - (void)setDocumentEdited:(BOOL)isEdited
468 - (void)setShouldCloseDocument:(BOOL)shouldCloseDocument
470 _shouldCloseDocument = shouldCloseDocument;
473 - (BOOL)shouldCloseDocument
475 return _shouldCloseDocument;
486 return _windowCibName;
488 return [[_windowCibPath lastPathComponent] stringByDeletingPathExtension];
494 return _windowCibPath;
504 - (void)synchronizeWindowTitleWithDocumentName
506 if (!_document || !_window)
Used to implement exception handling (creating & raising).
void addSubview:(CPView aSubview)
id initWithWindow:(CPWindow aWindow)
CPString windowTitleForDocumentDisplayName:(CPString aDisplayName)
void setShouldCloseDocument:(BOOL shouldCloseDocument)
void setFrame:(CGRect aFrame)
void setDocument:(CPDocument aDocument)
void raise:reason:(CPString aName, [reason] CPString aReason)
CPNotificationCenter defaultCenter()
void synchronizeWindowTitleWithDocumentName()
void addDocument:(CPDocument aDocument)
CPViewController viewController()
void setViewController:(CPViewController aViewController)
CPString pathForResource:(CPString aFilename)
An immutable string (collection of characters).
id initWithWindowCibName:owner:(CPString aWindowCibName, [owner] id anOwner)
CPCib loadCibFile:externalNameTable:(CPString anAbsolutePath, [externalNameTable] CPDictionary aNameTable)
CPDocumentDidFailToSaveNotification
void setAutoresizingMask:(unsigned aMask)
CPDocumentDidSaveNotification
void setWindow:(CPWindow aWindow)
A notification that can be posted to a CPNotificationCenter.
void setDocumentEdited:(BOOL isEdited)
Sends messages (CPNotification) between objects.
CPDocumentWillSaveNotification
void setNextResponder:(CPResponder aResponder)
void viewControllerContainerView()
void removeDocument:(CPDocument aDocument)
void setDocumentEdited:(BOOL isDocumentEdited)
void setContentView:(CPView aView)
id stringWithFormat:(CPString format, [,] ...)