diff --git a/ChangeLog b/ChangeLog index e6cea9e..e4e9763 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-05-19 17:13-EDT Gregory John Casamento + + * Framework/PCEditorManager.m: Added code in -openEditorForFile: + editable:windowed: to open files which are not handled by any editor + using [NSWorkspace openFile:] as a fallback. + 2009-05-18 17:27-EDT Gregory John Casamento * Framework/PCProject.m: Add new project directory name. diff --git a/Framework/PCEditorManager.m b/Framework/PCEditorManager.m index fd10a5f..0655079 100644 --- a/Framework/PCEditorManager.m +++ b/Framework/PCEditorManager.m @@ -167,9 +167,10 @@ NSString *PCEditorDidResignActiveNotification = NSString *fileName = [filePath lastPathComponent]; id editor; id parser; + BOOL exists = [fm fileExistsAtPath:filePath isDirectory:&isDir]; // Determine if file not exist or file is directory - if (![fm fileExistsAtPath:filePath isDirectory:&isDir] || isDir) + if (!exists) { NSRunAlertPanel(@"Open Editor", @"Couldn't open editor for file '%@'.\n" @@ -179,52 +180,68 @@ NSString *PCEditorDidResignActiveNotification = } // Determine if file is text file - if (![[PCFileManager defaultManager] isTextFile:filePath]) + if(isDir == NO) { - // TODO: Do not open alert panel for now. Internal editor - // for non text files must not be opened. Review PCProjectBrowser. -/* NSRunAlertPanel(@"Open Editor", - @"Couldn't open editor for file '%@'.\n" - @"File is not plain text.", - @"Close", nil, nil, filePath);*/ - return nil; + if (![[PCFileManager defaultManager] isTextFile:filePath] && !isDir) + { + // TODO: Do not open alert panel for now. Internal editor + // for non text files must not be opened. Review PCProjectBrowser. + /* NSRunAlertPanel(@"Open Editor", + @"Couldn't open editor for file '%@'.\n" + @"File is not plain text.", + @"Close", nil, nil, filePath);*/ + return nil; + } } // NSLog(@"EditorManager 1: %@", _editorsDict); - editor = [_editorsDict objectForKey:filePath]; + editor = [_editorsDict objectForKey: filePath]; if (editor == nil) { NSLog(@"Opening new editor. Editor: %@", editorName); // Editor editor = [bundleManager objectForBundleWithName:editorName - type:@"editor" - protocol:@protocol(CodeEditor)]; + type:@"editor" + protocol:@protocol(CodeEditor)]; if (editor == nil) { editor = [bundleManager - objectForBundleWithName:@"ProjectCenter" - type:@"editor" - protocol:@protocol(CodeEditor)]; + objectForBundleWithName:@"ProjectCenter" + type:@"editor" + protocol:@protocol(CodeEditor)]; if (editor == nil) { return nil; } } - + // Parser parser = [bundleManager objectForBundleType:@"parser" - protocol:@protocol(CodeParser) - fileName:fileName]; - [editor setParser:parser]; - [editor openFileAtPath:filePath - editorManager:self - editable:editable]; - - [_editorsDict setObject:editor forKey:filePath]; - RELEASE(editor); + protocol:@protocol(CodeParser) + fileName:fileName]; + if(parser != nil) + { + [editor setParser:parser]; + [editor openFileAtPath:filePath + editorManager:self + editable:editable]; + [_editorsDict setObject:editor forKey:filePath]; + RELEASE(editor); + } + else + { + // + // If we don't have an editor or a parser, we fall back to opening the + // file with the editor designated by the system. + // + [[NSWorkspace sharedWorkspace] openFile: filePath]; + } + } + + if(editor != nil) + { + [editor setWindowed:windowed]; } - - [editor setWindowed:windowed]; return editor; }