mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:10:47 +00:00
Document-base app fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14904 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
00c2564afb
commit
73445405a5
5 changed files with 90 additions and 27 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2002-11-01 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Source/NSApplication.m (-finishLaunching): Instantiate an
|
||||
NSDocumentController if this is a doc-based app.
|
||||
(-targetForAction:): Check if NSDocumentController responds
|
||||
to action if this is a doc-based app.
|
||||
|
||||
* Source/NSDocument.m (-close): Rewrite to deal with removing
|
||||
objects from array while enumerating.
|
||||
* Source/NSDocumentController.m (-closeAllDocuments): Idem.
|
||||
(-sharedDocumentController): Don't set ourselves as the app delegate.
|
||||
(-isDocumentBasedApplication): Method for NSApplication.
|
||||
|
||||
* Source/NSWindow.m (-sendEvent:): Retain _lastView
|
||||
just in case it's a temporary view.
|
||||
|
||||
2002-10-31 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Source/NSBundleAdditions.m:
|
||||
|
|
|
@ -215,7 +215,7 @@ initialize_gnustep_backend(void)
|
|||
/* GSBackend will be in a separate library, so use the runtime
|
||||
to find the class and avoid an unresolved reference problem */
|
||||
backend = [[NSBundle gnustepBundle] classNamed: @"GSBackend"];
|
||||
NSCAssert (backend, _(@"Can't find backend context");
|
||||
NSCAssert (backend, _(@"Can't find backend context"));
|
||||
[backend initializeBackend];
|
||||
#endif
|
||||
}
|
||||
|
@ -232,6 +232,10 @@ struct _NSModalSession {
|
|||
NSModalSession previous;
|
||||
};
|
||||
|
||||
@interface NSDocumentController (ApplicationPrivate)
|
||||
+ (BOOL) isDocumentBasedApplication;
|
||||
@end
|
||||
|
||||
@interface NSApplication (Private)
|
||||
- _appIconInit;
|
||||
- (void) _openDocument: (NSString*)name;
|
||||
|
@ -760,6 +764,10 @@ static NSCell* tileCell = nil;
|
|||
|
||||
[self activateIgnoringOtherApps: YES];
|
||||
|
||||
/* Instantiate the NSDocumentController if we are a doc-based app */
|
||||
if ([NSDocumentController isDocumentBasedApplication])
|
||||
[NSDocumentController sharedDocumentController];
|
||||
|
||||
/*
|
||||
* Now check to see if we were launched with arguments asking to
|
||||
* open a file. We permit some variations on the default name.
|
||||
|
@ -1608,6 +1616,13 @@ delegate.
|
|||
{
|
||||
return _delegate;
|
||||
}
|
||||
if ([NSDocumentController isDocumentBasedApplication]
|
||||
&& [[NSDocumentController sharedDocumentController]
|
||||
respondsToSelector: aSelector])
|
||||
{
|
||||
return [NSDocumentController sharedDocumentController];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
|
|
@ -730,11 +730,29 @@
|
|||
}
|
||||
}
|
||||
|
||||
/** Closes all the windows owned by the document, then removes itself
|
||||
from the list of documents known by the NSDocumentController. This
|
||||
method does not ask the user if they want to save the document before
|
||||
closing. It is closed without saving any information.
|
||||
*/
|
||||
- (void)close
|
||||
{
|
||||
// We have an _docFlags.inClose flag, but I don't think we need to use it.
|
||||
[_windowControllers makeObjectsPerformSelector:@selector(close)];
|
||||
if (_docFlags.inClose == NO)
|
||||
{
|
||||
int count = [_windowControllers count];
|
||||
/* Closing a windowController will also send us a close, so make
|
||||
sure we don't go recursive */
|
||||
_docFlags.inClose = YES;
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
NSWindowController *array[count];
|
||||
[_windowControllers getObjects: array];
|
||||
while (count-- > 0)
|
||||
[array[count] close];
|
||||
}
|
||||
[[NSDocumentController sharedDocumentController] removeDocument:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowControllerWillLoadNib:(NSWindowController *)windowController {}
|
||||
|
|
|
@ -70,11 +70,16 @@ static NSDictionary *TypeInfoForName (NSArray *types, NSString *typeName)
|
|||
|
||||
/** <p>
|
||||
NSDocumentController is a class that controls a set of NSDocuments
|
||||
for an application. As the application delegate, it responds to
|
||||
the typical File Menu commands for opening and creating new
|
||||
documents, and making sure all documents have been saved when an
|
||||
application quits. It also registers itself for the
|
||||
NSWorkspaceWillPowerOffNotification.
|
||||
for an application. As an application delegate, it responds to the
|
||||
typical File Menu commands for opening and creating new documents,
|
||||
and making sure all documents have been saved when an application
|
||||
quits. It also registers itself for the
|
||||
NSWorkspaceWillPowerOffNotification. Note that
|
||||
NSDocumentController isn't truly the application delegate, but it
|
||||
works in a similar way. You can still have your own application
|
||||
delegate - but beware, if it responds to the same methods as
|
||||
NSDocumentController, your delegate methods will get called, not
|
||||
the NSDocumentController's.
|
||||
</p>
|
||||
<p>
|
||||
NSDocumentController also manages document types and the related
|
||||
|
@ -91,14 +96,14 @@ static NSDictionary *TypeInfoForName (NSArray *types, NSString *typeName)
|
|||
<item>NSUnixExtensions - Array of strings</item>
|
||||
<item>NSDOSExtensions - Array of strings</item>
|
||||
<item>NSIcon - Icon name for these documents</item>
|
||||
<item>NSRole - Class is a Viewer or Editor</item>
|
||||
<item>NSRole - Viewer or Editor</item>
|
||||
</list>
|
||||
<p>
|
||||
You can also use NSDocumentController to get a list of all open
|
||||
You can use NSDocumentController to get a list of all open
|
||||
documents, the current document (The one whose window is Key) and
|
||||
other information about these documents. It also remebers the most
|
||||
recently opened documents (through the user default key
|
||||
_GSRecentDocuments). .
|
||||
NSRecentDocuments). .
|
||||
</p>
|
||||
<p>
|
||||
You can subclass NSDocumentController to customize the behavior of
|
||||
|
@ -115,15 +120,20 @@ static NSDictionary *TypeInfoForName (NSArray *types, NSString *typeName)
|
|||
if (sharedController == nil)
|
||||
{
|
||||
sharedController = [[self alloc] init];
|
||||
/* Need to verify this is the correct behavior. Set ourselves as
|
||||
the app delegate if there isn't one already */
|
||||
if ([NSApp delegate] == nil)
|
||||
[NSApp setDelegate: self];
|
||||
}
|
||||
|
||||
return sharedController;
|
||||
}
|
||||
|
||||
/* Private method for use by NSApplication to determine if it should
|
||||
instantiate an NSDocumentController.
|
||||
*/
|
||||
+ (BOOL) isDocumentBasedApplication
|
||||
{
|
||||
return ([[[NSBundle mainBundle] infoDictionary] objectForKey: NSTypesKey])
|
||||
? YES : NO;
|
||||
}
|
||||
|
||||
/** </init>Initializes the document controller class. The first
|
||||
instance of a document controller class that gets initialized
|
||||
becomes the shared instance.
|
||||
|
@ -422,17 +432,21 @@ static NSDictionary *TypeInfoForName (NSArray *types, NSString *typeName)
|
|||
*/
|
||||
- (BOOL) closeAllDocuments
|
||||
{
|
||||
NSDocument *document;
|
||||
NSEnumerator *docEnum = [_documents objectEnumerator];
|
||||
|
||||
while ((document = [docEnum nextObject]))
|
||||
int count;
|
||||
count = [_documents count];
|
||||
if (count > 0)
|
||||
{
|
||||
NSDocument *array[count];
|
||||
[_documents getObjects: array];
|
||||
while (count-- > 0)
|
||||
{
|
||||
NSDocument *document = array[count];
|
||||
if (![document canCloseDocument])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
[document close];
|
||||
[self removeDocument: document];
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
|
|
|
@ -2822,7 +2822,7 @@ Code shared with [NSPanel -sendEvent:], remember to update both places.
|
|||
}
|
||||
|
||||
case NSLeftMouseUp:
|
||||
v = _lastView;
|
||||
v = AUTORELEASE(RETAIN(_lastView));
|
||||
DESTROY(_lastView);
|
||||
if (v == nil)
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue