diff --git a/ChangeLog b/ChangeLog index f23a5880d..1a898b82d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2001-06-23 Gregory John Casamento + * Source/NSSpellChecker.m implementation + * Source/NSSpellServer.m implementation + * Tools/GSspell.m for the GSspell.service. + * Panel/SpellPanel.gmodel also added for the spell checker gui. + Sat Jun 16 15:19:29 2001 Nicola Pero * Source/NSCell.m ([-performClick:]): Call setNextState: diff --git a/Headers/gnustep/gui/NSSpellServer.h b/Headers/gnustep/gui/NSSpellServer.h index 54b998b7e..87c750993 100644 --- a/Headers/gnustep/gui/NSSpellServer.h +++ b/Headers/gnustep/gui/NSSpellServer.h @@ -5,8 +5,8 @@ Copyright (C) 1996 Free Software Foundation, Inc. - Author: Gregory John Casamento - Date: 2000 + Author: Gregory John Casamento + Date: 2001 Author of previous version: Scott Christley Date: 1996 @@ -25,7 +25,7 @@ You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. - If not, write to the Free Software Foundation, + If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ diff --git a/Source/NSSpellChecker.m b/Source/NSSpellChecker.m index 312a355ab..2baba074c 100644 --- a/Source/NSSpellChecker.m +++ b/Source/NSSpellChecker.m @@ -1,12 +1,13 @@ /* NSSpellChecker.m - Description... + Class to provide the graphical interface to the spell checking + service. - Copyright (C) 1996, 2000 Free Software Foundation, Inc. + Copyright (C) 2001, 1996 Free Software Foundation, Inc. Author: Gregory John Casamento - Date: 2000 + Date: 2001 Author: Scott Christley Date: 1996 @@ -51,24 +52,26 @@ #include // prototype for function to create name for server -NSString *GSSpellServerName(NSString *checkerDictionary, - NSString *language); +NSString *GSSpellServerName(NSString *checkerDictionary, NSString *language); // These are methods which we only want the NSSpellChecker to call. // The protocol is defined here so that the outside world does not // have access to these internal methods. @protocol NSSpellServerPrivateProtocol -- (NSRange)_findMisspelledWordInString: (NSString *)stringToCheck - language: (NSString *)language - learnedDictionaries: (NSArray *)dictionaries - wordCount: (int *)wordCount - countOnly: (BOOL)countOnly; --(BOOL)_learnWord: (NSString *)word - inDictionary: (NSString *)language; --(BOOL)_forgetWord: (NSString *)word - inDictionary: (NSString *)language; -- (NSArray *)_suggestGuessesForWord: (NSString *)word - inLanguage: (NSString *)language; +- (NSRange) _findMisspelledWordInString: (NSString *)stringToCheck + language: (NSString *)language + learnedDictionaries: (NSArray *)dictionaries + wordCount: (int *)wordCount + countOnly: (BOOL)countOnly; + +- (BOOL) _learnWord: (NSString *)word + inDictionary: (NSString *)language; + +- (BOOL) _forgetWord: (NSString *)word + inDictionary: (NSString *)language; + +- (NSArray *) _suggestGuessesForWord: (NSString *)word + inLanguage: (NSString *)language; @end // Methods needed to get the GSServicesManager @@ -102,7 +105,6 @@ NSString *GSSpellServerName(NSString *checkerDictionary, NSString *port = GSSpellServerName(vendor, language); double seconds = 30.0; - NSLog(@"Spell Checker Dictionary: %@", spellCheckers); NSLog(@"Language: %@", language); NSLog(@"Service to start: %@", spellServicePath); NSLog(@"Port: %@",port); @@ -119,8 +121,8 @@ NSString *GSSpellServerName(NSString *checkerDictionary, else { NSLog(@"Set proxy"); - [(NSDistantObject *)proxy - setProtocolForProxy: @protocol(NSSpellServerPrivateProtocol)]; + [(NSDistantObject *)proxy setProtocolForProxy: + @protocol(NSSpellServerPrivateProtocol)]; } return proxy; @@ -185,25 +187,6 @@ static int __documentTag = 0; // // Internal methods for use by the spellChecker GUI // -- (void)_populateDictionaryPulldown: (NSArray *)dictionaries; -{ - [_dictionaryPulldown removeAllItems]; - [_dictionaryPulldown addItemsWithTitles: dictionaries]; - [_dictionaryPulldown selectItemWithTitle: _language]; -} - -- (void)_populateAccessoryView: (NSArray *)words -{ - NSLog(@"Populate accessory view.......... %@", words); -} - -- (void)_handleServerDeath: (NSNotification *)notification -{ - NSLog(@"Spell server died"); - RELEASE(_serverProxy); - _serverProxy = nil; -} - // Support function to start the spell server - (id)_startServerForLanguage: (NSString *)language { @@ -243,6 +226,28 @@ static int __documentTag = 0; return _serverProxy; } +- (void)_populateDictionaryPulldown: (NSArray *)dictionaries; +{ + [_dictionaryPulldown removeAllItems]; + [_dictionaryPulldown addItemsWithTitles: dictionaries]; + [_dictionaryPulldown selectItemWithTitle: _language]; +} + +- (void)_populateAccessoryView +{ + // Make sure that the spell server is up & + // refresh the columns in the browser + [self _serverProxy]; + [_accessoryView reloadColumn: 0]; +} + +- (void)_handleServerDeath: (NSNotification *)notification +{ + NSLog(@"Spell server died"); + RELEASE(_serverProxy); + _serverProxy = nil; +} + // // Instance methods // @@ -311,10 +316,10 @@ static int __documentTag = 0; int count = 0; NSRange r = NSMakeRange(0,0); r = [[self _serverProxy] _findMisspelledWordInString: aString - language: _language - learnedDictionaries: nil - wordCount: &count - countOnly: YES]; + language: _language + learnedDictionaries: nil + wordCount: &count + countOnly: YES]; return count; } @@ -326,11 +331,11 @@ static int __documentTag = 0; NSRange r = NSMakeRange(0,0); r = [self checkSpellingOfString: stringToCheck - startingAt: startingOffset - language: _language - wrap: NO - inSpellDocumentWithTag: 0 - wordCount: &wordCount]; + startingAt: startingOffset + language: _language + wrap: NO + inSpellDocumentWithTag: 0 + wordCount: &wordCount]; return r; } @@ -367,10 +372,10 @@ static int __documentTag = 0; // Get the substring and check it. NSString *substringToCheck = [stringToCheck substringFromIndex: startingOffset]; r = [[self _serverProxy] _findMisspelledWordInString: substringToCheck - language: _language - learnedDictionaries: dictForTag - wordCount: wordCount - countOnly: NO]; + language: _language + learnedDictionaries: dictForTag + wordCount: wordCount + countOnly: NO]; if(r.length != 0) { @@ -385,16 +390,16 @@ static int __documentTag = 0; NSString *firstHalfOfString = [stringToCheck substringToIndex: startingOffset]; r = [[self _serverProxy] _findMisspelledWordInString: firstHalfOfString - language: _language - learnedDictionaries: dictForTag - wordCount: wordCount - countOnly: NO]; + language: _language + learnedDictionaries: dictForTag + wordCount: wordCount + countOnly: NO]; } } misspelledWord = [stringToCheck substringFromRange: r]; - suggestedWords = [[self _serverProxy] _suggestGuessesForWord: misspelledWord - inLanguage: _language]; + //suggestedWords = [[self _serverProxy] _suggestGuessesForWord: misspelledWord + // inLanguage: _language]; } NS_HANDLER { @@ -403,7 +408,7 @@ static int __documentTag = 0; NS_ENDHANDLER [self updateSpellingPanelWithMisspelledWord: misspelledWord]; - [self _populateAccessoryView: suggestedWords]; + [self _populateAccessoryView]; return r; } @@ -492,6 +497,8 @@ inSpellDocumentWithTag:(int)tag - (void)updateSpellingPanelWithMisspelledWord:(NSString *)word { + [_ignoreButton setEnabled: YES]; + [_guessButton setEnabled: NO]; [self setWordFieldStringValue: word]; } @@ -553,30 +560,8 @@ inSpellDocumentWithTag:(int)tag - _guess: (id)sender { - NSString *word = [_wordField stringValue]; - NSArray *guesses = nil; - - NS_DURING - { - guesses = [[self _serverProxy] _suggestGuessesForWord: word - inLanguage: _language]; - if(guesses == nil) - { - NSLog(@"Nil array returned from server"); - } - else - { - // Fill in the view... - [self _populateAccessoryView: guesses]; - } - } - NS_HANDLER - { - NSLog(@"%@",[localException reason]); - guesses = nil; - } - NS_ENDHANDLER - + // Fill in the view... + [self _populateAccessoryView]; return self; } @@ -601,7 +586,7 @@ inSpellDocumentWithTag:(int)tag id responder = [[[[NSApplication sharedApplication] mainWindow] contentView] documentView]; processed = [responder tryToPerform: @selector(changeSpelling:) - with: _wordField]; + with: _wordField]; if(!processed) { NSLog(@"Call to changeSpelling failed. No responder found"); @@ -638,31 +623,82 @@ inSpellDocumentWithTag:(int)tag return self; } --(void) awakeFromNib +- _highlightGuess: (id)sender +{ + NSString *selectedGuess = nil; + + selectedGuess = [[_accessoryView selectedCell] stringValue]; + [_ignoreButton setEnabled: NO]; + [_guessButton setEnabled: YES]; + [_wordField setStringValue: selectedGuess]; + + return self; +} + +- (void) awakeFromNib { [self _populateDictionaryPulldown: [[NSApp _listener] _languagesForPopUpButton]]; [_accessoryView setDelegate: self]; + [_accessoryView setDoubleAction: @selector(_correct:)]; } @end -@implementation NSSpellChecker(NSBrowserDelegate) -- (BOOL) browser: (NSBrowser*)sender - selectRow: (int)row - inColumn: (int)column +@interface NSSpellChecker(SpellBrowserDelegate) +- (BOOL) browser: (NSBrowser*)sender selectRow: (int)row inColumn: (int)column; + +- (void) browser: (NSBrowser *)sender createRowsForColumn: (int)column + inMatrix: (NSMatrix *)matrix; + +- (NSString*) browser: (NSBrowser*)sender titleOfColumn: (int)column; + +- (void) browser: (NSBrowser *)sender + willDisplayCell: (id)cell + atRow: (int)row + column: (int)column; + +- (BOOL) browser: (NSBrowser *)sender isColumnValid: (int)column; +@end + +@implementation NSSpellChecker(SpellBrowserDelegate) +- (BOOL) browser: (NSBrowser*)sender selectRow: (int)row inColumn: (int)column { return YES; } -- (void) browser: (NSBrowser *)sender -createRowsForColumn: (int)column - inMatrix: (NSMatrix *)matrix +- (void) browser: (NSBrowser *)sender createRowsForColumn: (int)column + inMatrix: (NSMatrix *)matrix { - NSLog(@"Create rows"); + NSArray *guesses = nil; + NSEnumerator *e = nil; + NSString *word = nil; + NSBrowserCell *cell= nil; + int i = 0; + + // Make the call to the server to get the guesses. + NS_DURING + { + guesses = [_serverProxy _suggestGuessesForWord: [_wordField stringValue] + inLanguage: _language]; + } + NS_HANDLER + { + NSLog(@"%@",[localException reason]); + } + NS_ENDHANDLER + + e = [guesses objectEnumerator]; + while((word = [e nextObject]) != nil) + { + [matrix insertRow: i withCells: nil]; + cell = [matrix cellAtRow: i column: 0]; + [cell setLeaf: YES]; + i++; + [cell setStringValue: word]; + } } -- (NSString*) browser: (NSBrowser*)sender - titleOfColumn: (int)column +- (NSString*) browser: (NSBrowser*)sender titleOfColumn: (int)column { return @"Guess"; } @@ -675,12 +711,9 @@ createRowsForColumn: (int)column NSLog(@"reached 1...."); } -/* -- (BOOL) browser: (NSBrowser *)sender - isColumnValid: (int)column +- (BOOL) browser: (NSBrowser *)sender isColumnValid: (int)column { NSLog(@"reached 3...."); return NO; } -*/ @end diff --git a/Source/NSSpellServer.m b/Source/NSSpellServer.m index f8a2a819f..ffd23799a 100644 --- a/Source/NSSpellServer.m +++ b/Source/NSSpellServer.m @@ -1,16 +1,15 @@ /* NSSpellServer.m - Description... + Class to allow a spell checker to be available to other apps. - This class provides a + Copyright (C) 2001, 1996 Free Software Foundation, Inc. - Copyright (C) 1996 Free Software Foundation, Inc. + Author by: Gregory Casamento + Date: 2001 Author: Scott Christley Date: 1996 - Rewritten by: Gregory Casamento - Date: 2000 This file is part of the GNUstep GUI Library. @@ -47,8 +46,8 @@ static NSString *GNU_UserDictionariesDir = @"Dictionaries"; // Function to create name for spell server.... -NSString *GSSpellServerName(NSString *vendor, - NSString *language) +NSString* +GSSpellServerName(NSString *vendor, NSString *language) { NSString *serverName = nil; @@ -102,11 +101,9 @@ NSString *GSSpellServerName(NSString *vendor, connection = [[NSConnection alloc] init]; if(connection) { - NSLog(@"Connection created."); RETAIN(connection); [connection setRootObject: self]; result = [connection registerName: serverName]; - if(result) NSLog(@"Registered: %@",serverName); } return result; @@ -148,8 +145,7 @@ NSString *GSSpellServerName(NSString *vendor, NSFileManager *mgr = [NSFileManager defaultManager]; // Build the path and try to get the dictionary - dirPath = [user_gsroot stringByAppendingPathComponent: - GNU_UserDictionariesDir]; + dirPath = [user_gsroot stringByAppendingPathComponent: GNU_UserDictionariesDir]; path = [dirPath stringByAppendingPathComponent: currentLanguage]; if (![mgr fileExistsAtPath: path ]) @@ -187,8 +183,8 @@ NSString *GSSpellServerName(NSString *vendor, } } } - - NSLog(@"Path = %@", path); + + NSLog(@"Dictionary path = %@", path); return path; } @@ -285,8 +281,8 @@ NSString *GSSpellServerName(NSString *vendor, if(userDict) { result = [self _isWord: word - inDictionary: userDict - caseSensitive: flag]; + inDictionary: userDict + caseSensitive: flag]; } return result; @@ -321,17 +317,16 @@ NSString *GSSpellServerName(NSString *vendor, { NSMutableSet *set = [self _openUserDictionary: language]; [set addObject: word]; - NSLog(@"learnWord...."); NS_DURING { [_delegate spellServer: self - didLearnWord: word - inLanguage: language]; + didLearnWord: word + inLanguage: language]; } NS_HANDLER { - NSLog(@"Spell server delegate throw exception: %@", + NSLog(@"Call to delegate cause the following exception: %@", [localException reason]); } NS_ENDHANDLER @@ -344,18 +339,17 @@ NSString *GSSpellServerName(NSString *vendor, inDictionary: (NSString *)language { NSMutableSet *set = [self _openUserDictionary: language]; - NSLog(@"forgetWord...."); [set removeObject: word]; NS_DURING { [_delegate spellServer: self - didForgetWord: word - inLanguage: language]; + didForgetWord: word + inLanguage: language]; } NS_HANDLER { - NSLog(@"Spell server delegate throw exception: %@", + NSLog(@"Call to delegate caused following exception: %@", [localException reason]); } NS_ENDHANDLER @@ -371,9 +365,6 @@ NSString *GSSpellServerName(NSString *vendor, countOnly: (BOOL)countOnly { NSRange r = NSMakeRange(0,0); - NSLog(@"In _findMispelledWorkInString:...."); - - NSLog(@"%@", _delegate); if(dictionaries != nil) { @@ -388,10 +379,10 @@ NSString *GSSpellServerName(NSString *vendor, NS_DURING { r = [_delegate spellServer: self - findMisspelledWordInString: stringToCheck - language: language - wordCount: wordCount - countOnly: countOnly]; + findMisspelledWordInString: stringToCheck + language: language + wordCount: wordCount + countOnly: countOnly]; } NS_HANDLER { @@ -408,13 +399,12 @@ NSString *GSSpellServerName(NSString *vendor, { NSArray *words = nil; - NSLog(@"Entered suggestGuesses...."); // Forward to delegate NS_DURING { words = [_delegate spellServer: self - suggestGuessesForWord: word - inLanguage: language]; + suggestGuessesForWord: word + inLanguage: language]; } NS_HANDLER {