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