Implement [guessesForWord:] and use it in

[browser:createRowsForColumn:inMatrix:]. Don't create the server
in [init], but check it before each use. Check if ther server
proxy exists before all method calls that return a NSRange.
In [checkSpellingOfString:...wordCount:] don't call
[updateSpellingPanelWithMisspelledWord:]. Beep in this method,
when the string is empty. [_findNext:], [_ignore:] and [_correct:]
now use [[NSApp sendAction:to:from:] instead of explicit responder.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11300 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2001-11-03 09:55:32 +00:00
parent ca14662d3d
commit d7eea20d57

View file

@ -41,16 +41,13 @@
#include <AppKit/NSNibLoading.h> #include <AppKit/NSNibLoading.h>
#include <AppKit/NSSpellChecker.h> #include <AppKit/NSSpellChecker.h>
#include <AppKit/NSSpellServer.h> #include <AppKit/NSSpellServer.h>
#include <AppKit/NSTextField.h>
#include <AppKit/NSTextView.h>
#include <AppKit/NSPopUpButton.h>
#include <AppKit/IMLoading.h>
#include <AppKit/GSServicesManager.h> #include <AppKit/GSServicesManager.h>
#include <AppKit/NSApplication.h> #include <AppKit/NSApplication.h>
#include <AppKit/NSTextField.h>
#include <AppKit/NSMatrix.h> #include <AppKit/NSMatrix.h>
#include <AppKit/NSBrowser.h> #include <AppKit/NSBrowser.h>
#include <AppKit/NSBrowserCell.h> #include <AppKit/NSBrowserCell.h>
#include <AppKit/NSScrollView.h> #include <AppKit/NSPopUpButton.h>
// prototype for function to create name for server // prototype for function to create name for server
NSString *GSSpellServerName(NSString *checkerDictionary, NSString *language); NSString *GSSpellServerName(NSString *checkerDictionary, NSString *language);
@ -219,6 +216,8 @@ static int __documentTag = 0;
{ {
if(_serverProxy == nil) if(_serverProxy == nil)
{ {
// Start the server and retain the reference to the
// proxy.
id proxy = [self _startServerForLanguage: _language]; id proxy = [self _startServerForLanguage: _language];
if(proxy != nil) if(proxy != nil)
{ {
@ -238,17 +237,14 @@ static int __documentTag = 0;
- (void)_populateAccessoryView - (void)_populateAccessoryView
{ {
// Make sure that the spell server is up &
// refresh the columns in the browser // refresh the columns in the browser
[self _serverProxy];
[_accessoryView reloadColumn: 0]; [_accessoryView reloadColumn: 0];
} }
- (void)_handleServerDeath: (NSNotification *)notification - (void)_handleServerDeath: (NSNotification *)notification
{ {
NSLog(@"Spell server died"); NSLog(@"Spell server died");
RELEASE(_serverProxy); DESTROY(_serverProxy);
_serverProxy = nil;
} }
// //
@ -266,12 +262,7 @@ static int __documentTag = 0;
_spellPanel = nil; _spellPanel = nil;
_serverProxy = nil; _serverProxy = nil;
_currentTag = 0; _currentTag = 0;
_ignoredWords = [NSMutableDictionary dictionary]; _ignoredWords = [NSMutableDictionary new];
// Start the server and retain the reference to the
// proxy.
[self _serverProxy];
RETAIN(_ignoredWords);
// Load the gmodel file // Load the gmodel file
if(![NSBundle loadNibFile: @"SpellPanel.gmodel" if(![NSBundle loadNibFile: @"SpellPanel.gmodel"
@ -319,11 +310,14 @@ static int __documentTag = 0;
{ {
int count = 0; int count = 0;
NSRange r = NSMakeRange(0,0); NSRange r = NSMakeRange(0,0);
r = [[self _serverProxy] _findMisspelledWordInString: aString id proxy = [self _serverProxy];
language: _language
ignoredWords: nil if (proxy != nil)
wordCount: &count r = [proxy _findMisspelledWordInString: aString
countOnly: YES]; language: _language
ignoredWords: nil
wordCount: &count
countOnly: YES];
return count; return count;
} }
@ -351,8 +345,7 @@ static int __documentTag = 0;
inSpellDocumentWithTag:(int)tag inSpellDocumentWithTag:(int)tag
wordCount:(int *)wordCount wordCount:(int *)wordCount
{ {
NSRange r = NSMakeRange(0,0); NSRange r;
NSString *misspelledWord = nil;
NSArray *dictForTag = [self ignoredWordsInSpellDocumentWithTag: tag]; NSArray *dictForTag = [self ignoredWordsInSpellDocumentWithTag: tag];
_currentTag = tag; _currentTag = tag;
@ -372,13 +365,18 @@ static int __documentTag = 0;
// spellserver does not bring down the application. // spellserver does not bring down the application.
NS_DURING NS_DURING
{ {
id proxy = [self _serverProxy];
// Get the substring and check it. // Get the substring and check it.
NSString *substringToCheck = [stringToCheck substringFromIndex: startingOffset]; NSString *substringToCheck = [stringToCheck substringFromIndex: startingOffset];
r = [[self _serverProxy] _findMisspelledWordInString: substringToCheck if (proxy == nil)
language: _language NS_VALUERETURN(NSMakeRange(0,0), NSRange);
ignoredWords: dictForTag
wordCount: wordCount r = [proxy _findMisspelledWordInString: substringToCheck
countOnly: NO]; language: _language
ignoredWords: dictForTag
wordCount: wordCount
countOnly: NO];
if(r.length != 0) if(r.length != 0)
{ {
@ -392,15 +390,14 @@ static int __documentTag = 0;
// Check the second half of the string // Check the second half of the string
NSString *firstHalfOfString = [stringToCheck NSString *firstHalfOfString = [stringToCheck
substringToIndex: startingOffset]; substringToIndex: startingOffset];
r = [[self _serverProxy] _findMisspelledWordInString: firstHalfOfString r = [proxy _findMisspelledWordInString: firstHalfOfString
language: _language language: _language
ignoredWords: dictForTag ignoredWords: dictForTag
wordCount: wordCount wordCount: wordCount
countOnly: NO]; countOnly: NO];
} }
} }
NS_VALUERETURN(r, NSRange);
misspelledWord = [stringToCheck substringFromRange: r];
} }
NS_HANDLER NS_HANDLER
{ {
@ -408,10 +405,27 @@ static int __documentTag = 0;
} }
NS_ENDHANDLER NS_ENDHANDLER
[self updateSpellingPanelWithMisspelledWord: misspelledWord]; return NSMakeRange(0,0);
[self _populateAccessoryView]; }
return r; - (NSArray *)guessesForWord:(NSString *)word
{
NSArray *guesses;
// Make the call to the server to get the guesses.
NS_DURING
{
guesses = [[self _serverProxy] _suggestGuessesForWord: word
inLanguage: _language];
NS_VALUERETURN(guesses, id);
}
NS_HANDLER
{
NSLog(@"%@",[localException reason]);
}
NS_ENDHANDLER
return nil;
} }
// //
@ -495,18 +509,26 @@ inSpellDocumentWithTag:(int)tag
- (void)updateSpellingPanelWithMisspelledWord:(NSString *)word - (void)updateSpellingPanelWithMisspelledWord:(NSString *)word
{ {
if ((word == nil) || ([word isEqualToString: @""]))
{
[_ignoreButton setEnabled: NO];
[_guessButton setEnabled: NO];
NSBeep();
return;
}
[_ignoreButton setEnabled: YES]; [_ignoreButton setEnabled: YES];
[_guessButton setEnabled: NO]; [_guessButton setEnabled: NO];
[self setWordFieldStringValue: word]; [self setWordFieldStringValue: word];
[self _populateAccessoryView];
} }
- _findNext: (id)sender - _findNext: (id)sender
{ {
BOOL processed = NO; BOOL processed = [NSApp sendAction: @selector(checkSpelling:)
id responder = [[[NSApplication sharedApplication] mainWindow] firstResponder]; to: nil
from: _spellPanel];
processed = [responder tryToPerform: @selector(checkSpelling:)
with: _spellPanel];
if(!processed) if(!processed)
{ {
NSLog(@"No responder found"); NSLog(@"No responder found");
@ -562,11 +584,10 @@ inSpellDocumentWithTag:(int)tag
- _ignore: (id)sender - _ignore: (id)sender
{ {
BOOL processed = NO; BOOL processed = [NSApp sendAction: @selector(ignoreSpelling:)
id responder = [[[NSApplication sharedApplication] mainWindow] firstResponder]; to: nil
from: _wordField];
processed = [responder tryToPerform: @selector(ignoreSpelling:)
with: _wordField];
if(!processed) if(!processed)
{ {
NSLog(@"_ignore: No responder found"); NSLog(@"_ignore: No responder found");
@ -586,11 +607,10 @@ inSpellDocumentWithTag:(int)tag
- _correct: (id)sender - _correct: (id)sender
{ {
BOOL processed = NO; BOOL processed = [NSApp sendAction: @selector(changeSpelling:)
id responder = [[[NSApplication sharedApplication] mainWindow] firstResponder]; to: nil
from: _wordField];
processed = [responder tryToPerform: @selector(changeSpelling:)
with: _wordField];
if(!processed) if(!processed)
{ {
NSLog(@"No responder found"); NSLog(@"No responder found");
@ -614,9 +634,7 @@ inSpellDocumentWithTag:(int)tag
if(proxy != nil) if(proxy != nil)
{ {
ASSIGN(_language, language); ASSIGN(_language, language);
RELEASE(_serverProxy); ASSIGN(_serverProxy, proxy);
_serverProxy = proxy;
RETAIN(_serverProxy);
} }
else else
{ {
@ -685,25 +703,12 @@ inSpellDocumentWithTag:(int)tag
- (void) browser: (NSBrowser *)sender createRowsForColumn: (int)column - (void) browser: (NSBrowser *)sender createRowsForColumn: (int)column
inMatrix: (NSMatrix *)matrix inMatrix: (NSMatrix *)matrix
{ {
NSArray *guesses = nil; NSArray *guesses = [self guessesForWord: [_wordField stringValue]];
NSEnumerator *e = nil; NSEnumerator *e = [guesses objectEnumerator];
NSString *word = nil; NSString *word = nil;
NSBrowserCell *cell= nil; NSBrowserCell *cell= nil;
int i = 0; 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) while((word = [e nextObject]) != nil)
{ {
[matrix insertRow: i withCells: nil]; [matrix insertRow: i withCells: nil];