Skip to content

Commit

Permalink
Merge pull request #543 from zonble/master
Browse files Browse the repository at this point in the history
Fixes auto layout.
  • Loading branch information
lukhnos committed Oct 21, 2024
2 parents d5133b5 + 291a449 commit 58aa285
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 163 deletions.
14 changes: 14 additions & 0 deletions McBopomofo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
6A6ED16C2797650A0012872E /* template-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1652797650A0012872E /* template-data.txt */; };
6A6ED16D2797650A0012872E /* template-exclude-phrases-plain-bpmf.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1672797650A0012872E /* template-exclude-phrases-plain-bpmf.txt */; };
6A6ED16E2797650A0012872E /* template-exclude-phrases.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1692797650A0012872E /* template-exclude-phrases.txt */; };
6A7C450C2CC571D00076AECA /* template-data-plain-bpmf.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A7C450A2CC571D00076AECA /* template-data-plain-bpmf.txt */; };
6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EA15FC1D9000935EF6 /* InfoPlist.strings */; };
6ACA41FB15FC1D9000935EF6 /* License.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EC15FC1D9000935EF6 /* License.rtf */; };
6ACA41FC15FC1D9000935EF6 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EE15FC1D9000935EF6 /* Localizable.strings */; };
Expand Down Expand Up @@ -139,6 +140,8 @@
6A6ED170279765140012872E /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text; name = "zh-Hant"; path = "zh-Hant.lproj/template-exclude-phrases-plain-bpmf.txt"; sourceTree = "<group>"; };
6A6ED171279765170012872E /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text; name = "zh-Hant"; path = "zh-Hant.lproj/template-exclude-phrases.txt"; sourceTree = "<group>"; };
6A6ED1722797651A0012872E /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text; name = "zh-Hant"; path = "zh-Hant.lproj/template-phrases-replacement.txt"; sourceTree = "<group>"; };
6A7C450B2CC571D00076AECA /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-data-plain-bpmf.txt"; sourceTree = "<group>"; };
6A7C450D2CC571E10076AECA /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text; name = "zh-Hant"; path = "zh-Hant.lproj/template-data-plain-bpmf.txt"; sourceTree = "<group>"; };
6A93050C279877FF00D370DA /* McBopomofoInstaller-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "McBopomofoInstaller-Bridging-Header.h"; sourceTree = "<group>"; };
6ACA41CB15FC1D7500935EF6 /* McBopomofoInstaller.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = McBopomofoInstaller.app; sourceTree = BUILT_PRODUCTS_DIR; };
6ACA41EB15FC1D9000935EF6 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -412,6 +415,7 @@
isa = PBXGroup;
children = (
6A6ED1652797650A0012872E /* template-data.txt */,
6A7C450A2CC571D00076AECA /* template-data-plain-bpmf.txt */,
6A6ED1672797650A0012872E /* template-exclude-phrases-plain-bpmf.txt */,
6A6ED1692797650A0012872E /* template-exclude-phrases.txt */,
6A6ED1632797650A0012872E /* template-phrases-replacement.txt */,
Expand Down Expand Up @@ -632,6 +636,7 @@
6AFF97F2253B299E007F1C49 /* NonModalAlertWindowController.xib in Resources */,
D4EE675A2B39968900F062DE /* dictionary_service.json in Resources */,
6AE210B215FC63CC003659FE /* PlainBopomofo.tiff in Resources */,
6A7C450C2CC571D00076AECA /* template-data-plain-bpmf.txt in Resources */,
D4F0BBE7279B14C20071253C /* Credits.rtf in Resources */,
D476CB492827DB6300F48552 /* add-phrase-hook.sh in Resources */,
6A6ED16C2797650A0012872E /* template-data.txt in Resources */,
Expand Down Expand Up @@ -825,6 +830,15 @@
name = "template-exclude-phrases.txt";
sourceTree = "<group>";
};
6A7C450A2CC571D00076AECA /* template-data-plain-bpmf.txt */ = {
isa = PBXVariantGroup;
children = (
6A7C450B2CC571D00076AECA /* Base */,
6A7C450D2CC571E10076AECA /* zh-Hant */,
);
name = "template-data-plain-bpmf.txt";
sourceTree = "<group>";
};
6ACA41EA15FC1D9000935EF6 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
Expand Down
6 changes: 3 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## 系統需求

小麥注音輸入法可以在 macOS 10.13 以上版本運作。如果您要自行編譯小麥注音輸入法,或參與開發,您需要:
小麥注音輸入法可以在 macOS 10.15 以上版本運作。如果您要自行編譯小麥注音輸入法,或參與開發,您需要:

- macOS 13.6 以上版本
- Xcode 15.1 以上版本
- macOS 14.7 以上版本
- Xcode 15.3 以上版本
- Python 3.9 (可使用 Xcode 安裝後內附的,或是使用 homebrew 等方式安裝)

## 開發流程
Expand Down
8 changes: 6 additions & 2 deletions Source/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle

func updateUserPhrases() {
NSLog("updateUserPhrases called \(LanguageModelManager.dataFolderPath)")
LanguageModelManager.loadUserPhrases()
LanguageModelManager.loadUserPhrases(enableForPlainBopomofo: Preferences.EnableUserPhrasesInPlainBopomofo)
LanguageModelManager.loadUserPhraseReplacement()

fsStreamHelper?.delegate = nil
Expand Down Expand Up @@ -274,7 +274,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
extension AppDelegate: FSEventStreamHelperDelegate {
func helper(_ helper: FSEventStreamHelper, didReceive events: [FSEventStreamHelper.Event]) {
DispatchQueue.main.async {
LanguageModelManager.loadUserPhrases()
LanguageModelManager.loadUserPhrases(enableForPlainBopomofo: Preferences.EnableUserPhrasesInPlainBopomofo)
LanguageModelManager.loadUserPhraseReplacement()
}
}
Expand Down Expand Up @@ -302,6 +302,10 @@ extension AppDelegate {
open(userFileAt: LanguageModelManager.userPhrasesDataPathMcBopomofo)
}

@objc func openUserPhrasesPlainBopomofo(_ sender: Any?) {
open(userFileAt: LanguageModelManager.userPhrasesDataPathPlainBopomofo)
}

@objc func openExcludedPhrasesPlainBopomofo(_ sender: Any?) {
open(userFileAt: LanguageModelManager.excludedPhrasesDataPathPlainBopomofo)
}
Expand Down
12 changes: 6 additions & 6 deletions Source/Base.lproj/preferences.xib
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="401" y="295" width="475" height="567"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1055"/>
<view key="contentView" id="2">
<rect key="frame" x="0.0" y="0.0" width="475" height="567"/>
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -52,7 +52,7 @@
<rect key="frame" x="229" y="462" width="39" height="25"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="n2z-u9-T3b">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="message"/>
<menu key="menu" title="OtherViews" id="aFj-Ch-q1M"/>
</popUpButtonCell>
<connections>
Expand Down Expand Up @@ -108,7 +108,7 @@
<rect key="frame" x="229" y="492" width="118" height="25"/>
<popUpButtonCell key="cell" type="push" title="Standard" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="PTu-Ks-u1l" id="tPE-G4-rho">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="message"/>
<menu key="menu" title="OtherViews" id="gB4-rd-gSr">
<items>
<menuItem title="Standard" state="on" id="PTu-Ks-u1l"/>
Expand Down Expand Up @@ -187,7 +187,7 @@
<rect key="frame" x="229" y="165" width="56" height="26"/>
<popUpButtonCell key="cell" type="push" title="18" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" tag="18" imageScaling="proportionallyDown" inset="2" selectedItem="64X-UF-Vz6" id="Bsy-hs-5q4">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="message"/>
<menu key="menu" title="OtherViews" id="jHd-60-Ic9">
<items>
<menuItem title="12" tag="12" id="4rb-ai-9Xy"/>
Expand Down Expand Up @@ -462,7 +462,7 @@ when selecting candidats</string>
<rect key="frame" x="240" y="64" width="221" height="25"/>
<popUpButtonCell key="cell" type="push" title="Off" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="bAf-tJ-tnK" id="dl4-pi-p7L">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="message"/>
<menu key="menu" id="Nps-ru-fnW">
<items>
<menuItem title="Off" state="on" id="bAf-tJ-tnK"/>
Expand Down Expand Up @@ -514,7 +514,7 @@ when selecting candidats</string>
<rect key="frame" x="17" y="252" width="86" height="25"/>
<popUpButtonCell key="cell" type="push" title="Default" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="avu-Uo-JGI" id="Kln-Ca-WBd">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="menu"/>
<font key="font" metaFont="message"/>
<menu key="menu" id="WPe-Ie-ipP">
<items>
<menuItem title="Default" state="on" id="avu-Uo-JGI">
Expand Down
10 changes: 10 additions & 0 deletions Source/Base.lproj/template-data-plain-bpmf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Custom Characters (for Plain Bopomofo).
#
# See https://github.com/openvanilla/McBopomofo/wiki/使用手冊#手動加詞 for usage.
#
# Add your characters and their respective Bopomofo reading below.
#
# 㵘 ㄇㄢˋ
#
# Any line that starts with "#" is treated as comment.

5 changes: 3 additions & 2 deletions Source/Engine/McBopomofoLM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ void McBopomofoLM::loadAssociatedPhrasesV2(const char* associatedPhrasesPath) {

void McBopomofoLM::loadUserPhrases(const char* userPhrasesDataPath,
const char* excludedPhrasesDataPath) {
userPhrases_.close();
excludedPhrases_.close();

if (userPhrasesDataPath) {
userPhrases_.close();
userPhrases_.open(userPhrasesDataPath);
}
if (excludedPhrasesDataPath) {
excludedPhrases_.close();
excludedPhrases_.open(excludedPhrasesDataPath);
}
}
Expand Down
9 changes: 8 additions & 1 deletion Source/InputMethodController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class McBopomofoInputMethodController: IMKInputController {
menu.addItem(withTitle: NSLocalizedString("User Phrases", comment: ""), action: nil, keyEquivalent: "")

if inputMode == .plainBopomofo {
if (Preferences.EnableUserPhrasesInPlainBopomofo) {
menu.addItem(withTitle: NSLocalizedString("Edit User Phrases", comment: ""), action: #selector(openUserPhrasesPlainBopomofo(_:)), keyEquivalent: "")
}
menu.addItem(withTitle: NSLocalizedString("Edit Excluded Phrases", comment: ""), action: #selector(openExcludedPhrasesPlainBopomofo(_:)), keyEquivalent: "")
} else {
menu.addItem(withTitle: NSLocalizedString("Edit User Phrases", comment: ""), action: #selector(openUserPhrases(_:)), keyEquivalent: "")
Expand Down Expand Up @@ -234,6 +237,10 @@ class McBopomofoInputMethodController: IMKInputController {
(NSApp.delegate as? AppDelegate)?.openUserPhrases(sender)
}

@objc func openUserPhrasesPlainBopomofo(_ sender: Any?) {
(NSApp.delegate as? AppDelegate)?.openUserPhrasesPlainBopomofo(sender)
}

@objc func openExcludedPhrasesPlainBopomofo(_ sender: Any?) {
(NSApp.delegate as? AppDelegate)?.openExcludedPhrasesPlainBopomofo(sender)
}
Expand All @@ -247,7 +254,7 @@ class McBopomofoInputMethodController: IMKInputController {
}

@objc func reloadUserPhrases(_ sender: Any?) {
LanguageModelManager.loadUserPhrases()
LanguageModelManager.loadUserPhrases(enableForPlainBopomofo: Preferences.EnableUserPhrasesInPlainBopomofo)
LanguageModelManager.loadUserPhraseReplacement()
}

Expand Down
3 changes: 2 additions & 1 deletion Source/LanguageModelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface LanguageModelManager : NSObject

+ (void)loadDataModel:(InputMode)mode;
+ (void)loadUserPhrases;
+ (void)loadUserPhrasesWithPlainBopomofoEnabled:(BOOL)userPhraseForPlainBopomofo NS_SWIFT_NAME(loadUserPhrases(enableForPlainBopomofo:));
+ (void)loadUserPhraseReplacement;
+ (void)setupDataModelValueConverter;
+ (BOOL)checkIfUserLanguageModelFilesExist;
Expand All @@ -41,6 +41,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (class, readonly, nonatomic) NSString *dataFolderPath;
@property (class, readonly, nonatomic) NSString *userPhrasesDataPathMcBopomofo;
@property (class, readonly, nonatomic) NSString *userPhrasesDataPathPlainBopomofo;
@property (class, readonly, nonatomic) NSString *excludedPhrasesDataPathMcBopomofo;
@property (class, readonly, nonatomic) NSString *excludedPhrasesDataPathPlainBopomofo;
@property (class, readonly, nonatomic) NSString *phraseReplacementDataPathMcBopomofo;
Expand Down
15 changes: 13 additions & 2 deletions Source/LanguageModelManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
static McBopomofo::UserOverrideModel gUserOverrideModel(kUserOverrideModelCapacity, kObservedOverrideHalflife);

static NSString *const kUserDataTemplateName = @"template-data";
static NSString *const kUserDataPlainBopomofoTemplateName = @"template-data-plain-bpmf";
static NSString *const kExcludedPhrasesMcBopomofoTemplateName = @"template-exclude-phrases";
static NSString *const kExcludedPhrasesPlainBopomofoTemplateName = @"template-exclude-phrases-plain-bpmf";
static NSString *const kPhraseReplacementTemplateName = @"template-phrases-replacement";
Expand Down Expand Up @@ -94,10 +95,12 @@ + (void)loadDataModel:(InputMode)mode
}
}

+ (void)loadUserPhrases
+ (void)loadUserPhrasesWithPlainBopomofoEnabled:(BOOL)userPhraseForPlainBopomofo
{
gLanguageModelMcBopomofo.loadUserPhrases([self userPhrasesDataPathMcBopomofo].UTF8String, [self excludedPhrasesDataPathMcBopomofo].UTF8String);
gLanguageModelPlainBopomofo.loadUserPhrases(NULL, [self excludedPhrasesDataPathPlainBopomofo].UTF8String);
gLanguageModelPlainBopomofo.loadUserPhrases(userPhraseForPlainBopomofo ?
[self userPhrasesDataPathPlainBopomofo].UTF8String : NULL,
[self excludedPhrasesDataPathPlainBopomofo].UTF8String);
}

+ (void)loadUserPhraseReplacement
Expand Down Expand Up @@ -185,6 +188,9 @@ + (BOOL)checkIfUserLanguageModelFilesExist
if (![self ensureFileExists:[self userPhrasesDataPathMcBopomofo] populateWithTemplate:kUserDataTemplateName extension:kTemplateExtension]) {
return NO;
}
if (![self ensureFileExists:[self userPhrasesDataPathPlainBopomofo] populateWithTemplate:kUserDataPlainBopomofoTemplateName extension:kTemplateExtension]) {
return NO;
}
if (![self ensureFileExists:[self excludedPhrasesDataPathMcBopomofo] populateWithTemplate:kExcludedPhrasesMcBopomofoTemplateName extension:kTemplateExtension]) {
return NO;
}
Expand Down Expand Up @@ -273,6 +279,11 @@ + (NSString *)userPhrasesDataPathMcBopomofo
return [[self dataFolderPath] stringByAppendingPathComponent:@"data.txt"];
}

+ (NSString *)userPhrasesDataPathPlainBopomofo
{
return [[self dataFolderPath] stringByAppendingPathComponent:@"data-plain-bpmf.txt"];
}

+ (NSString *)excludedPhrasesDataPathMcBopomofo
{
return [[self dataFolderPath] stringByAppendingPathComponent:@"exclude-phrases.txt"];
Expand Down
7 changes: 7 additions & 0 deletions Source/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ private let kBig5InputEnabledKey = "Big5InputEnabled"
// Need to be populated to true by default upon first start, so the key is not private.
let kBeepUponInputErrorKey = "BeepUponInputError"

private let kEnableUserPhrasesInPlainBopomofo = "EnableUserPhrasesInPlainBopomofo"

// MARK: Property wrappers

@propertyWrapper
Expand Down Expand Up @@ -488,3 +490,8 @@ extension Preferences {
@UserDefault(key: kBeepUponInputErrorKey, defaultValue: true)
@objc static var BeepUponInputError: Bool
}

extension Preferences {
@UserDefault(key: kEnableUserPhrasesInPlainBopomofo, defaultValue: false)
@objc static var EnableUserPhrasesInPlainBopomofo: Bool
}
Loading

0 comments on commit 58aa285

Please sign in to comment.