From 26dc666444d6ec6f5ce187b52e08615d15d234d8 Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Thu, 27 Sep 2007 00:03:51 +0000 Subject: [PATCH] * Framework/PCBundleManager.m, * Headers/ProjectCenter/PCBundleManager.h: Make massive cleaup. some methods changed, some deleted, some added. * Framework/PCProjectManager.m, * Framework/PCProjectEditor.m: Make use of changed PCBundleManager. * TextFinder.m: (-enterSelection:): Add sanity check for text variable. (-jumpToSelection:): Ditto. * Modules/Parsers/ProjectCenter/Resources/Info.table: Fix value of "Name" key. * Headers/Protocols/CodeEditor.h: Remove declaration of openExternalEditor:withPath:projectEditor: method. It will be provided by Custom.editor bundle (will be added soon). * Headers/ProjectCenter/PCProjectEditor.h: Cleanup. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@25504 72102866-910b-0410-8b05-ffd578937521 --- Documentation/ChangeLog | 17 ++ Framework/PCBundleManager.m | 207 +++++++++++++++--- Framework/PCProjectEditor.m | 117 ++-------- Framework/PCProjectManager.m | 38 ++-- Headers/ProjectCenter/PCBundleManager.h | 44 +++- Headers/ProjectCenter/PCProjectEditor.h | 6 - Headers/Protocols/CodeEditor.h | 4 - .../ProjectCenter/Resources/Info.table | 2 +- TextFinder.m | 40 +++- 9 files changed, 300 insertions(+), 175 deletions(-) diff --git a/Documentation/ChangeLog b/Documentation/ChangeLog index 8832027..a4ae632 100644 --- a/Documentation/ChangeLog +++ b/Documentation/ChangeLog @@ -1,5 +1,22 @@ 2007-09-24 Sergii Stoian + * Framework/PCBundleManager.m, + * Headers/ProjectCenter/PCBundleManager.h: Make massive cleaup. + some methods changed, some deleted, some added. + * Framework/PCProjectManager.m, + * Framework/PCProjectEditor.m: Make use of changed PCBundleManager. + * TextFinder.m: + (-enterSelection:): Add sanity check for text variable. + (-jumpToSelection:): Ditto. + * Modules/Parsers/ProjectCenter/Resources/Info.table: Fix value of + "Name" key. + * Headers/Protocols/CodeEditor.h: Remove declaration of + openExternalEditor:withPath:projectEditor: method. It will be provided + by Custom.editor bundle (will be added soon). + * Headers/ProjectCenter/PCProjectEditor.h: Cleanup. + +2007-09-24 Sergii Stoian + * English.lproj/FindPanel.gorm: Added Find panel. * PCMenuController.m: Added Find panel support. * TextFinder.[hm]: Added implementation of Find panel. diff --git a/Framework/PCBundleManager.m b/Framework/PCBundleManager.m index f646589..7347056 100644 --- a/Framework/PCBundleManager.m +++ b/Framework/PCBundleManager.m @@ -23,6 +23,14 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ +// TODO: Finish support for third party bundles. +// It involves support for user defined bundle directories +// through preferences. Now supported are: +// - PC application resource dir +// (GNUSTEP_SYSTEM_APPS/ProjectCenter.app/Resources) +// - GNUSTEP_SYSTEM_LIBRARY/Bundles/ProjectCenter +// (NSApplicationSupportDirectory) + #include #include @@ -68,11 +76,13 @@ return path; } -// +// --- Handling of bundles' Info.table dictionaries without actual +// --- bundles loading + // bundlesInfo is a dictionary. key/value pair is the following: +// (NSString *) (NSDictionary *) // "full path of a bundle" = "Info.table contents" -// propertyValueOfClass:withKey: -- (NSDictionary *)infoForBundlesOfType:(NSString *)extension +- (NSDictionary *)infoForBundlesType:(NSString *)extension { NSArray *bundles; NSEnumerator *enumerator; @@ -90,6 +100,8 @@ { infoTablePath = [NSString stringWithFormat:@"%@/Resources/Info.table", bundlePath]; + // TODO: fill 'reqBundlesInfo' with element from 'bundlesInfo' if + // exists infoTable = [NSDictionary dictionaryWithContentsOfFile:infoTablePath]; [reqBundlesInfo setObject:infoTable forKey:bundlePath]; [bundlesInfo setObject:infoTable forKey:bundlePath]; @@ -98,6 +110,95 @@ return reqBundlesInfo; } +// Key value can be checked against NSString and NSArray values only. +- (NSDictionary *)infoForBundleType:(NSString *)extension + keyName:(NSString *)key + keyContains:(NSString *)value +{ + NSDictionary *reqBundlesInfo; + NSEnumerator *enumerator; + NSString *bundlePath; + id keyValue; + NSDictionary *infoTable; + + if (extension == nil) + { + return nil; + } + + reqBundlesInfo = [self infoForBundlesType:extension]; + enumerator = [[reqBundlesInfo allKeys] objectEnumerator]; + + while ((bundlePath = [enumerator nextObject])) + { + infoTable = [reqBundlesInfo objectForKey:bundlePath]; + + if (key == nil || value == nil) + { + break; + } + + keyValue = [infoTable objectForKey:key]; + + if ([keyValue isKindOfClass:[NSString class]] && + [keyValue isEqualToString:value]) + { + break; + } + else if ([keyValue isKindOfClass:[NSArray class]] && + [keyValue containsObject:value]) + { + break; + } + else + { + infoTable = nil; + } + } + + return infoTable; +} + +- (NSDictionary *)infoForBundleName:(NSString *)name + type:(NSString *)type +{ + NSDictionary *reqBundlesInfo = [self infoForBundlesType:type]; + NSEnumerator *enumerator = [[reqBundlesInfo allKeys] objectEnumerator]; + NSString *bundlePath; + NSDictionary *infoTable; + + while ((bundlePath = [enumerator nextObject])) + { + infoTable = [reqBundlesInfo objectForKey:bundlePath]; + if ([[infoTable objectForKey:@"Name"] isEqualToString:name]) + { + break; + } + else + { + infoTable = nil; + } + } + + return infoTable; +} + +- (NSString *)classNameForBundleType:(NSString*)type + fileName:(NSString *)fileName +{ + NSString *fileExtension = [fileName pathExtension]; + NSDictionary *infoTable = nil; + NSString *className = nil; + + infoTable = [self infoForBundleType:type + keyName:@"FileTypes" + keyContains:fileExtension]; + + className = [infoTable objectForKey:@"PrincipalClassName"]; + + return className; +} + - (NSString *)bundlePathWithName:(NSString *)bundleName { NSArray *bundlePaths = nil; @@ -108,6 +209,9 @@ bundlePaths = [bundlesInfo allKeys]; enumerator = [bundlePaths objectEnumerator]; + NSLog(@"Bundle fullpath method #1: %@", + [[self resourcePath] stringByAppendingPathComponent:bundleName]); + while ((bundleFullPath = [enumerator nextObject])) { if ([[bundleFullPath lastPathComponent] isEqualToString:bundleName]) @@ -116,14 +220,73 @@ } } + NSLog(@"Bundle fullpath method #2: %@", bundleFullPath); + return bundleFullPath; } -- (NSBundle *)bundleOfType:(NSString *)type forClassName:(NSString *)className +// --- Invokes loading of bundle + +- (id)objectForClassName:(NSString *)className + bundleType:(NSString *)bundleExtension + protocol:(Protocol *)proto +{ + Class objectClass; + + if ([self bundleOfType:bundleExtension withClassName:className] == nil) + { + NSLog(@"Bundle for class %@ NOT FOUND!", className); + return nil; + } + + objectClass = NSClassFromString(className); + + if (proto != nil && ![objectClass conformsToProtocol:proto]) + { + [NSException raise:NOT_A_PROJECT_TYPE_EXCEPTION + format:@"%@ does not conform to protocol!", className]; + return nil; + } + + return [[objectClass alloc] init]; +} + +- (id)objectForBundleWithName:(NSString *)name + type:(NSString *)extension + protocol:(Protocol *)proto +{ + NSDictionary *infoTable; + NSString *className; + + infoTable = [self infoForBundleName:name type:extension]; + className = [infoTable objectForKey:@"PrincipalClassName"]; + + return [self objectForClassName:className + bundleType:extension + protocol:proto]; +} + +- (id)objectForBundleType:(NSString *)extension + protocol:(Protocol *)proto + fileName:(NSString *)fileName +{ + NSString *className; + + className = [self classNameForBundleType:extension fileName:fileName]; + + return [self objectForClassName:className + bundleType:extension + protocol:proto]; +} + +// --- Bundle loading + +- (NSBundle *)bundleOfType:(NSString *)type + withClassName:(NSString *)className { NSArray *bundlePaths = nil; - NSDictionary *infoTable = nil; NSString *bundleFullPath = nil; + NSDictionary *infoTable = nil; NSEnumerator *enumerator = nil; NSString *bundleName = nil; NSString *principalClass; @@ -158,35 +321,9 @@ return [loadedBundles objectForKey:bundleFullPath]; } -- (id)objectForClassName:(NSString *)className - withProtocol:(Protocol *)proto - inBundleType:(NSString *)type -{ - Class objectClass; - - if ([self bundleOfType:type forClassName:className] == nil) - { - NSLog(@"Bundle for class %@ NOT FOUND!", className); - return nil; - } - - objectClass = NSClassFromString(className); - - if (proto != nil && ![objectClass conformsToProtocol:proto]) - { - [NSException raise:NOT_A_PROJECT_TYPE_EXCEPTION - format:@"%@ does not conform to protocol!", className]; - return nil; - } - - return [[objectClass alloc] init]; -} - - (BOOL)loadBundleIfNeededWithName:(NSString *)bundleName { - NSString *bundleFullPath; - - bundleFullPath = [self bundlePathWithName:bundleName]; + NSString *bundleFullPath = [self bundlePathWithName:bundleName]; // Check if bundle allready loaded if ([[loadedBundles allKeys] containsObject:bundleFullPath] == NO) @@ -197,7 +334,6 @@ return YES; } -// --- - (void)loadBundlesWithExtension:(NSString *)extension { NSEnumerator *enumerator; @@ -216,10 +352,9 @@ objectEnumerator]; while ((path = [enumerator nextObject]) != nil) { - path = [path stringByAppendingPathComponent: @"ProjectCenter"]; + path = [path stringByAppendingPathComponent:@"ProjectCenter"]; - if ([fileManager fileExistsAtPath: path isDirectory: &isDir] - && isDir) + if ([fileManager fileExistsAtPath:path isDirectory:&isDir] && isDir) { PCLogInfo(self, @"Loading bundles at %@", path); [self loadBundlesAtPath:path withExtension:extension]; diff --git a/Framework/PCProjectEditor.m b/Framework/PCProjectEditor.m index ccd7e55..9a6e7a7 100644 --- a/Framework/PCProjectEditor.m +++ b/Framework/PCProjectEditor.m @@ -115,7 +115,6 @@ NSString *PCEditorDidResignActiveNotification = - (id)initWithProject:(PCProject *)aProject { - PCBundleManager *bundleManager; NSAssert(aProject, @"No project specified!"); if ((self = [super init])) @@ -125,15 +124,6 @@ NSString *PCEditorDidResignActiveNotification = componentView = nil; editorsDict = [[NSMutableDictionary alloc] init]; - // Bundles - bundleManager = [[project projectManager] bundleManager]; - - // Editor bundles - editorBundlesInfo = [[bundleManager infoForBundlesOfType:@"editor"] copy]; - - // Parser bundles - parserBundlesInfo = [[bundleManager infoForBundlesOfType:@"parser"] copy]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editorDidOpen:) @@ -182,8 +172,6 @@ NSString *PCEditorDidResignActiveNotification = RELEASE(componentView); } - RELEASE(editorBundlesInfo); - RELEASE(parserBundlesInfo); RELEASE(editorsDict); [super dealloc]; @@ -208,63 +196,12 @@ NSString *PCEditorDidResignActiveNotification = // ==== Project and Editor handling // =========================================================================== -- (NSDictionary *)infoTableForBundleType:(NSString *)type - andFileType:(NSString *)extension -{ - NSDictionary *bundlesInfo = nil; - NSEnumerator *enumerator = nil; - NSString *bundlePathKey = nil; - NSDictionary *infoTable = nil; - - if ([type isEqualToString:@"editor"]) - { - bundlesInfo = editorBundlesInfo; - } - else - { - bundlesInfo = parserBundlesInfo; - } - - enumerator = [[bundlesInfo allKeys] objectEnumerator]; - while ((bundlePathKey = [enumerator nextObject])) - { - infoTable = [bundlesInfo objectForKey:bundlePathKey]; - if ([[infoTable objectForKey:@"FileTypes"] containsObject:extension]) - { - break; - } - else - { - infoTable = nil; - } - } - - return infoTable; -} - -- (NSString *)classNameForBundleType:(NSString*)type - andFile:(NSString *)file -{ - NSString *fileExtension = [file pathExtension]; - NSDictionary *infoTable = nil; - NSString *className = nil; - - infoTable = [self infoTableForBundleType:type andFileType:fileExtension]; - className = [infoTable objectForKey:@"PrincipalClassName"]; - - if (className == nil && [type isEqualToString:@"editor"]) - { - className = [NSString stringWithString:@"PCEditor"]; - } - - return className; -} - // TODO: Should it be editor or parser? - (BOOL)editorProvidesBrowserItemsForItem:(NSString *)item { - NSString *file = [[project projectBrowser] nameOfSelectedFile]; - NSDictionary *infoTable = nil; + NSString *file = [[project projectBrowser] nameOfSelectedFile]; + PCBundleManager *bundleManager = [[project projectManager] bundleManager]; + NSDictionary *infoTable = nil; // File selected and editor should already be loaded if (file != nil) @@ -276,8 +213,9 @@ NSString *PCEditorDidResignActiveNotification = } // Category selected - infoTable = [self infoTableForBundleType:@"editor" - andFileType:[item pathExtension]]; + infoTable = [bundleManager infoForBundleType:@"editor" + keyName:@"FileTypes" + keyContains:[item pathExtension]]; if ([[infoTable objectForKey:@"ProvidesBrowserItems"] isEqualToString:@"YES"]) { @@ -381,48 +319,35 @@ NSString *PCEditorDidResignActiveNotification = editable:(BOOL)editable windowed:(BOOL)windowed { -// NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; -// NSString *ed = [ud objectForKey:Editor]; PCBundleManager *bundleManager = [[project projectManager] bundleManager]; - NSString *editorClassName = nil; - NSString *parserClassName = nil; + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + NSString *ed = [ud objectForKey:Editor]; + NSString *fileName = [path lastPathComponent]; id editor; id parser; NSLog(@"PCPE: categoryPath: \"%@\"", categoryPath); - // TODO: Include external editor code into editor bundle? -/* if (![ed isEqualToString:@"ProjectCenter"]) - { - [editor initExternalEditor:ed withPath:path projectEditor:self]; - return editor; - }*/ - if (!(editor = [editorsDict objectForKey:path])) { // Editor - editorClassName = [self classNameForBundleType:@"editor" - andFile:[path lastPathComponent]]; - editor = [bundleManager objectForClassName:editorClassName - withProtocol:@protocol(CodeEditor) - inBundleType:@"editor"]; - if (!editor) + editor = [bundleManager objectForBundleWithName:ed + type:@"editor" + protocol:@protocol(CodeEditor)]; + if (editor == nil) { + editor = [bundleManager + objectForBundleWithName:@"ProjectCenter" + type:@"editor" + protocol:@protocol(CodeEditor)]; return nil; } // Parser - parserClassName = [self classNameForBundleType:@"parser" - andFile:[path lastPathComponent]]; - if (parserClassName != nil) - { - NSLog(@"PCPE: parser: %@", parserClassName); - parser = [bundleManager objectForClassName:parserClassName - withProtocol:@protocol(CodeParser) - inBundleType:@"parser"]; - [editor setParser:parser]; - RELEASE(parser); - } + parser = [bundleManager objectForBundleType:@"parser" + protocol:@protocol(CodeParser) + fileName:fileName]; + [editor setParser:parser]; [editor openFileAtPath:path categoryPath:categoryPath diff --git a/Framework/PCProjectManager.m b/Framework/PCProjectManager.m index 270d816..453b9d0 100644 --- a/Framework/PCProjectManager.m +++ b/Framework/PCProjectManager.m @@ -178,7 +178,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; if (projectTypes == nil) { projectTypes = [[NSMutableDictionary alloc] init]; - bundlesInfo = [bundleManager infoForBundlesOfType:@"project"]; + bundlesInfo = [bundleManager infoForBundlesType:@"project"]; bundlePaths = [bundlesInfo allKeys]; enumerator = [bundlePaths objectEnumerator]; @@ -521,8 +521,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; stringByAppendingPathComponent:@"PC.project"]; project = [bundleManager objectForClassName:projectClassName - withProtocol:@protocol(ProjectType) - inBundleType:@"project"]; + bundleType:@"project" + protocol:@protocol(ProjectType)]; projectTypeName = [project projectTypeName]; [pDict setObject:projectTypeName forKey:PCProjectType]; @@ -565,8 +565,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; return nil; } project = [bundleManager objectForClassName:projectClassName - withProtocol:@protocol(ProjectType) - inBundleType:@"project"]; + bundleType:@"project" + protocol:@protocol(ProjectType)]; } if (![project openWithDictionaryAt:aPath]) @@ -652,8 +652,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; } projectCreator = [bundleManager objectForClassName:className - withProtocol:@protocol(ProjectType) - inBundleType:@"project"]; + bundleType:@"project" + protocol:@protocol(ProjectType)]; // NSLog(@"%@ CLASS: %@", className, projectCreator); if (!projectCreator) { @@ -1076,21 +1076,19 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; - (void)openFileWithEditor:(NSString *)path { -/* id editor; - NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; +// id editor; +/* NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; NSString *editor = [ud objectForKey:Editor]; - editor = [PCProjectEditor openFileInEditor:path]; - if (![editor isEqualToString:@"ProjectCenter"]) { NSArray *ea = [editor componentsSeparatedByString:@" "]; - NSString *app = [ea objectAtIndex: 0]; + NSString *app = [ea objectAtIndex:0]; if ([[app pathExtension] isEqualToString:@"app"]) { BOOL ret = [[NSWorkspace sharedWorkspace] openFile:path - withApplication:app]; + withApplication:app]; if (ret == NO) { @@ -1101,24 +1099,22 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; } editor = [[editorClass alloc] initExternalEditor:editor - withPath:path - projectEditor:self]; + withPath:path + projectEditor:self]; } else { id editor; editor = [[editorClass alloc] initWithPath:path - categoryPath:nil - projectEditor:self]; + categoryPath:nil + projectEditor:self]; [editor setWindowed:YES]; [editor show]; return editor; } - return nil; - [nonProjectEditors setObject:editor forKey:path]; [editor release];*/ @@ -1251,8 +1247,8 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; }*/ projectCreator = [bundleManager objectForClassName:className - withProtocol:@protocol(ProjectType) - inBundleType:@"project"]; + bundleType:@"project" + protocol:@protocol(ProjectType)]; if (!(subproject = [projectCreator createProjectAt:aPath])) { return nil; diff --git a/Headers/ProjectCenter/PCBundleManager.h b/Headers/ProjectCenter/PCBundleManager.h index 7bc2383..43c85a6 100644 --- a/Headers/ProjectCenter/PCBundleManager.h +++ b/Headers/ProjectCenter/PCBundleManager.h @@ -43,14 +43,44 @@ - (NSString *)resourcePath; -- (NSDictionary *)infoForBundlesOfType:(NSString *)extension; -- (NSString *)bundlePathWithName:(NSString *)bundleName; -- (NSBundle *)bundleOfType:(NSString *)type forClassName:(NSString *)className; -- (id)objectForClassName:(NSString *)className - withProtocol:(Protocol *)proto - inBundleType:(NSString *)type; -- (BOOL)loadBundleIfNeededWithName:(NSString *)bundleName; +// --- Handling of bundles' Info.table dictionaries without actual +// --- bundles loading +- (NSDictionary *)infoForBundlesType:(NSString *)extension; + +// Key value can be checked against NSString and NSArray values only. +- (NSDictionary *)infoForBundleType:(NSString *)extension + keyName:(NSString *)key + keyContains:(NSString *)value; + +- (NSDictionary *)infoForBundleName:(NSString *)name + type:(NSString *)type; + +- (NSString *)classNameForBundleType:(NSString*)type + fileName:(NSString *)fileName; + +- (NSString *)bundlePathWithName:(NSString *)bundleName; + +// --- Invokes loading of bundle + +- (id)objectForClassName:(NSString *)className + bundleType:(NSString *)bundleExtension + protocol:(Protocol *)proto; + +- (id)objectForBundleWithName:(NSString *)name + type:(NSString *)extension + protocol:(Protocol *)proto; + +- (id)objectForBundleType:(NSString *)extension + protocol:(Protocol *)proto + fileName:(NSString *)fileName; + +- (NSBundle *)bundleOfType:(NSString *)type + withClassName:(NSString *)className; + +// --- Bundle loading + +- (BOOL)loadBundleIfNeededWithName:(NSString *)bundleName; // Load all bundles found in the BundlePaths - (void)loadBundlesWithExtension:(NSString *)extension; - (void)loadBundlesAtPath:(NSString *)path withExtension:(NSString *)extension; diff --git a/Headers/ProjectCenter/PCProjectEditor.h b/Headers/ProjectCenter/PCProjectEditor.h index d0c2ad9..de464dc 100644 --- a/Headers/ProjectCenter/PCProjectEditor.h +++ b/Headers/ProjectCenter/PCProjectEditor.h @@ -67,12 +67,6 @@ // ==== Project and Editor handling // =========================================================================== -- (NSDictionary *)infoTableForBundleType:(NSString *)type - andFileType:(NSString *)extension; - -- (NSString *)classNameForBundleType:(NSString*)type - andFile:(NSString *)file; - - (BOOL)editorProvidesBrowserItemsForItem:(NSString *)item; // Returns nil if editor is not opened diff --git a/Headers/Protocols/CodeEditor.h b/Headers/Protocols/CodeEditor.h index 0674d18..bb45f9d 100644 --- a/Headers/Protocols/CodeEditor.h +++ b/Headers/Protocols/CodeEditor.h @@ -40,10 +40,6 @@ projectEditor:(id)aProjectEditor editable:(BOOL)editable; -- (id)openExternalEditor:(NSString *)editor - withPath:(NSString *)file - projectEditor:(id)aProjectEditor; - - (void)show; - (void)setWindowed:(BOOL)yn; - (BOOL)isWindowed; diff --git a/Modules/Parsers/ProjectCenter/Resources/Info.table b/Modules/Parsers/ProjectCenter/Resources/Info.table index 904408b..c31a3d1 100644 --- a/Modules/Parsers/ProjectCenter/Resources/Info.table +++ b/Modules/Parsers/ProjectCenter/Resources/Info.table @@ -1,6 +1,6 @@ { Type = "Parser"; - Name = "CodeEditor ObjectiveC parser"; + Name = "ProjectCenter"; Description = "Parser for C and ObjectiveC language"; PrincipalClassName = "PCParser"; FileTypes = (C,c,m,M,h,H,cc,CC); diff --git a/TextFinder.m b/TextFinder.m index 5807ed2..8a3e226 100644 --- a/TextFinder.m +++ b/TextFinder.m @@ -280,18 +280,22 @@ static id sharedFindObject = nil; - (void)enterSelection:(id)sender { NSTextView *text = [self textObjectToSearchIn]; - NSRange range = [text selectedRange]; NSString *string = [text string]; - [self setFindString:[string substringWithRange:range]]; + if (text && string) + { + [self setFindString:[string substringWithRange:[text selectedRange]]]; + } } - (void)jumpToSelection:(id)sender { NSTextView *text = [self textObjectToSearchIn]; - NSRange range = [text selectedRange]; - [text scrollRangeToVisible:range]; + if (text) + { + [text scrollRangeToVisible:[text selectedRange]]; + } } - (void)replace:(id)sender @@ -386,6 +390,34 @@ static id sharedFindObject = nil; } } +- (BOOL)validateMenuItem:(NSMenuItem *)anItem +{ + + if ([anItem action] == @selector(orderFrontFindPanel:)) + { + return ([self textObjectToSearchIn] != NULL); + } + if ([anItem action] == @selector(findNext:)) + { + return ([self textObjectToSearchIn] != NULL); + } + if ([anItem action] == @selector(findPrevious:)) + { + return ([self textObjectToSearchIn] != NULL); + } + if ([anItem action] == @selector(enterSelection:)) + { + return ([self textObjectToSearchIn] != NULL); + } + if ([anItem action] == @selector(jumpToSelection:)) + { + return ([self textObjectToSearchIn] != NULL); + } + // if it isn't one of our menu items, we'll let the + // superclass take care of it + return [super validateMenuItem:anItem]; +} + @end