From a5247d958c753a988f8067240bc177b943f7c56a Mon Sep 17 00:00:00 2001 From: zonble Date: Sun, 9 Jan 2022 21:53:45 +0800 Subject: [PATCH] Makes it able to reload user phrases. --- Source/InputMethodController.mm | 21 ++++++++++++++------- Source/en.lproj/Localizable.strings | 4 ++++ Source/zh-Hant.lproj/Localizable.strings | 5 +++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Source/InputMethodController.mm b/Source/InputMethodController.mm index 03541288..17343783 100644 --- a/Source/InputMethodController.mm +++ b/Source/InputMethodController.mm @@ -233,8 +233,13 @@ static double FindHighestScore(const vector& nodes, double epsilon) chineseConversionMenuItem.state = _chineseConversionEnabled ? NSControlStateValueOn : NSControlStateValueOff; [menu addItem:chineseConversionMenuItem]; - NSMenuItem *editUserPhraseItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Edit User Phrases", @"") action:@selector(openUserPhrases:) keyEquivalent:@""]; - [menu addItem:editUserPhraseItem]; + if (_inputMode != kPlainBopomofoModeIdentifier) { + NSMenuItem *editUserPhraseItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Edit User Phrases", @"") action:@selector(openUserPhrases:) keyEquivalent:@""]; + [menu addItem:editUserPhraseItem]; + + NSMenuItem *reloadUserPhraseItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Reload User Phrases", @"") action:@selector(reloadUserPhrases:) keyEquivalent:@""]; + [menu addItem:reloadUserPhraseItem]; + } NSMenuItem *updateCheckItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Check for Updates…", @"") action:@selector(checkForUpdate:) keyEquivalent:@""]; [menu addItem:updateCheckItem]; @@ -666,6 +671,8 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; } NSData *data = [currentMarkedPhrase dataUsingEncoding:NSUTF8StringEncoding]; [file writeData:data]; [file closeFile]; + + LTLoadUserLanguageModelFile(); return YES; } @@ -1550,11 +1557,11 @@ NS_INLINE size_t max(size_t a, size_t b) { return a > b ? a : b; } } NSURL *url = [NSURL fileURLWithPath:path]; [[NSWorkspace sharedWorkspace] openURL:url]; -// NSWorkspaceOpenConfiguration *config = [NSWorkspaceOpenConfiguration configuration]; -// [[NSWorkspace sharedWorkspace] openURL:url configuration:config completionHandler:^(NSRunningApplication * app, NSError * error) { -// NSLog(@"app %@", app); -// NSLog(@"error %@", error); -// }]; +} + +- (void)reloadUserPhrases:(id)sender +{ + LTLoadUserLanguageModelFile(); } - (void)showAbout:(id)sender diff --git a/Source/en.lproj/Localizable.strings b/Source/en.lproj/Localizable.strings index 4fdc110c..35ba6025 100644 --- a/Source/en.lproj/Localizable.strings +++ b/Source/en.lproj/Localizable.strings @@ -50,3 +50,7 @@ "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" = "Convert to Simplified Chinese"; + +"Edit User Phrases" = "Edit User Phrases"; + +"Reload User Phrases" = "Reload User Phrases"; diff --git a/Source/zh-Hant.lproj/Localizable.strings b/Source/zh-Hant.lproj/Localizable.strings index e49af527..503bdb09 100644 --- a/Source/zh-Hant.lproj/Localizable.strings +++ b/Source/zh-Hant.lproj/Localizable.strings @@ -50,3 +50,8 @@ "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" = "輸出簡體中文"; + +"Edit User Phrases" = "編輯使用者詞彙"; + +"Reload User Phrases" = "重新載入使用者詞彙"; +