mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 21:00: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>
|
2002-10-31 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||||
|
|
||||||
* Source/NSBundleAdditions.m:
|
* Source/NSBundleAdditions.m:
|
||||||
|
|
|
@ -202,7 +202,7 @@ initialize_gnustep_backend(void)
|
||||||
NSCAssert1 ([theBundle load],
|
NSCAssert1 ([theBundle load],
|
||||||
_(@"Can't load object file from backend at path %@"),
|
_(@"Can't load object file from backend at path %@"),
|
||||||
path);
|
path);
|
||||||
|
|
||||||
/* Now get the GSBackend class, which should have just been loaded
|
/* Now get the GSBackend class, which should have just been loaded
|
||||||
* from the bundle. */
|
* from the bundle. */
|
||||||
backend = NSClassFromString (@"GSBackend");
|
backend = NSClassFromString (@"GSBackend");
|
||||||
|
@ -215,7 +215,7 @@ initialize_gnustep_backend(void)
|
||||||
/* GSBackend will be in a separate library, so use the runtime
|
/* GSBackend will be in a separate library, so use the runtime
|
||||||
to find the class and avoid an unresolved reference problem */
|
to find the class and avoid an unresolved reference problem */
|
||||||
backend = [[NSBundle gnustepBundle] classNamed: @"GSBackend"];
|
backend = [[NSBundle gnustepBundle] classNamed: @"GSBackend"];
|
||||||
NSCAssert (backend, _(@"Can't find backend context");
|
NSCAssert (backend, _(@"Can't find backend context"));
|
||||||
[backend initializeBackend];
|
[backend initializeBackend];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -231,6 +231,10 @@ struct _NSModalSession {
|
||||||
NSWindow *window;
|
NSWindow *window;
|
||||||
NSModalSession previous;
|
NSModalSession previous;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@interface NSDocumentController (ApplicationPrivate)
|
||||||
|
+ (BOOL) isDocumentBasedApplication;
|
||||||
|
@end
|
||||||
|
|
||||||
@interface NSApplication (Private)
|
@interface NSApplication (Private)
|
||||||
- _appIconInit;
|
- _appIconInit;
|
||||||
|
@ -760,6 +764,10 @@ static NSCell* tileCell = nil;
|
||||||
|
|
||||||
[self activateIgnoringOtherApps: YES];
|
[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
|
* Now check to see if we were launched with arguments asking to
|
||||||
* open a file. We permit some variations on the default name.
|
* open a file. We permit some variations on the default name.
|
||||||
|
@ -1608,6 +1616,13 @@ delegate.
|
||||||
{
|
{
|
||||||
return _delegate;
|
return _delegate;
|
||||||
}
|
}
|
||||||
|
if ([NSDocumentController isDocumentBasedApplication]
|
||||||
|
&& [[NSDocumentController sharedDocumentController]
|
||||||
|
respondsToSelector: aSelector])
|
||||||
|
{
|
||||||
|
return [NSDocumentController sharedDocumentController];
|
||||||
|
}
|
||||||
|
|
||||||
return nil;
|
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
|
- (void)close
|
||||||
{
|
{
|
||||||
// We have an _docFlags.inClose flag, but I don't think we need to use it.
|
if (_docFlags.inClose == NO)
|
||||||
[_windowControllers makeObjectsPerformSelector:@selector(close)];
|
{
|
||||||
[[NSDocumentController sharedDocumentController] removeDocument:self];
|
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 {}
|
- (void)windowControllerWillLoadNib:(NSWindowController *)windowController {}
|
||||||
|
|
|
@ -70,11 +70,16 @@ static NSDictionary *TypeInfoForName (NSArray *types, NSString *typeName)
|
||||||
|
|
||||||
/** <p>
|
/** <p>
|
||||||
NSDocumentController is a class that controls a set of NSDocuments
|
NSDocumentController is a class that controls a set of NSDocuments
|
||||||
for an application. As the application delegate, it responds to
|
for an application. As an application delegate, it responds to the
|
||||||
the typical File Menu commands for opening and creating new
|
typical File Menu commands for opening and creating new documents,
|
||||||
documents, and making sure all documents have been saved when an
|
and making sure all documents have been saved when an application
|
||||||
application quits. It also registers itself for the
|
quits. It also registers itself for the
|
||||||
NSWorkspaceWillPowerOffNotification.
|
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>
|
||||||
<p>
|
<p>
|
||||||
NSDocumentController also manages document types and the related
|
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>NSUnixExtensions - Array of strings</item>
|
||||||
<item>NSDOSExtensions - Array of strings</item>
|
<item>NSDOSExtensions - Array of strings</item>
|
||||||
<item>NSIcon - Icon name for these documents</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>
|
</list>
|
||||||
<p>
|
<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
|
documents, the current document (The one whose window is Key) and
|
||||||
other information about these documents. It also remebers the most
|
other information about these documents. It also remebers the most
|
||||||
recently opened documents (through the user default key
|
recently opened documents (through the user default key
|
||||||
_GSRecentDocuments). .
|
NSRecentDocuments). .
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
You can subclass NSDocumentController to customize the behavior of
|
You can subclass NSDocumentController to customize the behavior of
|
||||||
|
@ -115,15 +120,20 @@ static NSDictionary *TypeInfoForName (NSArray *types, NSString *typeName)
|
||||||
if (sharedController == nil)
|
if (sharedController == nil)
|
||||||
{
|
{
|
||||||
sharedController = [[self alloc] init];
|
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;
|
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
|
/** </init>Initializes the document controller class. The first
|
||||||
instance of a document controller class that gets initialized
|
instance of a document controller class that gets initialized
|
||||||
becomes the shared instance.
|
becomes the shared instance.
|
||||||
|
@ -422,19 +432,23 @@ static NSDictionary *TypeInfoForName (NSArray *types, NSString *typeName)
|
||||||
*/
|
*/
|
||||||
- (BOOL) closeAllDocuments
|
- (BOOL) closeAllDocuments
|
||||||
{
|
{
|
||||||
NSDocument *document;
|
int count;
|
||||||
NSEnumerator *docEnum = [_documents objectEnumerator];
|
count = [_documents count];
|
||||||
|
if (count > 0)
|
||||||
while ((document = [docEnum nextObject]))
|
|
||||||
{
|
{
|
||||||
if (![document canCloseDocument])
|
NSDocument *array[count];
|
||||||
|
[_documents getObjects: array];
|
||||||
|
while (count-- > 0)
|
||||||
{
|
{
|
||||||
return NO;
|
NSDocument *document = array[count];
|
||||||
|
if (![document canCloseDocument])
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
[document close];
|
||||||
}
|
}
|
||||||
[document close];
|
|
||||||
[self removeDocument: document];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2822,7 +2822,7 @@ Code shared with [NSPanel -sendEvent:], remember to update both places.
|
||||||
}
|
}
|
||||||
|
|
||||||
case NSLeftMouseUp:
|
case NSLeftMouseUp:
|
||||||
v = _lastView;
|
v = AUTORELEASE(RETAIN(_lastView));
|
||||||
DESTROY(_lastView);
|
DESTROY(_lastView);
|
||||||
if (v == nil)
|
if (v == nil)
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue