Merge pull request #167 from zonble/master

Add Chinese conversion function by bridging SwiftyOpenCC
This commit is contained in:
Weizhong Yang a.k.a zonble 2021-11-11 00:31:51 +08:00 committed by GitHub
commit c9f3e02f2c
30 changed files with 419 additions and 210 deletions

View File

@ -6,10 +6,10 @@ jobs:
name: Build
runs-on: macOS-latest
env:
DEVELOPER_DIR: /Applications/Xcode_11.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_12.app/Contents/Developer
steps:
- uses: actions/checkout@v1
- name: Clean
run: xcodebuild -target McBopomofo -configuration Release clean
run: xcodebuild -scheme McBopomofo -configuration Release clean
- name: Build
run: xcodebuild -target McBopomofo -configuration Release
run: xcodebuild -scheme McBopomofo -configuration Release

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ Credits.rtf
# the executable we used to count the occurance of a string in a file
# that can be built by make -C Source/Data/bin/C_Version
# C_count.occ.exe
.idea

View File

@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 52;
objects = {
/* Begin PBXBuildFile section */
@ -33,7 +33,6 @@
6A2E40F9253A6AA000D1AE1D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A2E40F5253A69DA00D1AE1D /* Images.xcassets */; };
6A38BC1515FC117A00A8A51F /* data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A38BBF615FC117A00A8A51F /* data.txt */; };
6A38BC2815FC158A00A8A51F /* InputMethodKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A38BC2715FC158A00A8A51F /* InputMethodKit.framework */; };
6A38BC2A15FC161000A8A51F /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A38BC2915FC161000A8A51F /* Carbon.framework */; };
6ACA41CD15FC1D7500935EF6 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */; };
6ACA41F915FC1D9000935EF6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ACA41E915FC1D9000935EF6 /* AppDelegate.m */; };
6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EA15FC1D9000935EF6 /* InfoPlist.strings */; };
@ -47,6 +46,8 @@
6AE210B315FC63CC003659FE /* PlainBopomofo@2x.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 6AE210B115FC63CC003659FE /* PlainBopomofo@2x.tiff */; };
6AFF97F2253B299E007F1C49 /* OVNonModalAlertWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6AFF97F0253B299E007F1C49 /* OVNonModalAlertWindowController.xib */; };
6AFF97F3253B299E007F1C49 /* OVNonModalAlertWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AFF97F1253B299E007F1C49 /* OVNonModalAlertWindowController.m */; };
D427A9C125ED28CC005D43E0 /* OpenCCBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */; };
D48550A325EBE689006A204C /* OpenCC in Frameworks */ = {isa = PBXBuildFile; productRef = D48550A225EBE689006A204C /* OpenCC */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -188,7 +189,6 @@
6A38BBFC15FC117A00A8A51F /* PhraseFreq.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PhraseFreq.txt; sourceTree = "<group>"; };
6A38BBFD15FC117A00A8A51F /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
6A38BC2715FC158A00A8A51F /* InputMethodKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = InputMethodKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/InputMethodKit.framework; sourceTree = DEVELOPER_DIR; };
6A38BC2915FC161000A8A51F /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Carbon.framework; sourceTree = DEVELOPER_DIR; };
6ACA41CB15FC1D7500935EF6 /* McBopomofoInstaller.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = McBopomofoInstaller.app; sourceTree = BUILT_PRODUCTS_DIR; };
6ACA41E815FC1D9000935EF6 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = Source/Installer/AppDelegate.h; sourceTree = SOURCE_ROOT; };
6ACA41E915FC1D9000935EF6 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = Source/Installer/AppDelegate.m; sourceTree = SOURCE_ROOT; };
@ -208,6 +208,8 @@
6AFF97EF253B299E007F1C49 /* OVNonModalAlertWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OVNonModalAlertWindowController.h; sourceTree = "<group>"; };
6AFF97F0253B299E007F1C49 /* OVNonModalAlertWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = OVNonModalAlertWindowController.xib; sourceTree = "<group>"; };
6AFF97F1253B299E007F1C49 /* OVNonModalAlertWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OVNonModalAlertWindowController.m; sourceTree = "<group>"; };
D427A9BF25ED28CC005D43E0 /* McBopomofo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "McBopomofo-Bridging-Header.h"; sourceTree = "<group>"; };
D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenCCBridge.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -215,8 +217,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6A38BC2A15FC161000A8A51F /* Carbon.framework in Frameworks */,
6A38BC2815FC158A00A8A51F /* InputMethodKit.framework in Frameworks */,
D48550A325EBE689006A204C /* OpenCC in Frameworks */,
6A0D4EA715FC0D2D00ABF4B3 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -254,7 +256,6 @@
isa = PBXGroup;
children = (
6A0D4EA915FC0D2D00ABF4B3 /* AppKit.framework */,
6A38BC2915FC161000A8A51F /* Carbon.framework */,
6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */,
6A0D4EAB15FC0D2D00ABF4B3 /* Foundation.framework */,
6A38BC2715FC158A00A8A51F /* InputMethodKit.framework */,
@ -282,6 +283,8 @@
6A0D4ECA15FC0D6400ABF4B3 /* OVInputSourceHelper.m */,
6A0D4ECB15FC0D6400ABF4B3 /* PreferencesWindowController.h */,
6A0D4ECC15FC0D6400ABF4B3 /* PreferencesWindowController.m */,
D427A9C025ED28CC005D43E0 /* OpenCCBridge.swift */,
D427A9BF25ED28CC005D43E0 /* McBopomofo-Bridging-Header.h */,
);
path = Source;
sourceTree = "<group>";
@ -509,6 +512,9 @@
6A38BC2615FC131100A8A51F /* PBXTargetDependency */,
);
name = McBopomofo;
packageProductDependencies = (
D48550A225EBE689006A204C /* OpenCC */,
);
productName = McBopomofo;
productReference = 6A0D4EA215FC0D2D00ABF4B3 /* McBopomofo.app */;
productType = "com.apple.product-type.application";
@ -539,6 +545,11 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1220;
TargetAttributes = {
6A0D4EA115FC0D2D00ABF4B3 = {
LastSwiftMigration = 1240;
};
};
};
buildConfigurationList = 6A0D4E9715FC0CFA00ABF4B3 /* Build configuration list for PBXProject "McBopomofo" */;
compatibilityVersion = "Xcode 3.2";
@ -550,6 +561,9 @@
Base,
);
mainGroup = 6A0D4E9215FC0CFA00ABF4B3;
packageReferences = (
D48550A125EBE689006A204C /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */,
);
productRefGroup = 6A0D4EA315FC0D2D00ABF4B3 /* Products */;
projectDirPath = "";
projectRoot = "";
@ -634,6 +648,7 @@
6A0D4F0115FC0DA600ABF4B3 /* VTVerticalCandidateController.m in Sources */,
6A0D4F0215FC0DA600ABF4B3 /* VTVerticalCandidateTableView.m in Sources */,
6A0D4F0315FC0DA600ABF4B3 /* VTVerticalKeyLabelStripView.m in Sources */,
D427A9C125ED28CC005D43E0 /* OpenCCBridge.swift in Sources */,
6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */,
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */,
);
@ -751,6 +766,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
@ -779,6 +795,10 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-fcxx-modules",
);
};
name = Debug;
};
@ -786,6 +806,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
@ -812,6 +833,10 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
OTHER_CPLUSPLUSFLAGS = (
"$(OTHER_CFLAGS)",
"-fcxx-modules",
);
};
name = Release;
};
@ -821,6 +846,8 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
@ -857,11 +884,18 @@
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "Source/McBopomofo-Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.10;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.openvanilla.inputmethod.McBopomofo;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "Source/McBopomofo-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
WRAPPER_EXTENSION = app;
};
name = Debug;
@ -872,6 +906,8 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = NO;
@ -902,10 +938,16 @@
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
INFOPLIST_FILE = "Source/McBopomofo-Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = org.openvanilla.inputmethod.McBopomofo;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "Source/McBopomofo-Bridging-Header.h";
SWIFT_VERSION = 5.0;
WRAPPER_EXTENSION = app;
};
name = Release;
@ -973,6 +1015,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
@ -1010,6 +1053,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
@ -1074,6 +1118,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
D48550A125EBE689006A204C /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ddddxxx/SwiftyOpenCC.git";
requirement = {
kind = revision;
revision = 1d8105a0f7199c90af722bff62728050c858e777;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
D48550A225EBE689006A204C /* OpenCC */ = {
isa = XCSwiftPackageProductDependency;
package = D48550A125EBE689006A204C /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */;
productName = OpenCC;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 6A0D4E9415FC0CFA00ABF4B3 /* Project object */;
}

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

@ -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 = "6ACA41CA15FC1D7500935EF6"
BuildableName = "McBopomofoInstaller.app"
BlueprintName = "McBopomofoInstaller"
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 = "6ACA41CA15FC1D7500935EF6"
BuildableName = "McBopomofoInstaller.app"
BlueprintName = "McBopomofoInstaller"
ReferencedContainer = "container:McBopomofo.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6ACA41CA15FC1D7500935EF6"
BuildableName = "McBopomofoInstaller.app"
BlueprintName = "McBopomofoInstaller"
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>
{
@private
NSWindow *_window;
NSURLConnection *_updateCheckConnection;
BOOL _currentUpdateCheckIsForced;
NSMutableData *_receivingData;
@ -51,5 +50,5 @@
- (void)checkForUpdateForced:(BOOL)forced;
- (void)showPreferences;
@property (assign, nonatomic) IBOutlet NSWindow *window;
@property (weak, nonatomic) IBOutlet NSWindow *window;
@end

View File

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

View File

@ -56,7 +56,7 @@
- (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) BOOL visible;

View File

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

View File

@ -40,10 +40,9 @@
- (void)dealloc
{
[_candidateView release];
[_prevPageButton release];
[_nextPageButton release];
[super dealloc];
_candidateView = nil;
_prevPageButton = nil;
_nextPageButton = nil;
}
- (id)init
@ -51,7 +50,7 @@
NSRect contentRect = NSMakeRect(128.0, 128.0, 0.0, 0.0);
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 setHasShadow:YES];

View File

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

View File

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

View File

@ -57,21 +57,13 @@ static const CGFloat kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0;
CGFloat _candidateTextLeftMargin;
}
- (void)dealloc
{
[_candidateTextParagraphStyle release];
[_keyLabelStripView release];
[_scrollView release];
[_tableView release];
[super dealloc];
}
- (id)init
{
NSRect contentRect = NSMakeRect(128.0, 128.0, 0.0, 0.0);
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 setHasShadow:YES];
@ -100,8 +92,8 @@ static const CGFloat kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0;
[_tableView setDataSource:self];
[_tableView setDelegate:self];
NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"candidate"] autorelease];
[column setDataCell:[[[NSTextFieldCell alloc] init] autorelease]];
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"candidate"];
[column setDataCell:[[NSTextFieldCell alloc] init]];
[column setEditable:NO];
_candidateTextPadding = kCandidateTextPadding;
@ -238,7 +230,7 @@ static const CGFloat kCandidateTextLeftMarginWithMandatedTableViewPadding = 0.0;
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

View File

@ -35,9 +35,8 @@
- (void)dealloc
{
[_keyLabelFont release];
[_keyLabels release];
[super dealloc];
_keyLabelFont = nil;
_keyLabels = nil;
}
- (id)initWithFrame:(NSRect)frameRect
@ -71,7 +70,7 @@
NSColor *darkGray = [NSColor colorWithDeviceWhite:0.7 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];
NSDictionary *textAttr = [NSDictionary dictionaryWithObjectsAndKeys:

View File

@ -68,6 +68,9 @@
// current input mode
NSString *_inputMode;
// if Chinese conversion is enabled
BOOL _chineseConversionEnabled;
}
@end

View File

@ -41,6 +41,9 @@
#import "AppDelegate.h"
#import "VTHorizontalCandidateController.h"
#import "VTVerticalCandidateController.h"
#import "McBopomofo-Swift.h"
//@import SwiftUI;
// C++ namespace usages
using namespace std;
@ -75,6 +78,7 @@ static NSString *const kUseHorizontalCandidateListPreferenceKey = @"UseHorizonta
static NSString *const kComposingBufferSizePreferenceKey = @"ComposingBufferSize";
static NSString *const kDisableUserCandidateSelectionLearning = @"DisableUserCandidateSelectionLearning";
static NSString *const kChooseCandidateUsingSpaceKey = @"ChooseCandidateUsingSpaceKey";
static NSString *const kChineseConversionEnabledKey = @"ChineseConversionEnabledKey";
// advanced (usually optional) settings
static NSString *const kCandidateTextFontName = @"CandidateTextFontName";
@ -159,15 +163,8 @@ public:
if (_builder) {
delete _builder;
}
[_composingBuffer release];
[_candidates release];
// the two client pointers are weak pointers (i.e. we don't retain them)
// therefore we don't do anything about it
[super dealloc];
}
- (id)initWithServer:(IMKServer *)server delegate:(id)delegate client:(id)client
@ -198,6 +195,7 @@ public:
}
_inputMode = kBopomofoModeIdentifier;
_chineseConversionEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:kChineseConversionEnabledKey];
}
return self;
@ -206,8 +204,8 @@ public:
- (NSMenu *)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];
NSMenuItem *preferenceMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"McBopomofo Preferences", @"") action:@selector(showPreferences:) keyEquivalent:@""] autorelease];
NSMenu *menu = [[NSMenu alloc] initWithTitle:LocalizationNotNeeded(@"Input Method Menu")];
NSMenuItem *preferenceMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"McBopomofo Preferences", @"") action:@selector(showPreferences:) keyEquivalent:@""];
[menu addItem:preferenceMenuItem];
// If Option key is pressed, show the learning-related menu
@ -218,32 +216,31 @@ public:
BOOL learningEnabled = ![[NSUserDefaults standardUserDefaults] boolForKey:kDisableUserCandidateSelectionLearning];
NSMenuItem *learnMenuItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Enable Selection Learning", @"") action:@selector(toggleLearning:) keyEquivalent:@""] autorelease];
if (learningEnabled) {
[learnMenuItem setState:NSOnState];
}
else {
[learnMenuItem setState:NSOffState];
}
NSMenuItem *learnMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Enable Selection Learning", @"") action:@selector(toggleLearning:) keyEquivalent:@""];
learnMenuItem.state = learningEnabled ? NSControlStateValueOn : NSControlStateValueOff;
[menu addItem:learnMenuItem];
if (learningEnabled) {
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];
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];
}
}
#endif //DEBUG
NSMenuItem *updateCheckItem = [[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Check for Updates…", @"") action:@selector(checkForUpdate:) keyEquivalent:@""] autorelease];
NSMenuItem *chineseConversionMenuItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Chinese Conversion", @"") action:@selector(toggleChineseConverter:) keyEquivalent:@"G"];
chineseConversionMenuItem.keyEquivalentModifierMask = NSEventModifierFlagCommand | NSEventModifierFlagControl;
chineseConversionMenuItem.state = _chineseConversionEnabled ? NSControlStateValueOn : NSControlStateValueOff;
[menu addItem:chineseConversionMenuItem];
NSMenuItem *updateCheckItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Check for Updates…", @"") action:@selector(checkForUpdate:) keyEquivalent:@""];
[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];
return menu;
@ -397,8 +394,13 @@ public:
return;
}
NSString *buffer = _composingBuffer;
if (_chineseConversionEnabled) {
buffer = [OpenCCBridge convert:_composingBuffer];
}
// commit the text, clear the state
[client insertText:_composingBuffer replacementRange:NSMakeRange(NSNotFound, NSNotFound)];
[client insertText:buffer replacementRange:NSMakeRange(NSNotFound, NSNotFound)];
_builder->clear();
_walkedNodes.clear();
[_composingBuffer setString:@""];
@ -461,10 +463,9 @@ public:
// we must use NSAttributedString so that the cursor is visible --
// can't just use NSString
NSDictionary *attrDict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
[NSNumber numberWithInt:0], NSMarkedClauseSegmentAttributeName, nil];
NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:composedText attributes:attrDict] autorelease];
NSDictionary *attrDict = @{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle),
NSMarkedClauseSegmentAttributeName: @0};
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,
// i.e. the client app needs to take care of where to put ths composing buffer
@ -1438,6 +1439,12 @@ public:
[[NSUserDefaults standardUserDefaults] setBool:toggle forKey:kDisableUserCandidateSelectionLearning];
}
- (void)toggleChineseConverter:(id)sender
{
_chineseConversionEnabled = !_chineseConversionEnabled;
[[NSUserDefaults standardUserDefaults] setBool:_chineseConversionEnabled forKey:kChineseConversionEnabledKey];
}
- (void)clearLearningDictionary:(id)sender
{
[gCandidateLearningDictionary removeAllObjects];
@ -1540,7 +1547,7 @@ void LTLoadLanguageModel()
// TODO: Change this
NSString *userDictFile = [userDictPath stringByAppendingPathComponent:@"UserCandidatesCache.plist"];
gUserCandidatesDictionaryPath = [userDictFile retain];
gUserCandidatesDictionaryPath = userDictFile;
exists = [[NSFileManager defaultManager] fileExistsAtPath:userDictFile isDirectory:&isDir];
if (exists && !isDir) {

View File

@ -34,20 +34,20 @@
ArchiveUtil *_archiveUtil;
NSString *_installingVersion;
BOOL _upgrading;
NSButton *_installButton;
NSButton *_cancelButton;
NSTextView *_textView;
NSWindow *_progressSheet;
NSProgressIndicator *_progressIndicator;
NSButton *__weak _installButton;
NSButton *__weak _cancelButton;
NSTextView *__unsafe_unretained _textView;
NSWindow *__weak _progressSheet;
NSProgressIndicator *__weak _progressIndicator;
NSDate *_translocationRemovalStartTime;
NSInteger _currentVersionNumber;
}
- (IBAction)agreeAndInstallAction:(id)sender;
- (IBAction)cancelAction:(id)sender;
@property (assign) IBOutlet NSButton *installButton;
@property (assign) IBOutlet NSButton *cancelButton;
@property (assign) IBOutlet NSTextView *textView;
@property (assign) IBOutlet NSWindow *progressSheet;
@property (assign) IBOutlet NSProgressIndicator *progressIndicator;
@property (weak) IBOutlet NSButton *installButton;
@property (weak) IBOutlet NSButton *cancelButton;
@property (unsafe_unretained) IBOutlet NSTextView *textView;
@property (weak) IBOutlet NSWindow *progressSheet;
@property (weak) IBOutlet NSProgressIndicator *progressIndicator;
@end

View File

@ -46,7 +46,6 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) {
[alert setInformativeText:message];
[alert addButtonWithTitle:buttonTitle];
[alert runModal];
[alert autorelease];
}
@implementation AppDelegate
@ -56,17 +55,10 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) {
@synthesize progressSheet = _progressSheet;
@synthesize progressIndicator = _progressIndicator;
- (void)dealloc
{
[_archiveUtil release];
[_installingVersion release];
[_translocationRemovalStartTime release];
[super dealloc];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
_installingVersion = [[[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleVersionKey] retain];
_installingVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleVersionKey];
NSString *versionString = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
_archiveUtil = [[ArchiveUtil alloc] initWithAppName:kTargetBin targetAppBundleName:kTargetBundle];
@ -76,9 +68,9 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) {
[self.installButton setNextKeyView:self.cancelButton];
[[self window] setDefaultButtonCell:[self.installButton cell]];
NSAttributedString *attrStr = [[[NSAttributedString alloc] initWithRTF:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"License" ofType:@"rtf"]] documentAttributes:NULL] autorelease];
NSAttributedString *attrStr = [[NSAttributedString alloc] initWithRTF:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"License" ofType:@"rtf"]] documentAttributes:NULL];
NSMutableAttributedString *mutableAttrStr = [[attrStr mutableCopy] autorelease];
NSMutableAttributedString *mutableAttrStr = [attrStr mutableCopy];
[mutableAttrStr addAttribute:NSForegroundColorAttributeName value:[NSColor controlTextColor] range:NSMakeRange(0, [mutableAttrStr length])];
[[self.textView textStorage] setAttributedString:mutableAttrStr];
[self.textView setSelectedRange:NSMakeRange(0, 0)];
@ -145,8 +137,7 @@ void RunAlertPanel(NSString *title, NSString *message, NSString *buttonTitle) {
});
}];
[_translocationRemovalStartTime release];
_translocationRemovalStartTime = [[NSDate date] retain];
_translocationRemovalStartTime = [NSDate date];
[NSTimer scheduledTimerWithTimeInterval:kTranslocationRemovalTickInterval target:self selector:@selector(timerTick:) userInfo:nil repeats:YES];
return;
}

View File

@ -28,16 +28,15 @@
targetAppBundleName:(NSString *)targetAppBundleName {
self = [super init];
if (self) {
_appName = [name retain];
_targetAppBundleName = [targetAppBundleName retain];
_appName = name;
_targetAppBundleName = targetAppBundleName;
}
return self;
}
- (void)delloc {
[_appName release];
[_targetAppBundleName release];
[super dealloc];
_appName = nil;
_targetAppBundleName = nil;
}
- (BOOL)validateIfNotarizedArchiveExists {
@ -67,7 +66,6 @@
devModeAppBundleExists]];
[alert addButtonWithTitle:@"Terminate"];
[alert runModal];
[alert autorelease];
[[NSApplication sharedApplication] terminate:nil];
} else {
@ -84,8 +82,6 @@
devModeAppBundlePath]];
[alert addButtonWithTitle:@"Terminate"];
[alert runModal];
[alert autorelease];
[[NSApplication sharedApplication] terminate:nil];
}

View File

@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

View File

@ -28,8 +28,6 @@
<dict>
<key>TISDoubleSpaceSubstitution</key>
<string>。</string>
<key>TISIntendedLanguage</key>
<string>zh-Hant</string>
<key>tsInputModeAlternateMenuIconFileKey</key>
<string>Bopomofo.tiff</string>
<key>tsInputModeCharacterRepertoireKey</key>
@ -51,13 +49,20 @@
<true/>
<key>tsInputModeScriptKey</key>
<string>smTradChinese</string>
<key>TISIntendedLanguage</key>
<string>zh-Hant</string>
<key>tsInputModeCharacterRepertoireKey</key>
<array>
<string>Hant</string>
<string>Han</string>
</array>
<key>tsInputModeKeyEquivalentModifiersKey</key>
<integer>4608</integer>
</dict>
<key>org.openvanilla.inputmethod.McBopomofo.PlainBopomofo</key>
<dict>
<key>TISDoubleSpaceSubstitution</key>
<string>。</string>
<key>TISIntendedLanguage</key>
<string>zh-Hant</string>
<key>tsInputModeAlternateMenuIconFileKey</key>
<string>PlainBopomofo.tiff</string>
<key>tsInputModeCharacterRepertoireKey</key>
@ -79,6 +84,15 @@
<true/>
<key>tsInputModeScriptKey</key>
<string>smTradChinese</string>
<key>TISIntendedLanguage</key>
<string>zh-Hant</string>
<key>tsInputModeCharacterRepertoireKey</key>
<array>
<string>Hant</string>
<string>Han</string>
</array>
<key>tsInputModeKeyEquivalentModifiersKey</key>
<integer>4608</integer>
</dict>
</dict>
<key>tsVisibleInputModeOrderedArrayKey</key>

View File

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

View File

@ -18,14 +18,6 @@
@end
@interface OVNonModalAlertWindowController : NSWindowController
{
@private
NSTextField *_titleTextField;
NSTextField *_contentTextField;
NSButton *_confirmButton;
NSButton *_cancelButton;
id<OVNonModalAlertWindowControllerDelegate> _delegate;
}
+ (OVNonModalAlertWindowController *)sharedInstance;
- (void)showWithTitle:(NSString *)title content:(NSString *)content confirmButtonTitle:(NSString *)confirmTitle cancelButtonTitle:(NSString *)cancelButtonTitle cancelAsDefault:(BOOL)cancelAsDefault delegate:(id<OVNonModalAlertWindowControllerDelegate>)delegate;

View File

@ -30,10 +30,10 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-statement-expression"
- (void)showWithTitle:(NSString *)title content:(NSString *)content confirmButtonTitle:(NSString *)confirmTitle cancelButtonTitle:(NSString *)cancelButtonTitle cancelAsDefault:(BOOL)cancelAsDefault delegate:(id<OVNonModalAlertWindowControllerDelegate>)delegate;
- (void)showWithTitle:(NSString *)title content:(NSString *)content confirmButtonTitle:(NSString *)confirmTitle cancelButtonTitle:(NSString *)cancelButtonTitle cancelAsDefault:(BOOL)cancelAsDefault delegate:(id <OVNonModalAlertWindowControllerDelegate>)delegate;
{
// cancel previous alert
if ([[self window] isVisible]) {
if (self.window.visible) {
if ([_delegate respondsToSelector:@selector(nonModalAlertWindowControllerDidCancel:)]) {
[_delegate nonModalAlertWindowControllerDidCancel:self];
}
@ -41,11 +41,11 @@
_delegate = delegate;
NSRect oldFrame = [self.confirmButton frame];
NSRect oldFrame = self.confirmButton.frame;
[self.confirmButton setTitle:confirmTitle];
[self.confirmButton sizeToFit];
NSRect newFrame = [self.confirmButton frame];
NSRect newFrame = self.confirmButton.frame;
newFrame.size.width = MAX(90.0, (newFrame.size.width + 10.0));
newFrame.origin.x += (oldFrame.size.width - newFrame.size.width);
@ -54,41 +54,41 @@
if (cancelButtonTitle) {
[self.cancelButton setTitle:cancelButtonTitle];
[self.cancelButton sizeToFit];
NSRect adjustedFrame = [self.cancelButton frame];
NSRect adjustedFrame = self.cancelButton.frame;
adjustedFrame.size.width = MAX(90.0, (adjustedFrame.size.width + 10.0));
adjustedFrame.origin.x = newFrame.origin.x - adjustedFrame.size.width;
[self.cancelButton setFrame:adjustedFrame];
[self.cancelButton setHidden:NO];
self.cancelButton.frame = adjustedFrame;
self.cancelButton.hidden = NO;
}
else {
[self.cancelButton setHidden:YES];
self.cancelButton.hidden = YES;
}
[self.cancelButton setNextKeyView:self.confirmButton];
[self.confirmButton setNextKeyView:self.cancelButton];
self.cancelButton.nextKeyView = self.confirmButton;
self.confirmButton.nextKeyView = self.cancelButton;
if (cancelButtonTitle) {
if (cancelAsDefault) {
[[self window] setDefaultButtonCell:[self.cancelButton cell]];
[self.window setDefaultButtonCell:self.cancelButton.cell];
}
else {
[self.cancelButton setKeyEquivalent:@" "];
[[self window] setDefaultButtonCell:[self.confirmButton cell]];
self.cancelButton.keyEquivalent = @" ";
[self.window setDefaultButtonCell:self.confirmButton.cell];
}
}
else {
[[self window] setDefaultButtonCell:[self.confirmButton cell]];
[[self window] setDefaultButtonCell:self.confirmButton.cell];
}
[self.titleTextField setStringValue:title];
self.titleTextField.stringValue = title;
oldFrame = [self.contentTextField frame];
[self.contentTextField setStringValue:content];
self.contentTextField.stringValue = content;
NSRect infiniteHeightFrame = oldFrame;
infiniteHeightFrame.size.width -= 4.0;
infiniteHeightFrame.size.height = 10240;
newFrame = [content boundingRectWithSize:infiniteHeightFrame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:[self.contentTextField font], NSFontAttributeName, nil]];
newFrame = [content boundingRectWithSize:infiniteHeightFrame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: self.contentTextField.font}];
newFrame.size.width = MAX(newFrame.size.width, oldFrame.size.width);
newFrame.size.height += 4.0;
newFrame.origin = oldFrame.origin;
@ -98,18 +98,19 @@
NSRect windowFrame = [[self window] frame];
windowFrame.size.height += (newFrame.size.height - oldFrame.size.height);
[[self window] setLevel:CGShieldingWindowLevel() + 1];
[[self window] setFrame:windowFrame display:YES];
[[self window] center];
[[self window] makeKeyAndOrderFront:self];
self.window.level = CGShieldingWindowLevel() + 1;
[self.window setFrame:windowFrame display:YES];
[self.window center];
[self.window makeKeyAndOrderFront:self];
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}
#pragma GCC diagnostic pop
- (IBAction)confirmButtonAction:(id)sender
{
[_delegate nonModalAlertWindowControllerDidConfirm:self];
[[self window] orderOut:self];
[self.window orderOut:self];
}
- (IBAction)cancelButtonAction:(id)sender
@ -124,8 +125,7 @@
}
_delegate = nil;
[[self window] orderOut:self];
[self.window orderOut:self];
}
@end

22
Source/OpenCCBridge.swift Normal file
View File

@ -0,0 +1,22 @@
import Foundation
import OpenCC
// Since SwiftyOpenCC only provide Swift classes, we create an NSObject subclass
// in Swift in order to bridge the Swift classes into our Objective-C++ project.
class OpenCCBridge : NSObject {
private static let shared = OpenCCBridge()
private var conveter: ChineseConverter?
override init() {
try? conveter = ChineseConverter(options: .simplify)
super.init()
}
@objc static func convert(_ string:String) -> String? {
return shared.conveter?.convert(string)
}
private func convert(_ string:String) -> String? {
return conveter?.convert(string)
}
}

View File

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

View File

@ -46,7 +46,7 @@ static NSString *const kBasisKeyboardLayoutPreferenceKey = @"BasisKeyboardLayout
NSMenuItem *usKeyboardLayoutItem = nil;
NSMenuItem *chosenItem = nil;
[[self.basisKeyboardLayoutButton menu] removeAllItems];
[self.basisKeyboardLayoutButton.menu removeAllItems];
NSString *basisKeyboardLayoutID = [[NSUserDefaults standardUserDefaults] stringForKey:kBasisKeyboardLayoutPreferenceKey];
@ -68,12 +68,12 @@ static NSString *const kBasisKeyboardLayoutPreferenceKey = @"BasisKeyboardLayout
continue;
}
NSString *sourceID = (NSString *)TISGetInputSourceProperty(source, kTISPropertyInputSourceID);
NSString *localizedName = (NSString *)TISGetInputSourceProperty(source, kTISPropertyLocalizedName);
NSString *sourceID = (__bridge NSString *)TISGetInputSourceProperty(source, kTISPropertyInputSourceID);
NSString *localizedName = (__bridge NSString *)TISGetInputSourceProperty(source, kTISPropertyLocalizedName);
NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease];
[item setTitle:localizedName];
[item setRepresentedObject:sourceID];
NSMenuItem *item = [[NSMenuItem alloc] init];
item.title = localizedName;
item.representedObject = sourceID;
if ([sourceID isEqualToString:@"com.apple.keylayout.US"]) {
usKeyboardLayoutItem = item;
@ -84,7 +84,7 @@ static NSString *const kBasisKeyboardLayoutPreferenceKey = @"BasisKeyboardLayout
chosenItem = item;
}
[[self.basisKeyboardLayoutButton menu] addItem:item];
[self.basisKeyboardLayoutButton.menu addItem:item];
}
[self.basisKeyboardLayoutButton selectItem:(chosenItem ? chosenItem : usKeyboardLayoutItem)];

View File

@ -48,3 +48,5 @@
/* No comment provided by engineer. */
"You're currently using McBopomofo %@ (%@), a new version %@ (%@) is now available. Do you want to visit McBopomofo's website to download the version?%@" = "You're currently using McBopomofo %@ (%@), a new version %@ (%@) is now available. Do you want to visit McBopomofo's website to download the version?%@";
"Chinese Conversion" = "Chinese Conversion";

View File

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

View File

@ -48,3 +48,5 @@
/* No comment provided by engineer. */
"You're currently using McBopomofo %@ (%@), a new version %@ (%@) is now available. Do you want to visit McBopomofo's website to download the version?%@" = "目前使用的小麥注音版本是 %1$@ (%2$@),網路上有更新版本 %3$@ (%4$@) 可供下載。是否要前往小麥注音網站下載新版來安裝?%5$@";
"Chinese Conversion" = "簡繁轉換";