Reindented to conform to standards

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10289 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 2001-07-04 17:20:49 +00:00
parent eeefe3d6ed
commit dd921c06dc

View file

@ -56,8 +56,10 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
NSDictionary *dict = [types objectAtIndex: i]; NSDictionary *dict = [types objectAtIndex: i];
if ([[dict objectForKey: NSNameKey] isEqualToString: typeName]) if ([[dict objectForKey: NSNameKey] isEqualToString: typeName])
{
return dict; return dict;
} }
}
return nil; return nil;
} }
@ -83,7 +85,9 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
static id instance = nil; static id instance = nil;
if (instance == nil) if (instance == nil)
{
instance = [[super allocWithZone:NULL] init]; instance = [[super allocWithZone:NULL] init];
}
return instance; return instance;
} }
@ -132,22 +136,27 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
return AUTORELEASE ([[documentClass alloc] init]); return AUTORELEASE ([[documentClass alloc] init]);
} }
- (id)makeDocumentWithContentsOfFile:(NSString *)fileName ofType:(NSString *)type - (id) makeDocumentWithContentsOfFile: (NSString *)fileName
ofType: (NSString *)type
{ {
Class documentClass = [self documentClassForType:type]; Class documentClass = [self documentClassForType:type];
return AUTORELEASE([[documentClass alloc] initWithContentsOfFile:fileName ofType:type]); return AUTORELEASE ([[documentClass alloc] initWithContentsOfFile: fileName
ofType: type]);
} }
- (id) makeDocumentWithContentsOfURL: (NSURL *)url ofType: (NSString *)type - (id) makeDocumentWithContentsOfURL: (NSURL *)url ofType: (NSString *)type
{ {
Class documentClass = [self documentClassForType: type]; Class documentClass = [self documentClassForType: type];
return AUTORELEASE([[documentClass alloc] initWithContentsOfURL:url ofType:type]); return AUTORELEASE ([[documentClass alloc] initWithContentsOfURL: url
ofType: type]);
} }
- _defaultType - _defaultType
{ {
if ([_types count] == 0) if ([_types count] == 0)
{
return nil; // raise exception? return nil; // raise exception?
}
return [[_types objectAtIndex:0] objectForKey:NSNameKey]; return [[_types objectAtIndex:0] objectForKey:NSNameKey];
} }
@ -167,20 +176,25 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
NSDocument *document = [self makeUntitledDocumentOfType: type]; NSDocument *document = [self makeUntitledDocumentOfType: type];
if (document == nil) if (document == nil)
{
return nil; return nil;
}
[self addDocument: document]; [self addDocument: document];
if ([self shouldCreateUI]) if ([self shouldCreateUI])
{ {
[document makeWindowControllers]; [document makeWindowControllers];
if (display) if (display)
{
[document showWindows]; [document showWindows];
} }
}
return document; return document;
} }
- (id)openDocumentWithContentsOfFile:(NSString *)fileName display:(BOOL)display - (id) openDocumentWithContentsOfFile: (NSString *)fileName
display: (BOOL)display
{ {
NSDocument *document = [self documentForFileName: fileName]; NSDocument *document = [self documentForFileName: fileName];
@ -188,12 +202,17 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
{ {
NSString *type = [self typeFromFileExtension: [fileName pathExtension]]; NSString *type = [self typeFromFileExtension: [fileName pathExtension]];
if ((document = [self makeDocumentWithContentsOfFile:fileName ofType:type])) if ((document = [self makeDocumentWithContentsOfFile: fileName
ofType: type]))
{
[self addDocument: document]; [self addDocument: document];
}
if ([self shouldCreateUI]) if ([self shouldCreateUI])
{
[document makeWindowControllers]; [document makeWindowControllers];
} }
}
if (display && [self shouldCreateUI]) if (display && [self shouldCreateUI])
{ {
@ -213,12 +232,15 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
if (document == nil) if (document == nil)
{ {
NSString *type = [self typeFromFileExtension:[[url path] pathExtension]]; NSString *type = [self typeFromFileExtension:
[[url path] pathExtension]];
document = [self makeDocumentWithContentsOfURL: url ofType: type]; document = [self makeDocumentWithContentsOfURL: url ofType: type];
if (document == nil) if (document == nil)
{
return nil; return nil;
}
[self addDocument: document]; [self addDocument: document];
@ -236,7 +258,7 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
return document; return document;
} }
- _setupOpenPanel - (NSOpenPanel *) _setupOpenPanel
{ {
NSOpenPanel *openPanel = [NSOpenPanel openPanel]; NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setDirectory: [self currentDirectory]]; [openPanel setDirectory: [self currentDirectory]];
@ -244,7 +266,8 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
return openPanel; return openPanel;
} }
- (int)runModalOpenPanel:(NSOpenPanel *)openPanel forTypes:(NSArray *)openableFileExtensions - (int) runModalOpenPanel: (NSOpenPanel *)openPanel
forTypes: (NSArray *)openableFileExtensions
{ {
return [openPanel runModalForTypes:openableFileExtensions]; return [openPanel runModalForTypes:openableFileExtensions];
} }
@ -308,9 +331,11 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
- (IBAction) openDocument: (id)sender - (IBAction) openDocument: (id)sender
{ {
NSEnumerator *fileEnum = [[self fileNamesFromRunningOpenPanel] objectEnumerator]; NSEnumerator *fileEnum;
NSString *filename; NSString *filename;
fileEnum = [[self fileNamesFromRunningOpenPanel] objectEnumerator];
while ((filename = [fileEnum nextObject])) while ((filename = [fileEnum nextObject]))
{ {
[self openDocumentWithContentsOfFile: filename display: YES]; [self openDocumentWithContentsOfFile: filename display: YES];
@ -330,7 +355,10 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
while ((document = [docEnum nextObject])) while ((document = [docEnum nextObject]))
{ {
if (![document canCloseDocument]) return NO; if (![document canCloseDocument])
{
return NO;
}
[document close]; [document close];
[self removeDocument: document]; [self removeDocument: document];
} }
@ -338,13 +366,17 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
return YES; return YES;
} }
- (BOOL)reviewUnsavedDocumentsWithAlertTitle:(NSString *)title cancellable:(BOOL)cancellable - (BOOL) reviewUnsavedDocumentsWithAlertTitle: (NSString *)title
cancellable: (BOOL)cancellable
{ {
//FIXME -- localize. //FIXME -- localize.
NSString *cancelString = (cancellable)? @"Cancel" : nil; NSString *cancelString = (cancellable)? @"Cancel" : nil;
int result; int result;
if (![self hasEditedDocuments]) return YES; if (![self hasEditedDocuments])
{
return YES;
}
result = NSRunAlertPanel(title, @"You have unsaved documents.", result = NSRunAlertPanel(title, @"You have unsaved documents.",
@"Review Unsaved", cancelString, @"Quit Anyways"); @"Review Unsaved", cancelString, @"Quit Anyways");
@ -373,24 +405,28 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
return [self openDocumentWithContentsOfFile:filename display:YES] ? YES : NO; return [self openDocumentWithContentsOfFile:filename display:YES] ? YES : NO;
} }
- (BOOL)application:(NSApplication *)sender openTempFile:(NSString *)filename; - (BOOL) application:(NSApplication *)sender
openTempFile: (NSString *)filename;
{ {
return [self openDocumentWithContentsOfFile:filename display:YES] ? YES : NO; return [self openDocumentWithContentsOfFile:filename display:YES] ? YES : NO;
} }
- (BOOL) applicationOpenUntitledFile: (NSApplication *)sender - (BOOL) applicationOpenUntitledFile: (NSApplication *)sender
{ {
return [self openUntitledDocumentOfType:[self _defaultType] display:YES] ? YES : NO; return [self openUntitledDocumentOfType: [self _defaultType]
display: YES] ? YES : NO;
} }
- (BOOL) application:(id)sender openFileWithoutUI:(NSString *)filename - (BOOL) application:(id)sender openFileWithoutUI:(NSString *)filename
{ {
return [self openDocumentWithContentsOfFile:filename display:NO] ? YES : NO; return [self openDocumentWithContentsOfFile: filename display: NO] ?
YES : NO;
} }
- (BOOL) applicationShouldTerminate: (NSApplication *)sender - (BOOL) applicationShouldTerminate: (NSApplication *)sender
{ {
return [self reviewUnsavedDocumentsWithAlertTitle:@"Quit" cancellable:YES]; return [self reviewUnsavedDocumentsWithAlertTitle: @"Quit"
cancellable: YES];
} }
#endif #endif
@ -413,15 +449,18 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
if ([[_documents objectAtIndex: i] isDocumentEdited]) if ([[_documents objectAtIndex: i] isDocumentEdited])
{
return YES; return YES;
} }
}
return NO; return NO;
} }
- (id) currentDocument - (id) currentDocument
{ {
return [self documentForWindow:[[NSApplication sharedApplication] mainWindow]]; return [self documentForWindow:
[[NSApplication sharedApplication] mainWindow]];
} }
- (NSString *) currentDirectory - (NSString *) currentDirectory
@ -433,7 +472,9 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
if (directory && if (directory &&
[manager fileExistsAtPath: directory isDirectory: &isDir] && isDir) [manager fileExistsAtPath: directory isDirectory: &isDir] && isDir)
{
return directory; return directory;
}
//FIXME -- need to remember last saved directory, and return that here. //FIXME -- need to remember last saved directory, and return that here.
//Only return NSHomeDirectory if nothing's been saved yet. //Only return NSHomeDirectory if nothing's been saved yet.
@ -445,15 +486,21 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
id document; id document;
if (window == nil) if (window == nil)
{
return nil; return nil;
}
if (![[window windowController] isKindOfClass: [NSWindowController class]]) if (![[window windowController] isKindOfClass: [NSWindowController class]])
{
return nil; return nil;
}
document = [[window windowController] document]; document = [[window windowController] document];
if (![document isKindOfClass:[NSDocument class]]) if (![document isKindOfClass:[NSDocument class]])
{
return nil; return nil;
}
return document; return document;
} }
@ -467,8 +514,10 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
NSDocument *document = [_documents objectAtIndex: i]; NSDocument *document = [_documents objectAtIndex: i];
if ([[document fileName] isEqualToString: fileName]) if ([[document fileName] isEqualToString: fileName])
{
return document; return document;
} }
}
return nil; return nil;
} }
@ -476,7 +525,9 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
- (BOOL) validateMenuItem: (NSMenuItem *)anItem - (BOOL) validateMenuItem: (NSMenuItem *)anItem
{ {
if ([anItem action] == @selector(saveAllDocuments:)) if ([anItem action] == @selector(saveAllDocuments:))
{
return [self hasEditedDocuments]; return [self hasEditedDocuments];
}
return YES; return YES;
} }
@ -495,8 +546,10 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
{ {
NSDictionary *typeInfo = [_types objectAtIndex: i]; NSDictionary *typeInfo = [_types objectAtIndex: i];
if ([[typeInfo objectForKey:NSUnixExtensionsKey] containsObject:fileExtension] || if ([[typeInfo objectForKey:NSUnixExtensionsKey]
[[typeInfo objectForKey:NSDOSExtensionsKey] containsObject:fileExtension]) containsObject: fileExtension] ||
[[typeInfo objectForKey:NSDOSExtensionsKey]
containsObject: fileExtension])
{ {
return [typeInfo objectForKey: NSNameKey]; return [typeInfo objectForKey: NSNameKey];
} }
@ -536,10 +589,14 @@ static NSDictionary *TypeInfoForName(NSArray *types, NSString *typeName)
unsigned index = [_recentDocuments indexOfObject: anURL]; unsigned index = [_recentDocuments indexOfObject: anURL];
if (index != NSNotFound) if (index != NSNotFound)
{
// Always keep the current object at the end of the list // Always keep the current object at the end of the list
[_recentDocuments removeObjectAtIndex: index]; [_recentDocuments removeObjectAtIndex: index];
}
else if ([_recentDocuments count] > MAX_DOCS) else if ([_recentDocuments count] > MAX_DOCS)
{
[_recentDocuments removeObjectAtIndex: 0]; [_recentDocuments removeObjectAtIndex: 0];
}
[_recentDocuments addObject: anURL]; [_recentDocuments addObject: anURL];
} }
@ -568,8 +625,10 @@ static NSString *NSNoRole = @"None";
NSString *className = [typeInfo objectForKey: NSDocumentClassKey]; NSString *className = [typeInfo objectForKey: NSDocumentClassKey];
NSString *role = [typeInfo objectForKey: NSRoleKey]; NSString *role = [typeInfo objectForKey: NSRoleKey];
if ([docClassName isEqualToString:className] && if ([docClassName isEqualToString: className]
(role == nil || [role isEqual:NSEditorRole] || [role isEqual:NSViewerRole])) && (role == nil
|| [role isEqual: NSEditorRole]
|| [role isEqual: NSViewerRole]))
{ {
[types addObject: [typeInfo objectForKey: NSNameKey]]; [types addObject: [typeInfo objectForKey: NSNameKey]];
} }