mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 11:00:59 +00:00
The GSspell server now automatically vends its supported languages
besides AmericanEnglish by means of a small bundle in the user's Services directory. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29783 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b26c2b4df6
commit
8ae82c7bb3
2 changed files with 140 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2010-02-26 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
|
* Tools/GSspell.m (-createBundleAtPath:languages:,
|
||||||
|
-removeBundleAtPath:, -synchronizeLanguages, main): Maintain a
|
||||||
|
small bundle in the user's Services directory to automatically
|
||||||
|
vend the supported languages besides AmericanEnglish.
|
||||||
|
|
||||||
2010-02-26 Richard Frith-Macdonald <rfm@gnu.org>
|
2010-02-26 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/GSServicesManager.m: NSUpdateDynamicServices() ask workspace
|
* Source/GSServicesManager.m: NSUpdateDynamicServices() ask workspace
|
||||||
|
|
133
Tools/GSspell.m
133
Tools/GSspell.m
|
@ -57,6 +57,35 @@
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
// A category for NSBundle so that we can determine the languages
|
||||||
|
// vended by a service bundle
|
||||||
|
@interface NSBundle (MethodsForSpellChecker)
|
||||||
|
- (NSArray *) serviceLanguages;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSBundle (MethodsForSpellChecker)
|
||||||
|
- (NSArray *) serviceLanguages
|
||||||
|
{
|
||||||
|
NSDictionary *infoDict = [self infoDictionary];
|
||||||
|
if ([infoDict isKindOfClass: [NSDictionary class]])
|
||||||
|
{
|
||||||
|
NSArray *services = [infoDict objectForKey: @"NSServices"];
|
||||||
|
if ([services isKindOfClass: [NSArray class]] && [services count] > 0)
|
||||||
|
{
|
||||||
|
NSDictionary *serviceDict = [services objectAtIndex: 0];
|
||||||
|
if ([serviceDict isKindOfClass: [NSDictionary class]])
|
||||||
|
{
|
||||||
|
NSArray *languages = [serviceDict objectForKey: @"NSLanguages"];
|
||||||
|
if ([languages isKindOfClass: [NSArray class]])
|
||||||
|
{
|
||||||
|
return languages;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
// The base class. Its spell checker just provides a dumb spell checker
|
// The base class. Its spell checker just provides a dumb spell checker
|
||||||
// for American English as fallback if aspell is not available.
|
// for American English as fallback if aspell is not available.
|
||||||
|
@ -95,6 +124,109 @@
|
||||||
return [NSArray arrayWithObject: @"AmericanEnglish"];
|
return [NSArray arrayWithObject: @"AmericanEnglish"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) createBundleAtPath: (NSString *)path languages: (NSArray *)languages
|
||||||
|
{
|
||||||
|
NSDictionary *infoDict, *serviceDict;
|
||||||
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
|
NSString *execPath;
|
||||||
|
|
||||||
|
if ([fm fileExistsAtPath: path] && ![fm removeFileAtPath: path handler: nil])
|
||||||
|
{
|
||||||
|
NSLog(@"cannot remove %@", path);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = [path stringByAppendingPathComponent: @"Resources"];
|
||||||
|
if (![fm createDirectoryAtPath: path attributes: nil])
|
||||||
|
{
|
||||||
|
NSLog(@"cannot not create bundle directory %@", path);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = [path stringByAppendingPathComponent: @"Info-gnustep"];
|
||||||
|
path = [path stringByAppendingPathExtension: @"plist"];
|
||||||
|
|
||||||
|
/* FIXME Not sure if the executable path is needed in the service dictionary.
|
||||||
|
However, GSspellInfo.plist has it and so we include it here too. */
|
||||||
|
execPath = [[NSBundle mainBundle] executablePath];
|
||||||
|
serviceDict =
|
||||||
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
execPath, @"NSExecutable",
|
||||||
|
languages, @"NSLanguages",
|
||||||
|
@"GNU", @"NSSpellChecker",
|
||||||
|
nil];
|
||||||
|
infoDict =
|
||||||
|
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
execPath, @"NSExecutable",
|
||||||
|
[NSArray arrayWithObject: serviceDict], @"NSServices",
|
||||||
|
nil];
|
||||||
|
if (![infoDict writeToFile: path atomically: YES])
|
||||||
|
{
|
||||||
|
NSLog(@"cannot save info dictionary to %@", path);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) removeBundleAtPath: (NSString *)path
|
||||||
|
{
|
||||||
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
|
|
||||||
|
if (![fm fileExistsAtPath: path])
|
||||||
|
{
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
if (![fm removeFileAtPath: path handler: nil])
|
||||||
|
{
|
||||||
|
NSLog(@"cannot remove %@", path);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The installed services bundle only vends a spelling service for the
|
||||||
|
AmericanEnglish language. In order to make other languages available,
|
||||||
|
we maintain a bundle in the user's Services directory that vends those
|
||||||
|
languages. The bundle shares our server executable through its info
|
||||||
|
dictionary. */
|
||||||
|
- (void) synchronizeLanguages
|
||||||
|
{
|
||||||
|
NSArray *paths;
|
||||||
|
NSString *path;
|
||||||
|
NSMutableArray *otherLanguages;
|
||||||
|
|
||||||
|
paths =
|
||||||
|
NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
|
||||||
|
NSUserDomainMask,
|
||||||
|
YES);
|
||||||
|
path = [paths objectAtIndex:0];
|
||||||
|
path = [path stringByAppendingPathComponent: @"Services"];
|
||||||
|
path = [path stringByAppendingPathComponent: @"GSspell"];
|
||||||
|
path = [path stringByAppendingPathExtension: @"service"];
|
||||||
|
|
||||||
|
otherLanguages = [[[self languages] mutableCopy] autorelease];
|
||||||
|
[otherLanguages removeObject: @"AmericanEnglish"];
|
||||||
|
[otherLanguages sortUsingSelector: @selector(compare:)];
|
||||||
|
if ([otherLanguages count])
|
||||||
|
{
|
||||||
|
if (![otherLanguages isEqual:
|
||||||
|
[[NSBundle bundleWithPath: path] serviceLanguages]])
|
||||||
|
{
|
||||||
|
if ([self createBundleAtPath: path languages: otherLanguages])
|
||||||
|
{
|
||||||
|
[[NSWorkspace sharedWorkspace] findApplications];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ([self removeBundleAtPath: path])
|
||||||
|
{
|
||||||
|
[[NSWorkspace sharedWorkspace] findApplications];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (NSRange) spellServer: (NSSpellServer *)sender
|
- (NSRange) spellServer: (NSSpellServer *)sender
|
||||||
findMisspelledWordInString: (NSString *)stringToCheck
|
findMisspelledWordInString: (NSString *)stringToCheck
|
||||||
language: (NSString *)language
|
language: (NSString *)language
|
||||||
|
@ -387,6 +519,7 @@ int main(int argc, char** argv)
|
||||||
GNUSpellChecker *aSpellChecker = [[GNU_SPELL_CHECKER_CLASS alloc] init];
|
GNUSpellChecker *aSpellChecker = [[GNU_SPELL_CHECKER_CLASS alloc] init];
|
||||||
|
|
||||||
NSLog(@"NSLanguages = %@", [aSpellChecker languages]);
|
NSLog(@"NSLanguages = %@", [aSpellChecker languages]);
|
||||||
|
[aSpellChecker synchronizeLanguages];
|
||||||
if ([aSpellChecker registerLanguagesWithServer: aServer])
|
if ([aSpellChecker registerLanguagesWithServer: aServer])
|
||||||
{
|
{
|
||||||
[aServer setDelegate: aSpellChecker];
|
[aServer setDelegate: aSpellChecker];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue