From 75fef8140498a83653e130f1c55df6bc0854ed54 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 9 Feb 2022 23:18:15 +0800 Subject: [PATCH] ctlInputMethod // Add a shortcut to the User Data folder. --- Source/Modules/IMEModules/ctlInputMethod.swift | 8 ++++++++ Source/Modules/LangModelRelated/mgrLangModel.h | 1 + 2 files changed, 9 insertions(+) diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index 3a690edb..dbde36e3 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -80,6 +80,7 @@ class ctlInputMethod: IMKInputController { menu.addItem(NSMenuItem.separator()) // --------------------- + menu.addItem(withTitle: NSLocalizedString("Open User Data Folder", comment: ""), action: #selector(openUserDataFolder(_:)), keyEquivalent: "") menu.addItem(withTitle: NSLocalizedString("Edit User Phrases", comment: ""), action: #selector(openUserPhrases(_:)), keyEquivalent: "") if optionKeyPressed { @@ -252,6 +253,13 @@ class ctlInputMethod: IMKInputController { open(userFileAt: mgrLangModel.userPhrasesDataPath(keyHandler.inputMode)) } + @objc func openUserDataFolder(_ sender: Any?) { + if !mgrLangModel.checkIfUserDataFolderExists() { + return + } + NSWorkspace.shared.openFile(mgrLangModel.dataFolderPath, withApplication: "Finder") + } + @objc func openExcludedPhrases(_ sender: Any?) { open(userFileAt: mgrLangModel.excludedPhrasesDataPath(keyHandler.inputMode)) } diff --git a/Source/Modules/LangModelRelated/mgrLangModel.h b/Source/Modules/LangModelRelated/mgrLangModel.h index f1113cfb..e76c6ea1 100644 --- a/Source/Modules/LangModelRelated/mgrLangModel.h +++ b/Source/Modules/LangModelRelated/mgrLangModel.h @@ -29,6 +29,7 @@ NS_ASSUME_NONNULL_BEGIN + (void)loadUserPhraseReplacement; + (void)setupDataModelValueConverter; + (BOOL)checkIfUserLanguageModelFilesExist; ++ (BOOL)checkIfUserDataFolderExists; + (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase key:(NSString *)key NS_SWIFT_NAME(checkIfExist(userPhrase:key:)); + (BOOL)writeUserPhrase:(NSString *)userPhrase inputMode:(InputMode)mode;