diff --git a/BlueLocalization/Source/Framework/Model/Keys/BLKeyObject.m b/BlueLocalization/Source/Framework/Model/Keys/BLKeyObject.m index 69891fe..c49abb0 100755 --- a/BlueLocalization/Source/Framework/Model/Keys/BLKeyObject.m +++ b/BlueLocalization/Source/Framework/Model/Keys/BLKeyObject.m @@ -1,10 +1,10 @@ /*! - @header - BLKeyObject.m - Created by Max on 13.11.04. - - @copyright 2004-2009 the Localization Suite Foundation. All rights reserved. - */ +@header +BLKeyObject.m +Created by Max on 13.11.04. + +@copyright 2004-2009 the Localization Suite Foundation. All rights reserved. +*/ #import "BLKeyObject.h" @@ -21,83 +21,83 @@ @implementation BLKeyObject - (id)init { - self = [super init]; - - _attachedMedia = nil; - _comment = nil; - _key = nil; - _objects = [[NSMutableDictionary alloc] init]; - _snapshot = [[NSMutableDictionary alloc] init]; - - return self; +self = [super init]; + +_attachedMedia = nil; +_comment = nil; +_key = nil; +_objects = [[NSMutableDictionary alloc] init]; +_snapshot = [[NSMutableDictionary alloc] init]; + +return self; } - (id)initWithKey:(NSString *)key { - self = [self init]; - - if (self) { - [self setKey: key]; - } - - return self; +self = [self init]; + +if (self) { + [self setKey: key]; +} + +return self; } - (id)initWithPropertyList:(NSDictionary *)plist { - self = [super initWithPropertyList: plist]; - - if (self) { - // values first - [self setComment: [plist objectForKey: BLFileCommentKey]]; - [self setKey: [plist objectForKey: BLFileKeyKey]]; - [self setAttachedMedia: [[plist objectForKey: BLFileAttachmentsKey] wrapper]]; - - // strings - [_objects setDictionary: [plist objectForKey: BLFileLocalizationsKey]]; - [_snapshot setDictionary: [plist objectForKey: BLFileSnapshotsKey]]; - - // changes - [_changedValues setArray: [plist objectForKey: BLFileChangedValuesKey]]; - } - - return self; +self = [super initWithPropertyList: plist]; + +if (self) { + // values first + [self setComment: [plist objectForKey: BLFileCommentKey]]; + [self setKey: [plist objectForKey: BLFileKeyKey]]; + [self setAttachedMedia: [[plist objectForKey: BLFileAttachmentsKey] wrapper]]; + + // strings + [_objects setDictionary: [plist objectForKey: BLFileLocalizationsKey]]; + [_snapshot setDictionary: [plist objectForKey: BLFileSnapshotsKey]]; + + // changes + [_changedValues setArray: [plist objectForKey: BLFileChangedValuesKey]]; +} + +return self; } #pragma mark - Serialization - (NSDictionary *)propertyListWithAttributes:(NSDictionary *)attributes { - NSMutableDictionary *dict = [NSMutableDictionary dictionary]; - [dict setDictionary: [super propertyListWithAttributes: attributes]]; - - // General Properties - if ([self key]) - [dict setObject:[self key] forKey:BLFileKeyKey]; - if ([self comment]) - [dict setObject:[self comment] forKey:BLFileCommentKey]; - if ([self attachedMedia]) - [dict setObject:[BLWrapperHandle handleWithWrapper:[self attachedMedia] forPreferredPath:@"Media"] forKey:BLFileAttachmentsKey]; - - // Exported strings - NSMutableDictionary *exportedStrings = [NSMutableDictionary dictionaryWithDictionary: self.strings]; - NSMutableDictionary *snapshotStrings = [NSMutableDictionary dictionaryWithDictionary: _snapshot]; +NSMutableDictionary *dict = [NSMutableDictionary dictionary]; +[dict setDictionary: [super propertyListWithAttributes: attributes]]; + +// General Properties +if ([self key]) + [dict setObject:[self key] forKey:BLFileKeyKey]; +if ([self comment]) + [dict setObject:[self comment] forKey:BLFileCommentKey]; +if ([self attachedMedia]) + [dict setObject:[BLWrapperHandle handleWithWrapper:[self attachedMedia] forPreferredPath:@"Media"] forKey:BLFileAttachmentsKey]; + +// Exported strings +NSMutableDictionary *exportedStrings = [NSMutableDictionary dictionaryWithDictionary: self.strings]; +NSMutableDictionary *snapshotStrings = [NSMutableDictionary dictionaryWithDictionary: _snapshot]; + +// Filter languages +if ([attributes objectForKey: BLLanguagesSerializationKey]) { + NSMutableSet *remove = [NSMutableSet setWithArray: [exportedStrings allKeys]]; + [remove minusSet: [NSSet setWithArray: [attributes objectForKey: BLLanguagesSerializationKey]]]; - // Filter languages - if ([attributes objectForKey: BLLanguagesSerializationKey]) { - NSMutableSet *remove = [NSMutableSet setWithArray: [exportedStrings allKeys]]; - [remove minusSet: [NSSet setWithArray: [attributes objectForKey: BLLanguagesSerializationKey]]]; - - [exportedStrings removeObjectsForKeys: [remove allObjects]]; - [_snapshot removeObjectsForKeys: [remove allObjects]]; - } - - // Store strings - [dict setObject:exportedStrings forKey:BLFileLocalizationsKey]; - if (![[attributes objectForKey: BLClearAllBackupsSerializationKey] boolValue]) - [dict setObject:snapshotStrings forKey:BLFileSnapshotsKey]; - - return dict; + [exportedStrings removeObjectsForKeys: [remove allObjects]]; + [_snapshot removeObjectsForKeys: [remove allObjects]]; +} + +// Store strings +[dict setObject:exportedStrings forKey:BLFileLocalizationsKey]; +if (![[attributes objectForKey: BLClearAllBackupsSerializationKey] boolValue]) + [dict setObject:snapshotStrings forKey:BLFileSnapshotsKey]; + +return dict; } @@ -105,33 +105,33 @@ - (NSDictionary *)propertyListWithAttributes:(NSDictionary *)attributes - (NSString *)name { - return _key; +return _key; } @synthesize key=_key; - (NSString *)comment { - return _comment; +return _comment; } - (void)setComment:(NSString *)comment { - - if (comment && [comment length]) - _comment = comment; - else - _comment = nil; + +if (comment && [comment length]) + _comment = comment; +else + _comment = nil; } - (NSFileWrapper *)attachedMedia { - return _attachedMedia; +return _attachedMedia; } - (void)setAttachedMedia:(NSFileWrapper *)attachedMedia { - _attachedMedia = attachedMedia; +_attachedMedia = attachedMedia; } @@ -139,120 +139,120 @@ - (void)setAttachedMedia:(NSFileWrapper *)attachedMedia - (BLFileObject *)fileObject { - return _fileObject; +return _fileObject; } - (void)setFileObject:(BLFileObject *)object { - _fileObject = object; +_fileObject = object; } - (id)parentObject { - return [self fileObject]; +return [self fileObject]; } - (BOOL)isEmpty { - for (NSString *language in [self languages]) { - if (![self isEmptyForLanguage: language]) - return NO; - } - - return YES; +for (NSString *language in [self languages]) { + if (![self isEmptyForLanguage: language]) + return NO; +} + +return YES; } - (BOOL)isEmptyForLanguage:(NSString *)lang { - return [[self class] isEmptyValue: [self objectForLanguage: lang]]; +return [[self class] isEmptyValue: [self objectForLanguage: lang]]; } - (BOOL)isEqual:(id)other { - if (![super isEqual: other]) +if (![super isEqual: other]) + return NO; + +// Compare keys +if (!([self key] == nil && [other key] == nil) && ![[self key] isEqual: [other key]]) + return NO; +if (!([self comment] == nil && [other comment] == nil) && ![[self comment] isEqual: [other comment]]) + return NO; + +// Compare number of languages +if ([[self languages] count] != [[other languages] count]) + return NO; + +// Compare all objects +for (NSString *language in [self languages]) { + if (![[self class] value:[self objectForLanguage: language] isEqual:[other objectForLanguage: language]]) return NO; - - // Compare keys - if (!([self key] == nil && [other key] == nil) && ![[self key] isEqual: [other key]]) - return NO; - if (!([self comment] == nil && [other comment] == nil) && ![[self comment] isEqual: [other comment]]) - return NO; - - // Compare number of languages - if ([[self languages] count] != [[other languages] count]) - return NO; - - // Compare all objects - for (NSString *language in [self languages]) { - if (![[self class] value:[self objectForLanguage: language] isEqual:[other objectForLanguage: language]]) - return NO; - } - - return YES; +} + +return YES; } + (BOOL)isEmptyValue:(id)value { - return (value == nil); +return (value == nil); } + (BOOL)value:(id)value isEqual:(id)other { - return [value isEqual: other]; +return [value isEqual: other]; } - (void)removeObjectForLanguage:(NSString *)language { - [self setObject:nil forLanguage:language]; +[self setObject:nil forLanguage:language]; } #pragma mark - KVC Overrides - (id)valueForKey:(NSString *)key { - if ([key isEqual: @"comment"]) - return [self comment]; - if ([key isEqual: @"didChange"]) - return [NSNumber numberWithBool: [self didChange]]; - if ([key isEqual: @"key"]) - return [self key]; - if ([[self languages] containsObject: key]) - return [self objectForLanguage: key]; - - return [super valueForKey: key]; +if ([key isEqual: @"comment"]) + return [self comment]; +if ([key isEqual: @"didChange"]) + return [NSNumber numberWithBool: [self didChange]]; +if ([key isEqual: @"key"]) + return [self key]; +if ([[self languages] containsObject: key]) + return [self objectForLanguage: key]; + +return [super valueForKey: key]; } - (id)valueForUndefinedKey:(NSString *)key { - return [self objectForLanguage: key]; +return [self objectForLanguage: key]; } - (void)setValue:(id)value forKey:(NSString *)key { - if ([key isEqual: @"comment"]) { - [self setComment: value]; - return; - } - if ([key isEqual: @"didChange"]) { - if (![value boolValue]) - [self setNothingDidChange]; - return; - } - if ([key isEqual: @"key"]) { - [self setKey: value]; - return; - } - if ([[self languages] indexOfObject: key] != NSNotFound) { - [self setObject:value forLanguage:key]; - return; - } - - [super setValue:value forKey:key]; +if ([key isEqual: @"comment"]) { + [self setComment: value]; + return; +} +if ([key isEqual: @"didChange"]) { + if (![value boolValue]) + [self setNothingDidChange]; + return; +} +if ([key isEqual: @"key"]) { + [self setKey: value]; + return; +} +if ([[self languages] indexOfObject: key] != NSNotFound) { + [self setObject:value forLanguage:key]; + return; +} + +[super setValue:value forKey:key]; } - (void)setValue:(id)value forUndefinedKey:(NSString *)key { - [self setObject:value forLanguage:key]; +[self setObject:value forLanguage:key]; } @@ -260,71 +260,71 @@ - (void)setValue:(id)value forUndefinedKey:(NSString *)key - (id)objectForLanguage:(NSString *)lang { - return [_objects objectForKey: lang]; +return [_objects objectForKey: lang]; } - (NSString *)stringForLanguage:(NSString *)lang { - if ([[self class] classOfObjects] == [NSString class]) - return [self objectForLanguage: lang]; - else { - [NSException raise:NSInternalInconsistencyException format:@"Superclass cannot convert object to string!"]; - return nil; - } +if ([[self class] classOfObjects] == [NSString class]) + return [self objectForLanguage: lang]; +else { + [NSException raise:NSInternalInconsistencyException format:@"Superclass cannot convert object to string!"]; + return nil; +} } - (void)setObject:(id)object forLanguage:(NSString *)lang { - if (!lang) - [NSException raise:NSInvalidArgumentException format:@"Language may not be nil for setting value %@ to key object %@", object, self]; +if (!lang) + [NSException raise:NSInvalidArgumentException format:@"Language may not be nil for setting value %@ to key object %@", object, self]; + +if (object && [[self class] isEmptyValue: object]) + object = nil; +id oldObject = [self objectForLanguage: lang]; + +if ((object != oldObject) && ![object isEqual: oldObject]) { + [self willChangeValueForKey: lang]; - if (object && [[self class] isEmptyValue: object]) - object = nil; - id oldObject = [self objectForLanguage: lang]; + // Overwrite or delete + if (object) + [_objects setObject:object forKey:lang]; + else + [_objects removeObjectForKey: lang]; - if ((object != oldObject) && ![object isEqual: oldObject]) { - [self willChangeValueForKey: lang]; - - // Overwrite or delete - if (object) - [_objects setObject:object forKey:lang]; - else - [_objects removeObjectForKey: lang]; - - // Track changes - [self didChangeValueForKey: lang]; - [self setValue:lang didChange:YES]; - } + // Track changes + [self didChangeValueForKey: lang]; + [self setValue:lang didChange:YES]; +} } - (NSArray *)languages { - return [_objects allKeys]; +return [_objects allKeys]; } - (NSDictionary *)strings { - return _objects; +return _objects; } - (NSString *)description { - return [[super description] stringByAppendingFormat: @" %@", _objects]; +return [[super description] stringByAppendingFormat: @" %@", _objects]; } - (void)snapshotLanguage:(NSString *)language { - id object = [_objects objectForKey: language]; - - if (object) - [_snapshot setObject:object forKey:language]; - else - [_snapshot removeObjectForKey: language]; +id object = [_objects objectForKey: language]; + +if (object) + [_snapshot setObject:object forKey:language]; +else + [_snapshot removeObjectForKey: language]; } - (id)snapshotForLanguage:(NSString *)language { - return [_snapshot objectForKey: language]; +return [_snapshot objectForKey: language]; } @@ -332,7 +332,7 @@ - (id)snapshotForLanguage:(NSString *)language + (Class)classOfObjects { - return nil; +return nil; } @end diff --git a/BlueLocalization/Source/Framework/Utilities/General/BLDictionaryController.m b/BlueLocalization/Source/Framework/Utilities/General/BLDictionaryController.m index 535e690..9ea39da 100755 --- a/BlueLocalization/Source/Framework/Utilities/General/BLDictionaryController.m +++ b/BlueLocalization/Source/Framework/Utilities/General/BLDictionaryController.m @@ -51,34 +51,34 @@ @implementation BLDictionaryController - (id)init { - self = [super init]; + self = [super init]; - _dictionaries = [[NSMutableArray alloc] init]; + _dictionaries = [[NSMutableArray alloc] init]; _documents = [[NSMutableArray alloc] init]; - _keys = [[NSMutableArray alloc] init]; + _keys = [[NSMutableArray alloc] init]; _useDocuments = NO; - + __sharedDictionaryController = self; [self loadSettings]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:NSApp]; - - return self; + + return self; } - (void)dealloc { - - __sharedDictionaryController = nil; - + + __sharedDictionaryController = nil; + } + (id)sharedInstance { - if (!__sharedDictionaryController) - __sharedDictionaryController = [[self alloc] init]; - - return __sharedDictionaryController; + if (!__sharedDictionaryController) + __sharedDictionaryController = [[self alloc] init]; + + return __sharedDictionaryController; } @@ -86,18 +86,18 @@ + (id)sharedInstance - (void)loadSettings { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - - [self registerDictionariesAtPathURLs: [defaults objectForKey: LTDictionaryControllerDictionaryURLsKey]]; - [self setUseDocuments: [defaults boolForKey: LTDictionaryControllerUseDocumentsKey]]; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + [self registerDictionariesAtPathURLs: [defaults objectForKey: LTDictionaryControllerDictionaryURLsKey]]; + [self setUseDocuments: [defaults boolForKey: LTDictionaryControllerUseDocumentsKey]]; } - (void)applicationWillTerminate:(NSNotification *)notification { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - [defaults setObject:[_dictionaries valueForKeyPath: @"fileURL.absoluteString"] forKey:LTDictionaryControllerDictionaryURLsKey]; - [defaults setBool:[self useDocuments] forKey:LTDictionaryControllerUseDocumentsKey]; + [defaults setObject:[_dictionaries valueForKeyPath: @"fileURL.absoluteString"] forKey:LTDictionaryControllerDictionaryURLsKey]; + [defaults setBool:[self useDocuments] forKey:LTDictionaryControllerUseDocumentsKey]; } diff --git a/LocInterface/Source/Framework/Autotranslation/LIDictionaryStatusCell.m b/LocInterface/Source/Framework/Autotranslation/LIDictionaryStatusCell.m index 0862838..ac24a23 100644 --- a/LocInterface/Source/Framework/Autotranslation/LIDictionaryStatusCell.m +++ b/LocInterface/Source/Framework/Autotranslation/LIDictionaryStatusCell.m @@ -27,7 +27,7 @@ - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView NSRect target; NSString *path = [[_document fileURL] path]; - NSColor *altColor = ([self isHighlighted] && [[controlView window] firstResponder] == controlView && [[controlView window] isKeyWindow]) ? [NSColor whiteColor] : nil; + NSColor *altColor = ([self isHighlighted] && [[controlView window] firstResponder] == controlView && [[controlView window] isKeyWindow]) ? [NSColor textBackgroundColor] : nil; // Contains dict? BOOL containsDict = ([_document isKindOfClass: [BLLocalizerDocument class]] && [_document embeddedDictionary]); @@ -41,7 +41,7 @@ - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView [icon drawInRect:target fromRect:source operation:NSCompositeSourceOver fraction:1.0]; // Draw the file name - NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSFont systemFontOfSize: 13], NSFontAttributeName, (altColor) ? altColor : [NSColor blackColor], NSForegroundColorAttributeName, nil]; + NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSFont systemFontOfSize: 13], NSFontAttributeName, (altColor) ? altColor : [NSColor textColor], NSForegroundColorAttributeName, nil]; target.origin = NSMakePoint(target.size.width + 6, 2 + cellFrame.origin.y); target.size = NSMakeSize(cellFrame.size.width - target.origin.x - 150, 17); [[[path lastPathComponent] stringByDeletingPathExtension] drawInRect:target withAttributes:attributes]; diff --git a/LocInterface/Source/Framework/Content/Utilities/LIAttachmentCell.m b/LocInterface/Source/Framework/Content/Utilities/LIAttachmentCell.m index 8a81e37..b5b8c93 100644 --- a/LocInterface/Source/Framework/Content/Utilities/LIAttachmentCell.m +++ b/LocInterface/Source/Framework/Content/Utilities/LIAttachmentCell.m @@ -107,7 +107,7 @@ - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView [self setHighlighted: hightlighted]; // Delete mark - NSImage *delete = [self deleteImageWithColor: (![self isHighlighted]) ? [NSColor whiteColor] : [NSColor lightGrayColor]]; + NSImage *delete = [self deleteImageWithColor: (![self isHighlighted]) ? [NSColor textBackgroundColor] : [NSColor lightGrayColor]]; NSRect fromRect = NSMakeRect(0, 0, [delete size].width, [delete size].height); [delete drawInRect:[self deleteButtonFrame: cellFrame] fromRect:fromRect operation:NSCompositeSourceOver fraction:1]; diff --git a/LocInterface/Source/Framework/Content/Utilities/LIObjectColorValueTransformer.m b/LocInterface/Source/Framework/Content/Utilities/LIObjectColorValueTransformer.m index 2495b73..b3075f3 100644 --- a/LocInterface/Source/Framework/Content/Utilities/LIObjectColorValueTransformer.m +++ b/LocInterface/Source/Framework/Content/Utilities/LIObjectColorValueTransformer.m @@ -28,7 +28,7 @@ - (id)transformedValue:(id)value BLObject *object; if (![value isKindOfClass: [BLObject class]]) - return [NSColor blackColor]; + return [NSColor textColor]; object = (BLObject *)value; if ([[object errors] count] > 0) @@ -36,7 +36,7 @@ - (id)transformedValue:(id)value else if ([object isKindOfClass: [BLBundleObject class]]) return [NSColor disabledControlTextColor]; else - return [NSColor blackColor]; + return [NSColor textColor]; } @end diff --git a/LocInterface/Source/Framework/Content/Utilities/LIObjectStatusCell.m b/LocInterface/Source/Framework/Content/Utilities/LIObjectStatusCell.m index 40487a1..4a1c17a 100644 --- a/LocInterface/Source/Framework/Content/Utilities/LIObjectStatusCell.m +++ b/LocInterface/Source/Framework/Content/Utilities/LIObjectStatusCell.m @@ -81,7 +81,7 @@ - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView // Label NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSFont fontWithName:@"Helvetica Bold" size:10], NSFontAttributeName, - [NSColor whiteColor], NSForegroundColorAttributeName, + [NSColor textBackgroundColor], NSForegroundColorAttributeName, nil]; rect.origin.x += 2; rect.origin.y -= 1; diff --git a/LocInterface/Source/Framework/Panels/LIPreferences.m b/LocInterface/Source/Framework/Panels/LIPreferences.m index eb81d3a..4de50d2 100644 --- a/LocInterface/Source/Framework/Panels/LIPreferences.m +++ b/LocInterface/Source/Framework/Panels/LIPreferences.m @@ -31,30 +31,30 @@ - (NSString *)windowNibName - (id)init { - self = [super init]; - + self = [super init]; + if (self) { self.openDocuments = [NSArray array]; self.selectedDocument = nil; [self addObserver:self forKeyPath:@"openDocuments" options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionPrior context:@"documents"]; } - - return self; + + return self; } - (void)dealloc { - __sharedLIPreferences = nil; + __sharedLIPreferences = nil; [query removeObserver:self forKeyPath:@"results"]; } + (id)sharedInstance { - if (!__sharedLIPreferences) - __sharedLIPreferences = [[self alloc] init]; - - return __sharedLIPreferences; + if (!__sharedLIPreferences) + __sharedLIPreferences = [[self alloc] init]; + + return __sharedLIPreferences; } @@ -72,7 +72,7 @@ - (void)close - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (context == @"documents") { + if (context == @"documents") { if (![self.openDocuments containsObject: self.selectedDocument]) { if ([self.openDocuments count]) self.selectedDocument = [self.openDocuments objectAtIndex: 0]; @@ -81,11 +81,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N } } else if (context == @"toolPaths") { - if ([change objectForKey: NSKeyValueChangeNotificationIsPriorKey]) + if ([change objectForKey: NSKeyValueChangeNotificationIsPriorKey]) [self willChangeValueForKey: @"availableDeveloperTools"]; else [self didChangeValueForKey: @"availableDeveloperTools"]; - } + } else { [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } diff --git a/LocTools/Source/Framework/Matching/LTKeyMatch.m b/LocTools/Source/Framework/Matching/LTKeyMatch.m index 563725c..0370717 100755 --- a/LocTools/Source/Framework/Matching/LTKeyMatch.m +++ b/LocTools/Source/Framework/Matching/LTKeyMatch.m @@ -12,8 +12,8 @@ @implementation LTKeyMatch - (id)initWithKeyObject:(BLKeyObject *)match matchPercentage:(float)percentage forTargetLanguage:(NSString *)language actualTargetLanguage:(NSString *)actualLanguage andMatchLanguage:(NSString *)matchLanguage { - self = [super init]; - + self = [super init]; + if (self) { _actualTargetLanguage = actualLanguage; _targetLanguage = language; @@ -21,8 +21,8 @@ - (id)initWithKeyObject:(BLKeyObject *)match matchPercentage:(float)percentage f _percentage = percentage; _matchLanguage = matchLanguage; } - - return self; + + return self; } @@ -31,12 +31,12 @@ - (id)initWithKeyObject:(BLKeyObject *)match matchPercentage:(float)percentage f - (BLKeyObject *)keyObject { - return _object; + return _object; } - (float)matchPercentage { - return _percentage; + return _percentage; } - (NSString *)targetLanguage @@ -59,33 +59,33 @@ - (NSString *)matchLanguage - (NSAttributedString *)percentageString { - NSAttributedString *result; - NSColor *color; - - if (_percentage == 1.0) - color = [NSColor colorWithDeviceRed:0 green:0.5 blue:0 alpha:1.0]; - else if (_percentage >= 0.75) - color = [NSColor colorWithDeviceRed:0.9 green:0.6 blue:0 alpha:1.0]; - else if (_percentage >= 0.5) - color = [NSColor colorWithDeviceRed:0.8 green:0 blue:0 alpha:1.0]; - else - color = [NSColor blackColor]; - - result = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%0.0f%%", 100*[self matchPercentage]] + NSAttributedString *result; + NSColor *color; + + if (_percentage == 1.0) + color = [NSColor colorWithDeviceRed:0 green:0.5 blue:0 alpha:1.0]; + else if (_percentage >= 0.75) + color = [NSColor colorWithDeviceRed:0.9 green:0.6 blue:0 alpha:1.0]; + else if (_percentage >= 0.5) + color = [NSColor colorWithDeviceRed:0.8 green:0 blue:0 alpha:1.0]; + else + color = [NSColor textColor]; + + result = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%0.0f%%", 100*[self matchPercentage]] attributes:[NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName]]; - - return result; + + return result; } - (NSString *)matchedValue { - return [_object stringForLanguage: _matchLanguage]; + return [_object stringForLanguage: _matchLanguage]; } - (NSString *)targetValue { NSString *language = (_actualTargetLanguage) ? _actualTargetLanguage : _targetLanguage; - return [_object stringForLanguage: language]; + return [_object stringForLanguage: language]; } diff --git a/LocTools/Source/Framework/Translation Checker/LTTranslationChecker.m b/LocTools/Source/Framework/Translation Checker/LTTranslationChecker.m index 2697abc..d4ff043 100644 --- a/LocTools/Source/Framework/Translation Checker/LTTranslationChecker.m +++ b/LocTools/Source/Framework/Translation Checker/LTTranslationChecker.m @@ -81,7 +81,7 @@ + (void)initialize LTTranslationCheckerDefaultPlaceholders = [NSArray arrayWithObjects: @"%*@", @"^C", @"%*d", @"%*f", @"%*s", @"%c", @"%*x", @"%*i", @"%*u", nil]; LTTranslationCheckerIgnorePlaceholders = [NSArray arrayWithObjects: @"%%", @"%_", nil]; - LTTranslationCheckerStringEndingCharacters = [NSArray arrayWithObjects: @":", @";", @".", @"…", @"!", @"?", @")", @"]", @"}", @">", nil]; + LTTranslationCheckerStringEndingCharacters = [NSArray arrayWithObjects: @":", @";", @".", @"…", @"!", @"?", @")", @"]", @"}", @">", @"。", nil]; LTTranslationCheckerWhitespaceReplacements = [NSDictionary dictionaryWithObjectsAndKeys: @"", @"\n", @"", @"\t", @"", @" ", nil]; @@ -249,7 +249,12 @@ + (NSArray *)getLineEndingErrorsFromOrginal:(NSString *)original andTranslation: transWhitespace = [translated substringFromIndex: transEnd]; origEnding = [original substringWithRange: origRange]; transEnding = [translated substringWithRange: transRange]; - + if ([origEnding isEqualToString:@"。"]) { + origEnding = @"."; + } + if ([transEnding isEqualToString:@"。"]) { + transEnding = @"."; + } if (![origEnding isEqual: transEnding]) { description = [NSString stringWithFormat: NSLocalizedStringFromTableInBundle(@"Mismatching string ending", @"LTTranslationChecker", [NSBundle bundleForClass: [self class]], nil), origEnding, transEnding]; fix = [NSString stringWithFormat: @"%@%@%@", [translated substringToIndex: [translated length] - [transWhitespace length] - [transEnding length]], origEnding, transWhitespace]; diff --git a/Localizer/Interface/English.lproj/Document.xib b/Localizer/Interface/English.lproj/Document.xib index 3a8fe3e..9bb82b2 100644 --- a/Localizer/Interface/English.lproj/Document.xib +++ b/Localizer/Interface/English.lproj/Document.xib @@ -96,7 +96,7 @@ - + @@ -407,7 +407,7 @@ - + diff --git a/Localizer/Localizer.xcodeproj/project.pbxproj b/Localizer/Localizer.xcodeproj/project.pbxproj index 5f198e8..ad40c15 100755 --- a/Localizer/Localizer.xcodeproj/project.pbxproj +++ b/Localizer/Localizer.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ @@ -37,6 +37,7 @@ 50C3D1A60FC37A32005AEF1A /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50C3D1A50FC37A32005AEF1A /* Sparkle.framework */; }; 50C3D1A70FC37A3D005AEF1A /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 50C3D1A50FC37A32005AEF1A /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; 50C3D25C0FC37D40005AEF1A /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 50C3D25B0FC37D40005AEF1A /* dsa_pub.pem */; }; + 56320E74230EA988002A5878 /* GSStringToAttributedValueTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 56320E73230EA988002A5878 /* GSStringToAttributedValueTransformer.m */; }; 56370B451D42136B0024CD02 /* GSGroupView.m in Sources */ = {isa = PBXBuildFile; fileRef = 56370B441D42136B0024CD02 /* GSGroupView.m */; }; 56370B481D4221700024CD02 /* GSLine.m in Sources */ = {isa = PBXBuildFile; fileRef = 56370B471D4221700024CD02 /* GSLine.m */; }; 565DBF2F1D42066C000513F0 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 565DBF2E1D42066C000513F0 /* Cocoa.framework */; }; @@ -99,6 +100,8 @@ 50C3D18E0FC3792D005AEF1A /* loc.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = loc.icns; path = ../Shared/Icons/loc.icns; sourceTree = SOURCE_ROOT; }; 50C3D1A50FC37A32005AEF1A /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = ../Shared/Frameworks/Sparkle.framework; sourceTree = SOURCE_ROOT; }; 50C3D25B0FC37D40005AEF1A /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = dsa_pub.pem; path = ../Shared/Updates/dsa_pub.pem; sourceTree = SOURCE_ROOT; }; + 56320E72230EA988002A5878 /* GSStringToAttributedValueTransformer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GSStringToAttributedValueTransformer.h; sourceTree = ""; }; + 56320E73230EA988002A5878 /* GSStringToAttributedValueTransformer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GSStringToAttributedValueTransformer.m; sourceTree = ""; }; 56370B431D42136B0024CD02 /* GSGroupView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GSGroupView.h; sourceTree = ""; }; 56370B441D42136B0024CD02 /* GSGroupView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GSGroupView.m; sourceTree = ""; }; 56370B461D4221700024CD02 /* GSLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GSLine.h; sourceTree = ""; }; @@ -241,6 +244,8 @@ 50E8D89D08CDBF71003F43C3 /* Interface */ = { isa = PBXGroup; children = ( + 56320E72230EA988002A5878 /* GSStringToAttributedValueTransformer.h */, + 56320E73230EA988002A5878 /* GSStringToAttributedValueTransformer.m */, 50BB659D10B5C61A00A1AD4C /* StatisticsTextView.h */, 50BB659E10B5C61A00A1AD4C /* StatisticsTextView.m */, 56370B431D42136B0024CD02 /* GSGroupView.h */, @@ -290,7 +295,7 @@ }; }; buildConfigurationList = 501EBC8B0855AE8600FBC27B /* Build configuration list for PBXProject "Localizer" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 10.0"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( @@ -344,6 +349,7 @@ 50BB659F10B5C61A00A1AD4C /* StatisticsTextView.m in Sources */, 5056659F1384161300E8AB31 /* Preferences.m in Sources */, 50172E111403AA7E006EFC17 /* NSAlert-Extensions.m in Sources */, + 56320E74230EA988002A5878 /* GSStringToAttributedValueTransformer.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -407,6 +413,7 @@ CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; + DEVELOPMENT_TEAM = X2L8375ZQ7; FRAMEWORK_SEARCH_PATHS = "\"$(SRCROOT)/../Shared/Frameworks\""; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_OPTIMIZATION_LEVEL = 0; @@ -429,6 +436,7 @@ COMBINE_HIDPI_IMAGES = YES; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = X2L8375ZQ7; FRAMEWORK_SEARCH_PATHS = "\"$(SRCROOT)/../Shared/Frameworks\""; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_PRECOMPILE_PREFIX_HEADER = YES; diff --git a/Localizer/Source/Interface/GSGroupView.m b/Localizer/Source/Interface/GSGroupView.m index 2ba8477..e861af8 100644 --- a/Localizer/Source/Interface/GSGroupView.m +++ b/Localizer/Source/Interface/GSGroupView.m @@ -11,17 +11,17 @@ @implementation GSGroupView - (void)drawRect:(NSRect)dirtyRect { - [super drawRect:dirtyRect]; - [[NSColor whiteColor] set]; + [super drawRect:dirtyRect]; + [[NSColor textBackgroundColor] set]; NSRectFill(dirtyRect); - [[NSColor colorWithCalibratedWhite:0.6 alpha:1] set]; + [[NSColor tertiaryLabelColor] set]; NSRect bounds = [self bounds]; NSRect rect = bounds; rect.origin.y += NSHeight(rect) - 1; rect.size.height = 1; NSRectFill(rect); if (NSHeight(bounds) < 30 && NSHeight(bounds) > 3) { - [[NSColor colorWithCalibratedWhite:0.75 alpha:1] set]; + [[NSColor tertiaryLabelColor] set]; rect.origin.y = 0; NSRectFill(rect); } diff --git a/Localizer/Source/Interface/GSLine.m b/Localizer/Source/Interface/GSLine.m index a2daab2..d635172 100644 --- a/Localizer/Source/Interface/GSLine.m +++ b/Localizer/Source/Interface/GSLine.m @@ -11,7 +11,7 @@ @implementation GSLine - (void)drawRect:(NSRect)dirtyRect { - [[NSColor colorWithCalibratedWhite:0.6 alpha:1] set]; + [[NSColor tertiaryLabelColor] set]; NSRectFill(dirtyRect); } diff --git a/Localizer/Source/Interface/GSStringToAttributedValueTransformer.h b/Localizer/Source/Interface/GSStringToAttributedValueTransformer.h new file mode 100644 index 0000000..9f64bff --- /dev/null +++ b/Localizer/Source/Interface/GSStringToAttributedValueTransformer.h @@ -0,0 +1,17 @@ +// +// GSStringToAttributedValueTransformer.h +// LocInterface +// +// Created by Georg Seifert on 22.08.19. +// Copyright © 2019 Localization Suite. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface GSStringToAttributedValueTransformer : NSValueTransformer + +@end + +NS_ASSUME_NONNULL_END diff --git a/Localizer/Source/Interface/GSStringToAttributedValueTransformer.m b/Localizer/Source/Interface/GSStringToAttributedValueTransformer.m new file mode 100644 index 0000000..57b37e2 --- /dev/null +++ b/Localizer/Source/Interface/GSStringToAttributedValueTransformer.m @@ -0,0 +1,38 @@ +// +// GSStringToAttributedValueTransformer.m +// LocInterface +// +// Created by Georg Seifert on 22.08.19. +// Copyright © 2019 Localization Suite. All rights reserved. +// + +#import "GSStringToAttributedValueTransformer.h" + +@implementation GSStringToAttributedValueTransformer + ++ (BOOL)allowsReverseTransformation { + return YES; +} + ++ (Class)transformedValueClass { + return [NSAttributedString class]; +} + +- (NSAttributedString *)transformedValue:(NSString *)value { + if (!value) { + return nil; + } + if ([value isKindOfClass:[NSAttributedString class]]) + value = [(NSAttributedString *)value string]; + return [[NSAttributedString alloc] initWithString:value attributes:@{NSFontAttributeName:[NSFont systemFontOfSize:15], NSForegroundColorAttributeName: [NSColor textColor]}]; +} + +- (NSString *)reverseTransformedValue:(NSAttributedString *)value { + if (!value) { + return nil; + } + if ([value isKindOfClass:[NSString class]]) + return (NSString *)value; + return [value string]; +} +@end diff --git a/Localizer/Source/Interface/StatisticsTextView.m b/Localizer/Source/Interface/StatisticsTextView.m index 20172a9..135f27b 100644 --- a/Localizer/Source/Interface/StatisticsTextView.m +++ b/Localizer/Source/Interface/StatisticsTextView.m @@ -11,22 +11,19 @@ @implementation StatisticsTextView -- (void)updateCurrentObjects -{ +- (void)updateCurrentObjects { [self willChangeValueForKey: @"currentObjects"]; [self didChangeValueForKey: @"currentObjects"]; } -- (NSArray *)currentObjects -{ +- (NSArray *)currentObjects { if ([[self delegate] respondsToSelector: @selector(currentObjectsInTextView:)]) return [(id)[self delegate] currentObjectsInTextView: self]; else return nil; } -- (NSArray *)currentLanguages -{ +- (NSArray *)currentLanguages { if ([[self delegate] respondsToSelector: @selector(currentLanguagesInTextView:)]) return [(id)[self delegate] currentLanguagesInTextView: self]; else diff --git a/Localizer/Source/Main Classes/Controller.m b/Localizer/Source/Main Classes/Controller.m index 6e7b1a1..8794083 100755 --- a/Localizer/Source/Main Classes/Controller.m +++ b/Localizer/Source/Main Classes/Controller.m @@ -10,7 +10,7 @@ #import "Document.h" #import "Preferences.h" - +#import "GSStringToAttributedValueTransformer.h" @implementation Controller @@ -21,6 +21,8 @@ - (void)awakeFromNib { [LILogWindow logWindow]; [[SUUpdater sharedUpdater] setDelegate: self]; + NSValueTransformer *transformer = [[GSStringToAttributedValueTransformer alloc] init]; + [NSValueTransformer setValueTransformer:transformer forName:@"GSStringToAttributedValueTransformer"]; } diff --git a/Localizer/Source/Main Classes/Editor.m b/Localizer/Source/Main Classes/Editor.m index 547929e..a0f1c3f 100755 --- a/Localizer/Source/Main Classes/Editor.m +++ b/Localizer/Source/Main Classes/Editor.m @@ -34,10 +34,10 @@ @implementation Editor + (void)initialize { - [super initialize]; - - BackgroundColorEditable = [NSColor whiteColor]; - BackgroundColorNotEditable = [NSColor colorWithDeviceWhite:0.95 alpha:1.0]; + [super initialize]; + + BackgroundColorEditable = [NSColor textBackgroundColor]; + BackgroundColorNotEditable = [NSColor controlBackgroundColor]; } - (id)init @@ -68,15 +68,14 @@ - (void)dealloc - (void)setUp { - [[leftEditor window] setBackgroundColor:[NSColor whiteColor]]; [document addObserver:self forKeyPath:@"selectedObject" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil]; [document addObserver:self forKeyPath:@"preferences.showTranslationProblems" options:0 context:@"ERROR"]; [[BLDictionaryController sharedInstance] addObserver:self forKeyPath:@"useDocuments" options:0 context:@"MATCH"]; [[BLDictionaryController sharedInstance] addObserver:self forKeyPath:@"availableKeys" options:0 context:@"MATCH"]; - [leftEditor bind:@"backgroundColor" toObject:self withKeyPath:@"leftBackgroundColor" options:nil]; - [rightEditor bind:@"backgroundColor" toObject:self withKeyPath:@"rightBackgroundColor" options:nil]; + [leftEditor bind:@"backgroundColor" toObject:self withKeyPath:@"leftBackgroundColor" options:nil]; + [rightEditor bind:@"backgroundColor" toObject:self withKeyPath:@"rightBackgroundColor" options:nil]; [leftEditor setTextContainerInset:NSMakeSize(25, 6)]; [rightEditor setTextContainerInset:NSMakeSize(10, 6)]; @@ -102,7 +101,7 @@ - (void)cleanUp - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (object == document && [keyPath isEqual: @"selectedObject"]) { + if (object == document && [keyPath isEqual: @"selectedObject"]) { // Remove observation id oldObject = [change objectForKey: NSKeyValueChangeOldKey]; if (oldObject != [NSNull null]) { @@ -113,15 +112,15 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N @catch (NSException *e) {} } - // Save changes + // Save changes NSWindow *window = [leftEditor window]; if ([window firstResponder] == leftEditor) [window endEditingFor: leftEditor]; if ([window firstResponder] == rightEditor) [window endEditingFor: rightEditor]; - - // Update contents - [self willChangeValueForKey: @"selectedObject"]; + + // Update contents + [self willChangeValueForKey: @"selectedObject"]; [self didChangeValueForKey: @"selectedObject"]; // Set rich text @@ -144,7 +143,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N if (context == @"ERROR" || context == @"content") [self notifyUpdateTranslationErrors]; if (context == @"content") { - [self willChangeValueForKey: @"selectedObject"]; + [self willChangeValueForKey: @"selectedObject"]; [self didChangeValueForKey: @"selectedObject"]; } @@ -161,18 +160,18 @@ - (Document *)document - (NSString *)comment { - if ([document selectedObject] != nil) - return [[document selectedObject] comment]; - else - return @""; + if ([document selectedObject] != nil) + return [[document selectedObject] comment]; + else + return @""; } - (void)setComment:(NSString *)aComment { - if ([document selectedObject] != nil) { - [[document selectedObject] setComment: aComment]; + if ([document selectedObject] != nil) { + [[document selectedObject] setComment: aComment]; [document updateChangeCount: NSChangeDone]; - } + } } + (NSSet *)keyPathsForValuesAffectingComment @@ -182,24 +181,24 @@ + (NSSet *)keyPathsForValuesAffectingComment - (id)valueForLeftLanguage { - if ([document selectedObject] != nil) - return [self valueForObject: [[document selectedObject] objectForLanguage: [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]]]; - else - return NSNoSelectionMarker; + if ([document selectedObject] != nil) + return [self valueForObject: [[document selectedObject] objectForLanguage: [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]]]; + else + return NSNoSelectionMarker; } - (void)setValueForLeftLanguage:(id)newValue { - id value; - - value = [self objectFromString:newValue withClass:[[[document selectedObject] class] classOfObjects]]; - - if ([document selectedObject] != nil && ![[[document selectedObject] objectForLanguage: [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]] isEqual: value]) { - [[document selectedObject] setObject:value forLanguage:[[document preferences] objectForKey: DocumentViewOptionLeftLanguage]]; + id value; + + value = [self objectFromString:newValue withClass:[[[document selectedObject] class] classOfObjects]]; + + if ([document selectedObject] != nil && ![[[document selectedObject] objectForLanguage: [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]] isEqual: value]) { + [[document selectedObject] setObject:value forLanguage:[[document preferences] objectForKey: DocumentViewOptionLeftLanguage]]; [document updateChangeCount: NSChangeDone]; [self notifyUpdateTranslationErrors]; - } + } } + (NSSet *)keyPathsForValuesAffectingValueForLeftLanguage @@ -209,23 +208,23 @@ + (NSSet *)keyPathsForValuesAffectingValueForLeftLanguage - (id)valueForRightLanguage { - if ([document selectedObject] != nil) - return [self valueForObject: [[document selectedObject] objectForLanguage: [[document preferences] objectForKey: DocumentViewOptionRightLanguage]]]; - else - return NSNoSelectionMarker; + if ([document selectedObject] != nil) + return [self valueForObject: [[document selectedObject] objectForLanguage: [[document preferences] objectForKey: DocumentViewOptionRightLanguage]]]; + else + return NSNoSelectionMarker; } - (void)setValueForRightLanguage:(id)newValue { - id value; - - value = [self objectFromString:newValue withClass:[[[document selectedObject] class] classOfObjects]]; - - if ([document selectedObject] != nil && ![[[document selectedObject] objectForLanguage: [[document preferences] objectForKey: DocumentViewOptionRightLanguage]] isEqual: value]) { - [[document selectedObject] setObject:value forLanguage:[[document preferences] objectForKey: DocumentViewOptionRightLanguage]]; + id value; + + value = [self objectFromString:newValue withClass:[[[document selectedObject] class] classOfObjects]]; + + if ([document selectedObject] != nil && ![[[document selectedObject] objectForLanguage: [[document preferences] objectForKey: DocumentViewOptionRightLanguage]] isEqual: value]) { + [[document selectedObject] setObject:value forLanguage:[[document preferences] objectForKey: DocumentViewOptionRightLanguage]]; [document updateChangeCount: NSChangeDone]; [self notifyUpdateTranslationErrors]; - } + } } + (NSSet *)keyPathsForValuesAffectingValueForRightLanguage @@ -242,19 +241,19 @@ - (void)updateMatches // Stop matcher if ([_matcher isRunning]) [_matcher stop]; - + // Only update of enabled if (!_matchingEnabled) return; // Get the languages - if ([self leftFieldEditable]) { - language = [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]; - refLanguage = [[document preferences] objectForKey: DocumentViewOptionRightLanguage]; - } else { - language = [[document preferences] objectForKey: DocumentViewOptionRightLanguage]; - refLanguage = [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]; - } + if ([self leftFieldEditable]) { + language = [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]; + refLanguage = [[document preferences] objectForKey: DocumentViewOptionRightLanguage]; + } else { + language = [[document preferences] objectForKey: DocumentViewOptionRightLanguage]; + refLanguage = [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]; + } // Reset results and restart matcher [self setMatches: nil]; @@ -285,7 +284,7 @@ - (void)addMatch:(LTKeyMatch *)match matches = [NSArray arrayWithObject: match]; self.matches = [matches sortedArrayUsingDescriptors: - [NSArray arrayWithObject: [[NSSortDescriptor alloc] initWithKey:@"matchPercentage" ascending:NO]]]; + [NSArray arrayWithObject: [[NSSortDescriptor alloc] initWithKey:@"matchPercentage" ascending:NO]]]; } } @@ -309,10 +308,10 @@ - (void)useMatchAtIndex:(NSUInteger)index - (void)useKeyMatch:(LTKeyMatch *)match { - if ([match matchPercentage] == 1.0) { - BLKeyObject *object = document.selectedObject; - [document selectNext: nil]; - + if ([match matchPercentage] == 1.0) { + BLKeyObject *object = document.selectedObject; + [document selectNext: nil]; + if ([self rightFieldEditable]) [object setObject:[match targetValue] forLanguage: [document.preferences objectForKey: DocumentViewOptionRightLanguage]]; else @@ -376,17 +375,17 @@ - (void)setUseDocuments:(BOOL)enabled - (void)updateTranslationErrors { NSString *language, *refLanguage; - + if (_errorsTimer) - _errorsTimer = nil; + _errorsTimer = nil; - if ([self leftFieldEditable]) { - language = [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]; - refLanguage = [[document preferences] objectForKey: DocumentViewOptionRightLanguage]; - } else { - language = [[document preferences] objectForKey: DocumentViewOptionRightLanguage]; - refLanguage = [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]; - } + if ([self leftFieldEditable]) { + language = [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]; + refLanguage = [[document preferences] objectForKey: DocumentViewOptionRightLanguage]; + } else { + language = [[document preferences] objectForKey: DocumentViewOptionRightLanguage]; + refLanguage = [[document preferences] objectForKey: DocumentViewOptionLeftLanguage]; + } if ([document selectedObject] && [[[document preferences] objectForKey: DocumentViewOptionShowProblems] boolValue]) [self setTranslationErrors: [LTTranslationChecker calculateTranslationErrorsForKeyObject:[document selectedObject] forLanguage:language withReference:refLanguage]]; @@ -402,11 +401,11 @@ - (void)notifyUpdateTranslationErrors - (IBAction)fixError:(id)sender { - LTTranslationProblem *problem; - - problem = [[errorsArrayController arrangedObjects] objectAtIndex: [sender clickedRow]]; + LTTranslationProblem *problem; + + problem = [[errorsArrayController arrangedObjects] objectAtIndex: [sender clickedRow]]; [problem fix]; - + [self beginEditing]; [self updateTranslationErrors]; } @@ -416,7 +415,7 @@ - (IBAction)fixError:(id)sender - (BOOL)leftFieldEditable { - return ![[[document preferences] objectForKey: DocumentViewOptionLeftLanguage] isEqual: [document referenceLanguage]]; + return ![[[document preferences] objectForKey: DocumentViewOptionLeftLanguage] isEqual: [document referenceLanguage]]; } + (NSSet *)keyPathsForValuesAffectingLeftFieldEditable @@ -426,7 +425,7 @@ + (NSSet *)keyPathsForValuesAffectingLeftFieldEditable - (BOOL)rightFieldEditable { - return ![[[document preferences] objectForKey: DocumentViewOptionRightLanguage] isEqual: [document referenceLanguage]]; + return ![[[document preferences] objectForKey: DocumentViewOptionRightLanguage] isEqual: [document referenceLanguage]]; } + (NSSet *)keyPathsForValuesAffectingRightFieldEditable @@ -436,10 +435,10 @@ + (NSSet *)keyPathsForValuesAffectingRightFieldEditable - (NSColor *)leftBackgroundColor { - if ([self leftFieldEditable]) - return BackgroundColorEditable; - else - return BackgroundColorNotEditable; + if ([self leftFieldEditable]) + return BackgroundColorEditable; + else + return BackgroundColorNotEditable; } + (NSSet *)keyPathsForValuesAffectingLeftBackgroundColor @@ -449,10 +448,10 @@ + (NSSet *)keyPathsForValuesAffectingLeftBackgroundColor - (NSColor *)rightBackgroundColor { - if ([self rightFieldEditable]) - return BackgroundColorEditable; - else - return BackgroundColorNotEditable; + if ([self rightFieldEditable]) + return BackgroundColorEditable; + else + return BackgroundColorNotEditable; } + (NSSet *)keyPathsForValuesAffectingRightBackgroundColor @@ -477,26 +476,32 @@ - (void)beginEditing - (NSAttributedString *)valueForObject:(id)object { - NSAttributedString *string = nil; - - if ([object isKindOfClass: [NSString class]]) - string = [[NSAttributedString alloc] initWithString: object]; - else if ([object isKindOfClass: [NSAttributedString class]]) - string = object; - - return string; + NSAttributedString *string = nil; + + if ([object isKindOfClass: [NSString class]]) + string = [[NSAttributedString alloc] initWithString: object]; + else if ([object isKindOfClass: [NSAttributedString class]]) + string = object; + + return string; } - (id)objectFromString:(NSAttributedString *)string withClass:(Class)class { - id object = nil; + id object = nil; + + if ([class isSubclassOfClass: [NSString class]]) { + if (![string isKindOfClass:class]) { + object = [string string]; + } + else { + object = string; + } + } + else if (class == [NSAttributedString class]) + object = string; - if ([class isSubclassOfClass: [NSString class]]) - object = [string string]; - else if (class == [NSAttributedString class]) - object = string; - - return object; + return object; } #pragma mark - Statistics