Coverts to Objective-C ARC.

This commit is contained in:
zonble 2021-02-28 21:30:10 +08:00
parent aa8f36b92f
commit 0f05e245a5
17 changed files with 154 additions and 121 deletions

View File

@ -821,6 +821,7 @@
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES; CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO; CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
@ -872,6 +873,7 @@
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES; CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO; CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6A0D4EA115FC0D2D00ABF4B3"
BuildableName = "McBopomofo.app"
BlueprintName = "McBopomofo"
ReferencedContainer = "container:McBopomofo.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6A0D4EA115FC0D2D00ABF4B3"
BuildableName = "McBopomofo.app"
BlueprintName = "McBopomofo"
ReferencedContainer = "container:McBopomofo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6A0D4EA115FC0D2D00ABF4B3"
BuildableName = "McBopomofo.app"
BlueprintName = "McBopomofo"
ReferencedContainer = "container:McBopomofo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -39,7 +39,6 @@
@interface AppDelegate : NSObject <NSApplicationDelegate> @interface AppDelegate : NSObject <NSApplicationDelegate>
{ {
@private @private
NSWindow *_window;
NSURLConnection *_updateCheckConnection; NSURLConnection *_updateCheckConnection;
BOOL _currentUpdateCheckIsForced; BOOL _currentUpdateCheckIsForced;
NSMutableData *_receivingData; NSMutableData *_receivingData;
@ -51,5 +50,5 @@
- (void)checkForUpdateForced:(BOOL)forced; - (void)checkForUpdateForced:(BOOL)forced;
- (void)showPreferences; - (void)showPreferences;
@property (assign, nonatomic) IBOutlet NSWindow *window; @property (weak, nonatomic) IBOutlet NSWindow *window;
@end @end

View File

@ -53,9 +53,8 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
- (void)dealloc - (void)dealloc
{ {
[_preferencesWindowController release]; _preferencesWindowController = nil;
[_updateCheckConnection release]; _updateCheckConnection = nil;
[super dealloc];
} }
- (void)applicationDidFinishLaunching:(NSNotification *)inNotification - (void)applicationDidFinishLaunching:(NSNotification *)inNotification
@ -124,7 +123,6 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
#endif #endif
if (_receivingData) { if (_receivingData) {
[_receivingData release];
_receivingData = nil; _receivingData = nil;
} }
@ -147,9 +145,7 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
{ {
BOOL isForcedCheck = _currentUpdateCheckIsForced; BOOL isForcedCheck = _currentUpdateCheckIsForced;
[_receivingData release];
_receivingData = nil; _receivingData = nil;
[_updateCheckConnection release];
_updateCheckConnection = nil; _updateCheckConnection = nil;
_currentUpdateCheckIsForced = NO; _currentUpdateCheckIsForced = NO;
@ -172,9 +168,7 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
BOOL isForcedCheck = _currentUpdateCheckIsForced; BOOL isForcedCheck = _currentUpdateCheckIsForced;
[_receivingData release];
_receivingData = nil; _receivingData = nil;
[_updateCheckConnection release];
_updateCheckConnection = nil; _updateCheckConnection = nil;
_currentUpdateCheckIsForced = NO; _currentUpdateCheckIsForced = NO;
@ -226,9 +220,7 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
} }
return; return;
} }
[_updateNextStepURL release]; _updateNextStepURL = siteInfoURL;
_updateNextStepURL = nil;
_updateNextStepURL = [siteInfoURL retain];
NSDictionary *versionDescriptions = [plist objectForKey:@"Description"]; NSDictionary *versionDescriptions = [plist objectForKey:@"Description"];
NSString *versionDescription = @""; NSString *versionDescription = @"";
@ -268,13 +260,11 @@ static const NSTimeInterval kTimeoutInterval = 60.0;
[[NSWorkspace sharedWorkspace] openURL:_updateNextStepURL]; [[NSWorkspace sharedWorkspace] openURL:_updateNextStepURL];
} }
[_updateNextStepURL release];
_updateNextStepURL = nil; _updateNextStepURL = nil;
} }
- (void)nonModalAlertWindowControllerDidCancel:(OVNonModalAlertWindowController *)controller - (void)nonModalAlertWindowControllerDidCancel:(OVNonModalAlertWindowController *)controller
{ {
[_updateNextStepURL release];
_updateNextStepURL = nil; _updateNextStepURL = nil;
} }

View File

@ -56,7 +56,7 @@
- (NSUInteger)candidateIndexAtKeyLabelIndex:(NSUInteger)index; - (NSUInteger)candidateIndexAtKeyLabelIndex:(NSUInteger)index;
@property (assign, weak, nonatomic) id<VTCandidateControllerDelegate> delegate; @property (weak, nonatomic) id<VTCandidateControllerDelegate> delegate;
@property (assign, nonatomic) NSUInteger selectedCandidateIndex; @property (assign, nonatomic) NSUInteger selectedCandidateIndex;
@property (assign, nonatomic) BOOL visible; @property (assign, nonatomic) BOOL visible;

View File

@ -36,10 +36,9 @@
- (void)dealloc - (void)dealloc
{ {
[_keyLabels release]; _keyLabels = nil;
[_keyLabelFont release]; _keyLabelFont = nil;
[_candidateFont release]; _candidateFont = nil;
[super dealloc];
} }
- (id)initWithWindow:(NSWindow *)window - (id)initWithWindow:(NSWindow *)window
@ -47,11 +46,10 @@
self = [super initWithWindow:window]; self = [super initWithWindow:window];
if (self) { if (self) {
// populate the default values // populate the default values
_keyLabels = [[NSArray arrayWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", nil] retain]; _keyLabels = @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9"];
_keyLabelFont = [[NSFont systemFontOfSize:14.0] retain]; _keyLabelFont = [NSFont systemFontOfSize:14.0];
_candidateFont = [[NSFont systemFontOfSize:18.0] retain]; _candidateFont = [NSFont systemFontOfSize:18.0];
} }
return self; return self;
} }

View File

@ -40,10 +40,9 @@
- (void)dealloc - (void)dealloc
{ {
[_candidateView release]; _candidateView = nil;
[_prevPageButton release]; _prevPageButton = nil;
[_nextPageButton release]; _nextPageButton = nil;
[super dealloc];
} }
- (id)init - (id)init
@ -51,7 +50,7 @@
NSRect contentRect = NSMakeRect(128.0, 128.0, 0.0, 0.0); NSRect contentRect = NSMakeRect(128.0, 128.0, 0.0, 0.0);
NSUInteger styleMask = NSBorderlessWindowMask | NSNonactivatingPanelMask; NSUInteger styleMask = NSBorderlessWindowMask | NSNonactivatingPanelMask;
NSPanel *panel = [[[NSPanel alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:NO] autorelease]; NSPanel *panel = [[NSPanel alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
[panel setLevel:kCGPopUpMenuWindowLevel]; [panel setLevel:kCGPopUpMenuWindowLevel];
[panel setHasShadow:YES]; [panel setHasShadow:YES];

View File

@ -50,5 +50,5 @@
@property (readonly, nonatomic) NSSize sizeForView; @property (readonly, nonatomic) NSSize sizeForView;
@property (assign, nonatomic) NSUInteger highlightedIndex; @property (assign, nonatomic) NSUInteger highlightedIndex;
@property (assign, nonatomic) SEL action; @property (assign, nonatomic) SEL action;
@property (weak, assign, nonatomic) id target; @property (weak, nonatomic) id target;
@end @end

View File

@ -39,26 +39,18 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
- (void)dealloc - (void)dealloc
{ {
[_keyLabels release]; _keyLabels = nil;
[_displayedCandidates release]; _displayedCandidates = nil;
[_keyLabelAttrDict release]; _keyLabelAttrDict = nil;
[_candidateAttrDict release]; _candidateAttrDict = nil;
[_elementWidths release]; _elementWidths = nil;
[super dealloc];
} }
- (void)setKeyLabels:(NSArray *)labels displayedCandidates:(NSArray *)candidates - (void)setKeyLabels:(NSArray *)labels displayedCandidates:(NSArray *)candidates
{ {
NSUInteger count = min([labels count], [candidates count]); NSUInteger count = min([labels count], [candidates count]);
id tmp; _keyLabels = [labels subarrayWithRange:NSMakeRange(0, count)];
_displayedCandidates = [candidates subarrayWithRange:NSMakeRange(0, count)];
tmp = _keyLabels;
_keyLabels = [[labels subarrayWithRange:NSMakeRange(0, count)] retain];
[tmp release];
tmp = _displayedCandidates;
_displayedCandidates = [[candidates subarrayWithRange:NSMakeRange(0, count)] retain];
[tmp release];
NSMutableArray *newWidths = [NSMutableArray array]; NSMutableArray *newWidths = [NSMutableArray array];
@ -72,32 +64,24 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
[newWidths addObject:[NSNumber numberWithDouble:width]]; [newWidths addObject:[NSNumber numberWithDouble:width]];
} }
tmp = _elementWidths; _elementWidths = newWidths;
_elementWidths = [newWidths retain];
[tmp release];
} }
- (void)setKeyLabelFont:(NSFont *)labelFont candidateFont:(NSFont *)candidateFont - (void)setKeyLabelFont:(NSFont *)labelFont candidateFont:(NSFont *)candidateFont
{ {
NSMutableParagraphStyle *paraStyle = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease]; NSMutableParagraphStyle *paraStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paraStyle setAlignment:NSCenterTextAlignment]; [paraStyle setAlignment:NSCenterTextAlignment];
id tmp; _keyLabelAttrDict = [NSDictionary dictionaryWithObjectsAndKeys:
tmp = _keyLabelAttrDict;
_keyLabelAttrDict = [[NSDictionary dictionaryWithObjectsAndKeys:
labelFont, NSFontAttributeName, labelFont, NSFontAttributeName,
paraStyle, NSParagraphStyleAttributeName, paraStyle, NSParagraphStyleAttributeName,
[NSColor blackColor], NSForegroundColorAttributeName, [NSColor blackColor], NSForegroundColorAttributeName,
nil] retain]; nil];
[tmp release]; _candidateAttrDict = [NSDictionary dictionaryWithObjectsAndKeys:
tmp = _candidateAttrDict;
_candidateAttrDict = [[NSDictionary dictionaryWithObjectsAndKeys:
candidateFont, NSFontAttributeName, candidateFont, NSFontAttributeName,
paraStyle, NSParagraphStyleAttributeName, paraStyle, NSParagraphStyleAttributeName,
[NSColor textColor], NSForegroundColorAttributeName, [NSColor textColor], NSForegroundColorAttributeName,
nil] retain]; nil];
[tmp release];
CGFloat labelFontSize = [labelFont pointSize]; CGFloat labelFontSize = [labelFont pointSize];
CGFloat candidateFontSize = [candidateFont pointSize]; CGFloat candidateFontSize = [candidateFont pointSize];
@ -165,7 +149,7 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
if (index == _highlightedIndex) { if (index == _highlightedIndex) {
[[NSColor selectedTextBackgroundColor] setFill]; [[NSColor selectedTextBackgroundColor] setFill];
activeCandidateAttr = [[_candidateAttrDict mutableCopy] autorelease]; activeCandidateAttr = [_candidateAttrDict mutableCopy];
[(NSMutableDictionary *)activeCandidateAttr setObject:[NSColor selectedTextColor] forKey:NSForegroundColorAttributeName]; [(NSMutableDictionary *)activeCandidateAttr setObject:[NSColor selectedTextColor] forKey:NSForegroundColorAttributeName];
} }
else { else {
@ -230,9 +214,12 @@ NS_INLINE CGFloat max(CGFloat a, CGFloat b) { return a > b ? a : b; }
_trackingHighlightedIndex = 0; _trackingHighlightedIndex = 0;
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (triggerAction && _target && _action) { if (triggerAction && _target && _action) {
[_target performSelector:_action withObject:self]; [_target performSelector:_action withObject:self];
} }
# pragma clang diagnostic pop
} }
@end @end

View File

@ -57,21 +57,13 @@ static const CGFloat kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0;
CGFloat _candidateTextLeftMargin; CGFloat _candidateTextLeftMargin;
} }
- (void)dealloc
{
[_candidateTextParagraphStyle release];
[_keyLabelStripView release];
[_scrollView release];
[_tableView release];
[super dealloc];
}
- (id)init - (id)init
{ {
NSRect contentRect = NSMakeRect(128.0, 128.0, 0.0, 0.0); NSRect contentRect = NSMakeRect(128.0, 128.0, 0.0, 0.0);
NSUInteger styleMask = NSBorderlessWindowMask | NSNonactivatingPanelMask; NSUInteger styleMask = NSBorderlessWindowMask | NSNonactivatingPanelMask;
NSPanel *panel = [[[NSPanel alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:NO] autorelease]; NSPanel *panel = [[NSPanel alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
[panel setLevel:kCGPopUpMenuWindowLevel]; [panel setLevel:kCGPopUpMenuWindowLevel];
[panel setHasShadow:YES]; [panel setHasShadow:YES];
@ -100,8 +92,8 @@ static const CGFloat kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0;
[_tableView setDataSource:self]; [_tableView setDataSource:self];
[_tableView setDelegate:self]; [_tableView setDelegate:self];
NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"candidate"] autorelease]; NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"candidate"];
[column setDataCell:[[[NSTextFieldCell alloc] init] autorelease]]; [column setDataCell:[[NSTextFieldCell alloc] init]];
[column setEditable:NO]; [column setEditable:NO];
_candidateTextPadding = kCandidateTextPadding; _candidateTextPadding = kCandidateTextPadding;
@ -238,7 +230,7 @@ static const CGFloat kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0;
candidate = [_delegate candidateController:self candidateAtIndex:row]; candidate = [_delegate candidateController:self candidateAtIndex:row];
} }
NSAttributedString *attrString = [[[NSAttributedString alloc] initWithString:candidate attributes:[NSDictionary dictionaryWithObjectsAndKeys:_candidateFont, NSFontAttributeName, _candidateTextParagraphStyle, NSParagraphStyleAttributeName, nil]] autorelease]; NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:candidate attributes:[NSDictionary dictionaryWithObjectsAndKeys:_candidateFont, NSFontAttributeName, _candidateTextParagraphStyle, NSParagraphStyleAttributeName, nil]];
// we do more work than what this method is expected to; normally not a good practice, but for the amount of data (9 to 10 rows max), we can afford the overhead // we do more work than what this method is expected to; normally not a good practice, but for the amount of data (9 to 10 rows max), we can afford the overhead

View File

@ -35,9 +35,8 @@
- (void)dealloc - (void)dealloc
{ {
[_keyLabelFont release]; _keyLabelFont = nil;
[_keyLabels release]; _keyLabels = nil;
[super dealloc];
} }
- (id)initWithFrame:(NSRect)frameRect - (id)initWithFrame:(NSRect)frameRect
@ -71,7 +70,7 @@
NSColor *darkGray = [NSColor colorWithDeviceWhite:0.7 alpha:1.0]; NSColor *darkGray = [NSColor colorWithDeviceWhite:0.7 alpha:1.0];
NSColor *lightGray = [NSColor colorWithDeviceWhite:0.8 alpha:1.0]; NSColor *lightGray = [NSColor colorWithDeviceWhite:0.8 alpha:1.0];
NSMutableParagraphStyle *style = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease]; NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setAlignment:NSCenterTextAlignment]; [style setAlignment:NSCenterTextAlignment];
NSDictionary *textAttr = [NSDictionary dictionaryWithObjectsAndKeys: NSDictionary *textAttr = [NSDictionary dictionaryWithObjectsAndKeys:

View File

@ -160,14 +160,11 @@ public:
delete _builder; delete _builder;
} }
[_composingBuffer release];
[_candidates release];
// the two client pointers are weak pointers (i.e. we don't retain them) // the two client pointers are weak pointers (i.e. we don't retain them)
// therefore we don't do anything about it // therefore we don't do anything about it
[super dealloc];
} }
- (id)initWithServer:(IMKServer *)server delegate:(id)delegate client:(id)client - (id)initWithServer:(IMKServer *)server delegate:(id)delegate client:(id)client
@ -206,8 +203,8 @@ public:
- (NSMenu *)menu - (NSMenu *)menu
{ {
// a menu instance (autoreleased) is requested every time the user click on the input menu // a menu instance (autoreleased) is requested every time the user click on the input menu
NSMenu *menu = [[[NSMenu alloc] initWithTitle:LocalizationNotNeeded(@"Input Method Menu")] autorelease]; NSMenu *menu = [[NSMenu alloc] initWithTitle:LocalizationNotNeeded(@"Input Method Menu")];
NSMenuItem *preferenceMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"McBopomofo Preferences", @"") action:@selector(showPreferences:) keyEquivalent:@""] autorelease]; NSMenuItem *preferenceMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"McBopomofo Preferences", @"") action:@selector(showPreferences:) keyEquivalent:@""];
[menu addItem:preferenceMenuItem]; [menu addItem:preferenceMenuItem];
// If Option key is pressed, show the learning-related menu // If Option key is pressed, show the learning-related menu
@ -218,7 +215,7 @@ public:
BOOL learningEnabled = ![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning]; BOOL learningEnabled = ![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning];
NSMenuItem *learnMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Enable Selection Learning", @"") action:@selector(toggleLearning:) keyEquivalent:@""] autorelease]; NSMenuItem *learnMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Enable Selection Learning", @"") action:@selector(toggleLearning:) keyEquivalent:@""];
if (learningEnabled) { if (learningEnabled) {
[learnMenuItem setState:NSOnState]; [learnMenuItem setState:NSOnState];
} }
@ -230,20 +227,20 @@ public:
if (learningEnabled) { if (learningEnabled) {
NSString *clearMenuItemTitle = [NSString stringWithFormat:NSLocalizedString(@"Clear Learning Dictionary (%ju Items)", @""), (uintmax_t)[gCandidateLearningDictionary count]]; NSString *clearMenuItemTitle = [NSString stringWithFormat:NSLocalizedString(@"Clear Learning Dictionary (%ju Items)", @""), (uintmax_t)[gCandidateLearningDictionary count]];
NSMenuItem *clearMenuItem = [[[NSMenuItem alloc] initWithTitle:clearMenuItemTitle action:@selector(clearLearningDictionary:) keyEquivalent:@""] autorelease]; NSMenuItem *clearMenuItem = [[NSMenuItem alloc] initWithTitle:clearMenuItemTitle action:@selector(clearLearningDictionary:) keyEquivalent:@""];
[menu addItem:clearMenuItem]; [menu addItem:clearMenuItem];
NSMenuItem *dumpMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Dump Learning Data to Console", @"") action:@selector(dumpLearningDictionary:) keyEquivalent:@""] autorelease]; NSMenuItem *dumpMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Dump Learning Data to Console", @"") action:@selector(dumpLearningDictionary:) keyEquivalent:@""];
[menu addItem:dumpMenuItem]; [menu addItem:dumpMenuItem];
} }
} }
#endif //DEBUG #endif //DEBUG
NSMenuItem *updateCheckItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Check for Updates…", @"") action:@selector(checkForUpdate:) keyEquivalent:@""] autorelease]; NSMenuItem *updateCheckItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Check for Updates…", @"") action:@selector(checkForUpdate:) keyEquivalent:@""];
[menu addItem:updateCheckItem]; [menu addItem:updateCheckItem];
NSMenuItem *aboutMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About McBopomofo…", @"") action:@selector(showAbout:) keyEquivalent:@""] autorelease]; NSMenuItem *aboutMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About McBopomofo…", @"") action:@selector(showAbout:) keyEquivalent:@""];
[menu addItem:aboutMenuItem]; [menu addItem:aboutMenuItem];
return menu; return menu;
@ -464,7 +461,7 @@ public:
NSDictionary *attrDict = [NSDictionary dictionaryWithObjectsAndKeys: NSDictionary *attrDict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName, [NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
[NSNumber numberWithInt:0], NSMarkedClauseSegmentAttributeName, nil]; [NSNumber numberWithInt:0], NSMarkedClauseSegmentAttributeName, nil];
NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:composedText attributes:attrDict] autorelease]; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:composedText attributes:attrDict];
// the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound, // the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound,
// i.e. the client app needs to take care of where to put ths composing buffer // i.e. the client app needs to take care of where to put ths composing buffer
@ -1540,7 +1537,7 @@ void LTLoadLanguageModel()
// TODO: Change this // TODO: Change this
NSString *userDictFile = [userDictPath stringByAppendingPathComponent:@"UserCandidatesCache.plist"]; NSString *userDictFile = [userDictPath stringByAppendingPathComponent:@"UserCandidatesCache.plist"];
gUserCandidatesDictionaryPath = [userDictFile retain]; gUserCandidatesDictionaryPath = userDictFile;
exists = [[NSFileManager defaultManager] fileExistsAtPath:userDictFile isDirectory:&isDir]; exists = [[NSFileManager defaultManager] fileExistsAtPath:userDictFile isDirectory:&isDir];
if (exists && !isDir) { if (exists && !isDir) {

View File

@ -31,7 +31,8 @@
+ (NSArray *)allInstalledInputSources + (NSArray *)allInstalledInputSources
{ {
CFArrayRef list = TISCreateInputSourceList(NULL, true); CFArrayRef list = TISCreateInputSourceList(NULL, true);
return [NSMakeCollectable(list) autorelease]; return (__bridge NSArray *)list;
// return [NSMakeCollectable(list) autorelease];
} }
+ (TISInputSourceRef)inputSourceForProperty:(CFStringRef)inPropertyKey stringValue:(NSString *)inValue + (TISInputSourceRef)inputSourceForProperty:(CFStringRef)inPropertyKey stringValue:(NSString *)inValue
@ -39,16 +40,15 @@
CFTypeID stringID = CFStringGetTypeID(); CFTypeID stringID = CFStringGetTypeID();
for (id source in [self allInstalledInputSources]) { for (id source in [self allInstalledInputSources]) {
CFTypeRef property = TISGetInputSourceProperty((TISInputSourceRef)source, inPropertyKey); CFTypeRef property = TISGetInputSourceProperty((__bridge TISInputSourceRef)source, inPropertyKey);
if (!property || CFGetTypeID(property) != stringID) { if (!property || CFGetTypeID(property) != stringID) {
continue; continue;
} }
if (inValue && [inValue compare:(NSString *)property] == NSOrderedSame) { if (inValue && [inValue compare:(__bridge NSString *)property] == NSOrderedSame) {
return (TISInputSourceRef)source; return (__bridge TISInputSourceRef)source;
} }
} }
return NULL; return NULL;
} }
@ -74,9 +74,9 @@
BOOL enabled = NO; BOOL enabled = NO;
for (id source in [self allInstalledInputSources]) { for (id source in [self allInstalledInputSources]) {
TISInputSourceRef inputSource = (TISInputSourceRef)source; TISInputSourceRef inputSource = (__bridge TISInputSourceRef)source;
NSString *bundleID = (NSString *)TISGetInputSourceProperty(inputSource, kTISPropertyBundleID); NSString *bundleID = (__bridge NSString *)TISGetInputSourceProperty(inputSource, kTISPropertyBundleID);
NSString *mode = (NSString *)TISGetInputSourceProperty(inputSource, kTISPropertyInputModeID); NSString *mode = (NSString *)CFBridgingRelease(TISGetInputSourceProperty(inputSource, kTISPropertyInputModeID));
if (mode && [bundleID isEqualToString:inID]) { if (mode && [bundleID isEqualToString:inID]) {
BOOL modeEnabled = [self enableInputSource:inputSource]; BOOL modeEnabled = [self enableInputSource:inputSource];
if (!modeEnabled) { if (!modeEnabled) {
@ -98,7 +98,7 @@
+ (BOOL)registerInputSource:(NSURL *)inBundleURL + (BOOL)registerInputSource:(NSURL *)inBundleURL
{ {
OSStatus status = TISRegisterInputSource((CFURLRef)inBundleURL); OSStatus status = TISRegisterInputSource((__bridge CFURLRef)inBundleURL);
return status == noErr; return status == noErr;
} }
@end @end

View File

@ -20,11 +20,11 @@
@interface OVNonModalAlertWindowController : NSWindowController @interface OVNonModalAlertWindowController : NSWindowController
{ {
@private @private
NSTextField *_titleTextField; // NSTextField *_titleTextField;
NSTextField *_contentTextField; // NSTextField *_contentTextField;
NSButton *_confirmButton; // NSButton *_confirmButton;
NSButton *_cancelButton; // NSButton *_cancelButton;
id<OVNonModalAlertWindowControllerDelegate> _delegate; // id<OVNonModalAlertWindowControllerDelegate> _delegate;
} }
+ (OVNonModalAlertWindowController *)sharedInstance; + (OVNonModalAlertWindowController *)sharedInstance;

View File

@ -36,10 +36,10 @@
@interface PreferencesWindowController : NSWindowController @interface PreferencesWindowController : NSWindowController
{ {
@private @private
NSPopUpButton *_fontSizePopUpButton; NSPopUpButton *__weak _fontSizePopUpButton;
NSPopUpButton *_basisKeyboardLayoutButton; NSPopUpButton *__weak _basisKeyboardLayoutButton;
} }
- (IBAction)updateBasisKeyboardLayoutAction:(id)sender; - (IBAction)updateBasisKeyboardLayoutAction:(id)sender;
@property (assign, nonatomic) IBOutlet NSPopUpButton *fontSizePopUpButton; @property (weak, nonatomic) IBOutlet NSPopUpButton *fontSizePopUpButton;
@property (assign, nonatomic) IBOutlet NSPopUpButton *basisKeyboardLayoutButton; @property (weak, nonatomic) IBOutlet NSPopUpButton *basisKeyboardLayoutButton;
@end @end

View File

@ -68,10 +68,10 @@ static NSString *const kBasisKeyboardLayoutPreferenceKey = @"BasisKeyboardLayout
continue; continue;
} }
NSString *sourceID = (NSString *)TISGetInputSourceProperty(source, kTISPropertyInputSourceID); NSString *sourceID = (__bridge NSString *)TISGetInputSourceProperty(source, kTISPropertyInputSourceID);
NSString *localizedName = (NSString *)TISGetInputSourceProperty(source, kTISPropertyLocalizedName); NSString *localizedName = (__bridge NSString *)TISGetInputSourceProperty(source, kTISPropertyLocalizedName);
NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; NSMenuItem *item = [[NSMenuItem alloc] init];
[item setTitle:localizedName]; [item setTitle:localizedName];
[item setRepresentedObject:sourceID]; [item setRepresentedObject:sourceID];

View File

@ -39,7 +39,7 @@ static NSString *const kConnectionName = @"McBopomofo_1_Connection";
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @autoreleasepool {
// register and enable the input source (along with all its input modes) // register and enable the input source (along with all its input modes)
if (argc > 1 && !strcmp(argv[1], "install")) { if (argc > 1 && !strcmp(argv[1], "install")) {
@ -64,7 +64,6 @@ int main(int argc, char *argv[])
if (!status) { if (!status) {
NSLog(@"Fatal error: Cannot register input source %@ at %@.", bundleID, [bundleURL absoluteString]); NSLog(@"Fatal error: Cannot register input source %@ at %@.", bundleID, [bundleURL absoluteString]);
[pool drain];
return -1; return -1;
} }
@ -72,7 +71,6 @@ int main(int argc, char *argv[])
// if it still doesn't register successfully, bail. // if it still doesn't register successfully, bail.
if (!inputSource) { if (!inputSource) {
NSLog(@"Fatal error: Cannot find input source %@ after registration.", bundleID); NSLog(@"Fatal error: Cannot find input source %@ after registration.", bundleID);
[pool drain];
return -1; return -1;
} }
} }
@ -84,12 +82,10 @@ int main(int argc, char *argv[])
if (!status) { if (!status) {
NSLog(@"Fatal error: Cannot enable input source %@.", bundleID); NSLog(@"Fatal error: Cannot enable input source %@.", bundleID);
[pool drain];
return -1; return -1;
} }
if (![OVInputSourceHelper inputSourceEnabled:inputSource]){ if (![OVInputSourceHelper inputSourceEnabled:inputSource]){
NSLog(@"Fatal error: Cannot enable input source %@.", bundleID); NSLog(@"Fatal error: Cannot enable input source %@.", bundleID);
[pool drain];
return -1; return -1;
} }
} }
@ -110,26 +106,22 @@ int main(int argc, char *argv[])
NSString *mainNibName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"NSMainNibFile"]; NSString *mainNibName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"NSMainNibFile"];
if (!mainNibName) { if (!mainNibName) {
NSLog(@"Fatal error: NSMainNibFile key not defined in Info.plist."); NSLog(@"Fatal error: NSMainNibFile key not defined in Info.plist.");
[pool drain];
return -1; return -1;
} }
BOOL loadResult = [[NSBundle mainBundle] loadNibNamed:mainNibName owner:[NSApplication sharedApplication] topLevelObjects:NULL]; BOOL loadResult = [[NSBundle mainBundle] loadNibNamed:mainNibName owner:[NSApplication sharedApplication] topLevelObjects:NULL];
if (!loadResult) { if (!loadResult) {
NSLog(@"Fatal error: Cannot load %@.", mainNibName); NSLog(@"Fatal error: Cannot load %@.", mainNibName);
[pool drain];
return -1; return -1;
} }
IMKServer *server = [[IMKServer alloc] initWithName:kConnectionName bundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]]; IMKServer *server = [[IMKServer alloc] initWithName:kConnectionName bundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
if (!server) { if (!server) {
NSLog(@"Fatal error: Cannot initialize input method server with connection %@.", kConnectionName); NSLog(@"Fatal error: Cannot initialize input method server with connection %@.", kConnectionName);
[pool drain];
return -1; return -1;
} }
[[NSApplication sharedApplication] run]; [[NSApplication sharedApplication] run];
[server release]; }
[pool drain];
return 0; return 0;
} }