diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index e98fe4c7d..4f0d47908 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -271,10 +271,18 @@ 62E2BF4B2B4082BA00E42D38 /* AliResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E2BF482B4082BA00E42D38 /* AliResponse.swift */; }; 62E2BF4C2B4082BA00E42D38 /* AliTranslateType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62E2BF492B4082BA00E42D38 /* AliTranslateType.swift */; }; 62ED29A22B15F1F500901F51 /* EZWrapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 62ED29A12B15F1F500901F51 /* EZWrapView.m */; }; - 960835502B6791F200C6A931 /* ShortcutValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9608354F2B6791F200C6A931 /* ShortcutValidator.swift */; }; + 960835502B6791F200C6A931 /* Shortcut+Validator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9608354F2B6791F200C6A931 /* Shortcut+Validator.swift */; }; 96099AE22B5D40330055C4DD /* ShortcutTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96099AE12B5D40330055C4DD /* ShortcutTab.swift */; }; - 9627F9382B59956800B1E999 /* GeneralShortcutSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9627F9352B59956800B1E999 /* GeneralShortcutSetting.swift */; }; - 9627F9392B59956800B1E999 /* GeneralKeyHolderWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9627F9362B59956800B1E999 /* GeneralKeyHolderWrapper.swift */; }; + 9627F9382B59956800B1E999 /* GlobalShortcutSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9627F9352B59956800B1E999 /* GlobalShortcutSetting.swift */; }; + 9627F9392B59956800B1E999 /* KeyHolderWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9627F9362B59956800B1E999 /* KeyHolderWrapper.swift */; }; + 9643D9392B6F49E0000FBEA6 /* AppShortcutSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9382B6F49E0000FBEA6 /* AppShortcutSetting.swift */; }; + 9643D93D2B6F829C000FBEA6 /* MainMenuCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D93C2B6F829C000FBEA6 /* MainMenuCommand.swift */; }; + 9643D9402B6FC426000FBEA6 /* MainMenuShortcutCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D93F2B6FC426000FBEA6 /* MainMenuShortcutCommand.swift */; }; + 9643D9422B6FE4AF000FBEA6 /* Shortcut+Bind.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9412B6FE4AF000FBEA6 /* Shortcut+Bind.swift */; }; + 9643D9442B6FEF5F000FBEA6 /* Shortcut+Default.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9432B6FEF5F000FBEA6 /* Shortcut+Default.swift */; }; + 9643D9462B71D103000FBEA6 /* KeyHolderRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9452B71D103000FBEA6 /* KeyHolderRowView.swift */; }; + 9643D94A2B71EABE000FBEA6 /* KeyHolderAlterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D9492B71EABE000FBEA6 /* KeyHolderAlterView.swift */; }; + 9643D94C2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9643D94B2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift */; }; 9672D7D22B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m in Sources */ = {isa = PBXBuildFile; fileRef = 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */; }; 967712EA2B5B913600105E0F /* KeyHolder in Frameworks */ = {isa = PBXBuildFile; productRef = 967712E92B5B913600105E0F /* KeyHolder */; }; 967712EE2B5B943400105E0F /* Shortcut.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967712ED2B5B943400105E0F /* Shortcut.swift */; }; @@ -290,9 +298,8 @@ DC46DF802B4417B900DEAE3E /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC46DF7F2B4417B900DEAE3E /* Configuration.swift */; }; DC6D9C872B352EBC0055EFFC /* FontSizeHintView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */; }; DC6D9C892B3969510055EFFC /* Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC6D9C882B3969510055EFFC /* Appearance.swift */; }; - EA1013442B5DBDB1005E43F9 /* KeyCombo+Defaults.Serializable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1013432B5DBDB1005E43F9 /* KeyCombo+Defaults.Serializable.swift */; }; - EA3B81F92B5254AA004C0E8B /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3B81F82B5254AA004C0E8B /* Configuration.swift */; }; DCF176F22B57CED700CA6026 /* Configuration+UserData.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCF176F12B57CED700CA6026 /* Configuration+UserData.swift */; }; + EA1013442B5DBDB1005E43F9 /* KeyCombo+Defaults.Serializable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA1013432B5DBDB1005E43F9 /* KeyCombo+Defaults.Serializable.swift */; }; EA3B81F92B5254AA004C0E8B /* Configuration+Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3B81F82B5254AA004C0E8B /* Configuration+Defaults.swift */; }; EA3B81FC2B52555C004C0E8B /* Defaults in Frameworks */ = {isa = PBXBuildFile; productRef = EA3B81FB2B52555C004C0E8B /* Defaults */; }; EA9943E32B534C3300EE7B97 /* TTSServiceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA9943E22B534C3300EE7B97 /* TTSServiceType.swift */; }; @@ -787,10 +794,18 @@ 62ED29A12B15F1F500901F51 /* EZWrapView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZWrapView.m; sourceTree = ""; }; 6372B33DFF803C7096A82250 /* Pods_Easydict.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Easydict.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 91E3E579C6DB88658B4BB102 /* Pods-Easydict.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Easydict.release.xcconfig"; path = "Target Support Files/Pods-Easydict/Pods-Easydict.release.xcconfig"; sourceTree = ""; }; - 9608354F2B6791F200C6A931 /* ShortcutValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutValidator.swift; sourceTree = ""; }; + 9608354F2B6791F200C6A931 /* Shortcut+Validator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Shortcut+Validator.swift"; sourceTree = ""; }; 96099AE12B5D40330055C4DD /* ShortcutTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutTab.swift; sourceTree = ""; }; - 9627F9352B59956800B1E999 /* GeneralShortcutSetting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralShortcutSetting.swift; sourceTree = ""; }; - 9627F9362B59956800B1E999 /* GeneralKeyHolderWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralKeyHolderWrapper.swift; sourceTree = ""; }; + 9627F9352B59956800B1E999 /* GlobalShortcutSetting.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlobalShortcutSetting.swift; sourceTree = ""; }; + 9627F9362B59956800B1E999 /* KeyHolderWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyHolderWrapper.swift; sourceTree = ""; }; + 9643D9382B6F49E0000FBEA6 /* AppShortcutSetting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppShortcutSetting.swift; sourceTree = ""; }; + 9643D93C2B6F829C000FBEA6 /* MainMenuCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuCommand.swift; sourceTree = ""; }; + 9643D93F2B6FC426000FBEA6 /* MainMenuShortcutCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuShortcutCommand.swift; sourceTree = ""; }; + 9643D9412B6FE4AF000FBEA6 /* Shortcut+Bind.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Shortcut+Bind.swift"; sourceTree = ""; }; + 9643D9432B6FEF5F000FBEA6 /* Shortcut+Default.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Shortcut+Default.swift"; sourceTree = ""; }; + 9643D9452B71D103000FBEA6 /* KeyHolderRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyHolderRowView.swift; sourceTree = ""; }; + 9643D9492B71EABE000FBEA6 /* KeyHolderAlterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyHolderAlterView.swift; sourceTree = ""; }; + 9643D94B2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenuShortcutCommandItem.swift; sourceTree = ""; }; 9672D7D02B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MASShortcutBinder+EZMASShortcutBinder.h"; sourceTree = ""; }; 9672D7D12B4008B40023B8FB /* MASShortcutBinder+EZMASShortcutBinder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "MASShortcutBinder+EZMASShortcutBinder.m"; sourceTree = ""; }; 967712ED2B5B943400105E0F /* Shortcut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shortcut.swift; sourceTree = ""; }; @@ -807,9 +822,8 @@ DC46DF7F2B4417B900DEAE3E /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; DC6D9C862B352EBC0055EFFC /* FontSizeHintView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontSizeHintView.swift; sourceTree = ""; }; DC6D9C882B3969510055EFFC /* Appearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Appearance.swift; sourceTree = ""; }; - EA1013432B5DBDB1005E43F9 /* KeyCombo+Defaults.Serializable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyCombo+Defaults.Serializable.swift"; sourceTree = ""; }; - EA3B81F82B5254AA004C0E8B /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; DCF176F12B57CED700CA6026 /* Configuration+UserData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Configuration+UserData.swift"; sourceTree = ""; }; + EA1013432B5DBDB1005E43F9 /* KeyCombo+Defaults.Serializable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KeyCombo+Defaults.Serializable.swift"; sourceTree = ""; }; EA3B81F82B5254AA004C0E8B /* Configuration+Defaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Configuration+Defaults.swift"; sourceTree = ""; }; EA9943E22B534C3300EE7B97 /* TTSServiceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TTSServiceType.swift; sourceTree = ""; }; EA9943E72B534D8900EE7B97 /* LanguageDetectOptimizeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageDetectOptimizeExtensions.swift; sourceTree = ""; }; @@ -2133,6 +2147,7 @@ 27FE98062B3DD525000AD654 /* View */ = { isa = PBXGroup; children = ( + 9643D93E2B6FC405000FBEA6 /* MenuView */, 27FE980A2B3DD5D1000AD654 /* MenuItemView.swift */, 0AC11B212B4D16A500F07198 /* WindowAccessor.swift */, 0AC11B232B4E46B300F07198 /* TapHandlerView.swift */, @@ -2224,12 +2239,25 @@ 9627F9342B59956800B1E999 /* Shortcut */ = { isa = PBXGroup; children = ( - 9627F9352B59956800B1E999 /* GeneralShortcutSetting.swift */, - 9627F9362B59956800B1E999 /* GeneralKeyHolderWrapper.swift */, + 9627F9352B59956800B1E999 /* GlobalShortcutSetting.swift */, + 9627F9362B59956800B1E999 /* KeyHolderWrapper.swift */, + 9643D9382B6F49E0000FBEA6 /* AppShortcutSetting.swift */, + 9643D9452B71D103000FBEA6 /* KeyHolderRowView.swift */, + 9643D9492B71EABE000FBEA6 /* KeyHolderAlterView.swift */, ); path = Shortcut; sourceTree = ""; }; + 9643D93E2B6FC405000FBEA6 /* MenuView */ = { + isa = PBXGroup; + children = ( + 9643D93C2B6F829C000FBEA6 /* MainMenuCommand.swift */, + 9643D93F2B6FC426000FBEA6 /* MainMenuShortcutCommand.swift */, + 9643D94B2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift */, + ); + path = MenuView; + sourceTree = ""; + }; 967712EB2B5B93E200105E0F /* Feature */ = { isa = PBXGroup; children = ( @@ -2242,7 +2270,9 @@ isa = PBXGroup; children = ( 967712ED2B5B943400105E0F /* Shortcut.swift */, - 9608354F2B6791F200C6A931 /* ShortcutValidator.swift */, + 9643D9432B6FEF5F000FBEA6 /* Shortcut+Default.swift */, + 9643D9412B6FE4AF000FBEA6 /* Shortcut+Bind.swift */, + 9608354F2B6791F200C6A931 /* Shortcut+Validator.swift */, ); path = Shortcut; sourceTree = ""; @@ -2777,7 +2807,7 @@ 62E2BF4A2B4082BA00E42D38 /* AliService.swift in Sources */, 03B0233729231FA6001C7E63 /* MMMake.m in Sources */, 03B0232E29231FA6001C7E63 /* MMCrashSignalExceptionHandler.m in Sources */, - 9627F9382B59956800B1E999 /* GeneralShortcutSetting.swift in Sources */, + 9627F9382B59956800B1E999 /* GlobalShortcutSetting.swift in Sources */, 03BDA7C42A26DA280079D04F /* NSDictionary+RubyDescription.m in Sources */, 62ED29A22B15F1F500901F51 /* EZWrapView.m in Sources */, C4DD01EB2B12BA250025EE8E /* TencentResponse.swift in Sources */, @@ -2803,7 +2833,7 @@ 03B3B8B22925D5B200168E8D /* EZPopButtonWindow.m in Sources */, 03B0231529231FA6001C7E63 /* SnipWindow.m in Sources */, 033363A0293A05D200FED9C8 /* EZSelectLanguageButton.m in Sources */, - 960835502B6791F200C6A931 /* ShortcutValidator.swift in Sources */, + 960835502B6791F200C6A931 /* Shortcut+Validator.swift in Sources */, 03542A522937B69200C34C33 /* EZYoudaoTranslateResponse.m in Sources */, 03B0230129231FA6001C7E63 /* EZQueryView.m in Sources */, 03542A3D2937AF4F00C34C33 /* EZQueryResult.m in Sources */, @@ -2835,6 +2865,7 @@ 0AC8A8392B666F07006DA5CC /* CaiyunService+ConfigurableService.swift in Sources */, 27FE980B2B3DD5D1000AD654 /* MenuItemView.swift in Sources */, 03DC7C6A2A3CA852000BF7C9 /* EZAppCell.m in Sources */, + 9643D9392B6F49E0000FBEA6 /* AppShortcutSetting.swift in Sources */, 96099AE22B5D40330055C4DD /* ShortcutTab.swift in Sources */, 0399C6AC29A860AA00B4AFCC /* EZOpenAIService.m in Sources */, 03542A432937B45E00C34C33 /* EZBaiduTranslate.m in Sources */, @@ -2855,6 +2886,7 @@ 039F5506294B6E29004AB940 /* EZSettingViewController.m in Sources */, 03BD281E29481C0400F5891A /* EZAudioPlayer.m in Sources */, 0A8685C82B552A590022534F /* DisabledAppTab.swift in Sources */, + 9643D94A2B71EABE000FBEA6 /* KeyHolderAlterView.swift in Sources */, 03E02A2629250D1D00A10260 /* EZEventMonitor.m in Sources */, 03B0233429231FA6001C7E63 /* MMConsoleLogFormatter.m in Sources */, 037852B9295D49F900D0E2CF /* EZTableRowView.m in Sources */, @@ -2888,14 +2920,17 @@ 0396D615292CC4C3006A11D9 /* EZLocalStorage.m in Sources */, 0329CD6F29EE924500963F78 /* EZRightClickDetector.m in Sources */, 033C30FC2A7409C40095926A /* TTTDictionary.m in Sources */, + 9643D93D2B6F829C000FBEA6 /* MainMenuCommand.swift in Sources */, 03B0232D29231FA6001C7E63 /* NSArray+MM.m in Sources */, 039E5021296E5D9900072344 /* EZScrollViewController.m in Sources */, + 9643D94C2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift in Sources */, 0AC8A8412B695480006DA5CC /* DeepLTranslate+ConfigurableService.swift in Sources */, 039CC90D292F664E0037B91E /* NSObject+EZWindowType.m in Sources */, 03B0232229231FA6001C7E63 /* NSImage+MM.m in Sources */, 03BB2DEF29F59C8A00447EDD /* EZSymbolImageButton.m in Sources */, 0A2BA9642B4A3CCD002872A4 /* Notification+Name.swift in Sources */, C415C0AD2B450D4800A9D231 /* GeminiService.swift in Sources */, + 9643D9402B6FC426000FBEA6 /* MainMenuShortcutCommand.swift in Sources */, 62A2D03F2A82967F007EEB01 /* EZBingRequest.m in Sources */, 03BDA7BE2A26DA280079D04F /* XPMCountedArgument.m in Sources */, 038A72402B62C0B9004995E3 /* String+Regex.swift in Sources */, @@ -2904,6 +2939,7 @@ DC6D9C892B3969510055EFFC /* Appearance.swift in Sources */, 0396D611292C932F006A11D9 /* EZSelectLanguageCell.m in Sources */, 036196752A000F5900806370 /* FWEncryptorAES.m in Sources */, + 9643D9462B71D103000FBEA6 /* KeyHolderRowView.swift in Sources */, 0399C6A829A74E0F00B4AFCC /* EZQueryResult+EZDeepLTranslateResponse.m in Sources */, 039B694F2A9D9F370063709D /* EZWebViewManager.m in Sources */, 03B0231629231FA6001C7E63 /* SnipFocusView.m in Sources */, @@ -2936,6 +2972,7 @@ 27FE98052B3DCB09000AD654 /* NewAppManager.swift in Sources */, 0399116A292AA2EF00E1B06D /* EZLayoutManager.m in Sources */, 0320C5872B29F35700861B3D /* QueryServiceRecord.swift in Sources */, + 9643D9422B6FE4AF000FBEA6 /* Shortcut+Bind.swift in Sources */, 03FC699A2B39D13A0035D2DA /* EZOpenAIChatResponse.m in Sources */, 03B022FA29231FA6001C7E63 /* EZServiceTypes.m in Sources */, EAE3D3502B62E9DE001EE3E3 /* GlobalContext.swift in Sources */, @@ -2943,7 +2980,7 @@ 03B0233129231FA6001C7E63 /* MMCrash.m in Sources */, 03B0232629231FA6001C7E63 /* NSAttributedString+MM.m in Sources */, 03542A402937B3C900C34C33 /* EZOCRResult.m in Sources */, - 9627F9392B59956800B1E999 /* GeneralKeyHolderWrapper.swift in Sources */, + 9627F9392B59956800B1E999 /* KeyHolderWrapper.swift in Sources */, C4DD01E92B12B3C80025EE8E /* TencentService.swift in Sources */, 0A2BA9602B49A989002872A4 /* Binding+DidSet.swift in Sources */, EA9943E32B534C3300EE7B97 /* TTSServiceType.swift in Sources */, @@ -2963,6 +3000,7 @@ 03BDA7B92A26DA280079D04F /* NSProcessInfo+XPMArgumentParser.m in Sources */, 03542A4F2937B64B00C34C33 /* EZYoudaoOCRResponse.m in Sources */, 03B0233929231FA6001C7E63 /* MMTool.m in Sources */, + 9643D9442B6FEF5F000FBEA6 /* Shortcut+Default.swift in Sources */, 03542A552937B7DE00C34C33 /* EZError.m in Sources */, 17BCAEF72B0DFF9000A7D372 /* EZNiuTransTranslateResponse.m in Sources */, 03BDA7B82A26DA280079D04F /* XPMValuedArgument.m in Sources */, diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index a2ab7b33c..fe1356419 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -169,6 +169,23 @@ } } }, + "app_shortcut_setting" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "App Shortcut" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "应用内快捷键" + } + } + } + }, "appearenceType_dark" : { "localizations" : { "en" : { @@ -2376,7 +2393,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "打开窗口时自动选中查询文本" } } @@ -3563,6 +3580,40 @@ } } }, + "shortcut_clear_all" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Clear All" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "清空所有" + } + } + } + }, + "shortcut_clear_input" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Clear Input" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "清空查询内容" + } + } + } + }, "shortcut_confict %@" : { "extractionState" : "manual", "localizations" : { @@ -3598,7 +3649,14 @@ } }, "shortcut_confict_message (Shortcut.shared.confictMenuItem?.title ?? \"\")" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "" + } + } + } }, "shortcut_confict_message %@" : { "extractionState" : "manual", @@ -3618,7 +3676,14 @@ } }, "shortcut_confict_title (keyCombo!.keyEquivalentModifierMaskString + keyCombo!.characters)" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "" + } + } + } }, "shortcut_confict_title %@" : { "extractionState" : "manual", @@ -3637,6 +3702,108 @@ } } }, + "shortcut_copy" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Copy" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "复制文本" + } + } + } + }, + "shortcut_copy_first_translated_text" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Copy first translated text" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "复制第一个翻译结果" + } + } + } + }, + "shortcut_decrease_font" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Decrease Font Size" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "减小字体" + } + } + } + }, + "shortcut_focus" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Focus" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "聚焦" + } + } + } + }, + "shortcut_increase_font" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Increase Font Size" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "增大字体" + } + } + } + }, + "shortcut_play" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Play" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "播放单词发音" + } + } + } + }, "shortcut_select_translate_window_type" : { "localizations" : { "en" : { diff --git a/Easydict/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index 214e1bb5c..240aed001 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -10,6 +10,12 @@ import Defaults import Foundation import Magnet +/// Utils +extension Defaults.Keys { + /// is first launch + static let firstLaunch = Key("EZConfiguration_kFirstLaunch", default: true) +} + // Setting extension Defaults.Keys { // rename `from` @@ -171,9 +177,27 @@ extension Defaults.Keys { /// shortcut extension Defaults.Keys { - static let selectionShortcut = Key("EZSelectionShortcutKey_keyHolder", default: nil) - static let snipShortcut = Key("EZSnipShortcutKey_keyHolder", default: nil) - static let inputShortcut = Key("EZInputShortcutKey_keyHolder", default: nil) - static let screenshotOCRShortcut = Key("EZScreenshotOCRShortcutKey_keyHolder", default: nil) - static let showMiniWindowShortcut = Key("EZShowMiniShortcutKey_keyHolder", default: nil) + // Global + static let selectionShortcut = Key("EZSelectionShortcutKey_keyHolder") + static let snipShortcut = Key("EZSnipShortcutKey_keyHolder") + static let inputShortcut = Key("EZInputShortcutKey_keyHolder") + static let screenshotOCRShortcut = Key("EZScreenshotOCRShortcutKey_keyHolder") + static let showMiniWindowShortcut = Key("EZShowMiniShortcutKey_keyHolder") + + // App + static let clearInputShortcut = Key("EZClearInputShortcutKey_keyHolder") + static let clearAllShortcut = Key("EZClearAllShortcutKey_keyHolder") + static let copyShortcut = Key("EZCopyShortcutKey_keyHolder") + static let copyFirstResultShortcut = Key("EZCopyFirstResultShortcutKey_keyHolder") + static let focusShortcut = Key("EZFocusShortcutKey_keyHolder") + static let playShortcut = Key("EZPlayShortcutKey_keyHolder") + static let retryShortcut = Key("EZRetryShortcutKey_keyHolder") + static let toggleShortcut = Key("EZToggleShortcutKey_keyHolder") + static let pinShortcut = Key("EZPinShortcutKey_keyHolder") + static let hideShortcut = Key("EZHideShortcutKey_keyHolder") + static let increaseFontSize = Key("EZIncreaseFontSizeShortcutKey_keyHolder") + static let decreaseFontSize = Key("EZDecreaseFontSizeShortcutKey_keyHolder") + static let googleShortcut = Key("EZGoogleShortcutKey_keyHolder") + static let eudicShortcut = Key("EZEudicShortcutKey_keyHolder") + static let appleDictionaryShortcut = Key("EZAppleDictionaryShortcutKey_keyHolder") } diff --git a/Easydict/NewApp/EasydictApp.swift b/Easydict/NewApp/EasydictApp.swift index 95e985b93..9743e4dc4 100644 --- a/Easydict/NewApp/EasydictApp.swift +++ b/Easydict/NewApp/EasydictApp.swift @@ -52,7 +52,11 @@ struct EasydictApp: App { .scaledToFit() } .help("Easydict 🍃") - }.menuBarExtraStyle(.menu) + } + .menuBarExtraStyle(.menu) + .commands { + EasyDictMainMenu() // main menu + } Settings { SettingView() } diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut+Bind.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut+Bind.swift new file mode 100644 index 000000000..37008348c --- /dev/null +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut+Bind.swift @@ -0,0 +1,96 @@ +// +// Shortcut+Bind.swift +// Easydict +// +// Created by Sharker on 2024/2/4. +// Copyright © 2024 izual. All rights reserved. +// + +// App shortcut binding func +extension Shortcut { + @objc func clearInput() { + EZWindowManager.shared().clearInput() + } + + @objc func clearAll() { + EZWindowManager.shared().clearAll() + } + + @objc func shortcutCopy() { + EZWindowManager.shared().copyQueryText() + } + + @objc func shortcutCopyFirstResult() { + EZWindowManager.shared().copyFirstTranslatedText() + } + + @objc func shortcutFocus() { + EZWindowManager.shared().focusInputTextView() + } + + @objc func shortcutPlay() { + EZWindowManager.shared().playOrStopQueryTextAudio() + } + + @objc func shortcutRetry() { + EZWindowManager.shared().rerty() + } + + @objc func shortcutToggle() { + EZWindowManager.shared().toggleTranslationLanguages() + } + + @objc func shortcutPin() { + EZWindowManager.shared().pin() + } + + @objc func shortcutHide() { + EZWindowManager.shared().closeWindowOrExitSreenshot() + } + + @objc func increaseFontSize() { + Configuration.shared.fontSizeIndex += 1 + } + + @objc func decreaseFontSize() { + Configuration.shared.fontSizeIndex -= 1 + } + + @objc func shortcutGoogle() { + let window = EZWindowManager.shared().floatingWindow + window?.titleBar.googleButton.openLink() + } + + @objc func shortcutEudic() { + let window = EZWindowManager.shared().floatingWindow + window?.titleBar.eudicButton.openLink() + } + + @objc func shortcutAppleDic() { + let window = EZWindowManager.shared().floatingWindow + window?.titleBar.appleDictionaryButton.openLink() + } +} + +// global shortcut binding func +extension Shortcut { + @objc func selectTextTranslate() { + EZWindowManager.shared().selectTextTranslate() + } + + @objc func snipTranslate() { + EZWindowManager.shared().snipTranslate() + } + + @objc func inputTranslate() { + EZWindowManager.shared().inputTranslate() + } + + @objc func showMiniFloatingWindow() { + EZWindowManager.shared().showMiniFloatingWindow() + } + + @objc func screenshotOCR() { + EZWindowManager.shared().screenshotOCR() + } +} diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift new file mode 100644 index 000000000..d48d74d1d --- /dev/null +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift @@ -0,0 +1,31 @@ +// +// Shortcut+Default.swift +// Easydict +// +// Created by Sharker on 2024/2/5. +// Copyright © 2024 izual. All rights reserved. +// + +import Defaults +import Magnet + +extension Shortcut { + // set defalut for app shortcut + func setDefaultForAppShortcut() { + Defaults[.clearInputShortcut] = KeyCombo(key: .k, cocoaModifiers: .command) + Defaults[.clearAllShortcut] = KeyCombo(key: .k, cocoaModifiers: [.command, .shift]) + Defaults[.copyShortcut] = KeyCombo(key: .c, cocoaModifiers: [.command, .shift]) + Defaults[.copyFirstResultShortcut] = KeyCombo(key: .j, cocoaModifiers: [.command, .shift]) + Defaults[.focusShortcut] = KeyCombo(key: .i, cocoaModifiers: .command) + Defaults[.playShortcut] = KeyCombo(key: .s, cocoaModifiers: .command) + Defaults[.retryShortcut] = KeyCombo(key: .r, cocoaModifiers: .command) + Defaults[.toggleShortcut] = KeyCombo(key: .t, cocoaModifiers: .command) + Defaults[.pinShortcut] = KeyCombo(key: .p, cocoaModifiers: .command) + Defaults[.hideShortcut] = KeyCombo(key: .y, cocoaModifiers: .command) + Defaults[.increaseFontSize] = KeyCombo(key: .keypadPlus, cocoaModifiers: .command) + Defaults[.decreaseFontSize] = KeyCombo(key: .keypadMinus, cocoaModifiers: .command) + Defaults[.googleShortcut] = KeyCombo(key: .return, cocoaModifiers: .command) + Defaults[.eudicShortcut] = KeyCombo(key: .return, cocoaModifiers: [.command, .shift]) + Defaults[.appleDictionaryShortcut] = KeyCombo(key: .d, cocoaModifiers: [.command, .shift]) + } +} diff --git a/Easydict/NewApp/Feature/Shortcut/ShortcutValidator.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut+Validator.swift similarity index 99% rename from Easydict/NewApp/Feature/Shortcut/ShortcutValidator.swift rename to Easydict/NewApp/Feature/Shortcut/Shortcut+Validator.swift index 0f818a228..f7590400e 100644 --- a/Easydict/NewApp/Feature/Shortcut/ShortcutValidator.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut+Validator.swift @@ -1,5 +1,5 @@ // -// ShortcutValidator.swift +// Shortcut+Validator.swift // Easydict // // Created by Sharker on 2024/1/29. diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift index 434c33c77..c08c2dc2a 100644 --- a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift @@ -13,11 +13,75 @@ import SwiftUI /// Shortcut Service public enum ShortcutType: String { + // Global case inputTranslate = "EZInputShortcutKey" case snipTranslate = "EZSnipShortcutKey" case selectTranslate = "EZSelectionShortcutKey" case silentScreenshotOcr = "EZScreenshotOCRShortcutKey" case showMiniWindow = "EZShowMiniShortcutKey" + // In App + case clearInput = "EZClearInputShortcutKey" + case clearAll = "EZClearAllShortcutKey" + case copy = "EZCopyShortcutKey" + case copyFirstResult = "EZCopyFirstResultShortcutKey" + case focus = "EZFocusShortcutKey" + case play = "EZPlayShortcutKey" + case retry = "EZRetryShortcutKey" + case toggle = "EZToggleShortcutKey" + case pin = "EZPinShortcutKey" + case hide = "EZHideShortcutKey" + case increaseFontSize = "EZIncreaseFontSizeShortcutKey" + case decreaseFontSize = "EZDecreaseFontSizeShortcutKey" + case google = "EZGoogleShortcutKey" + case eudic = "EZEudicShortcutKey" + case appleDic = "EZAppleDicShortcutKey" +} + +extension ShortcutType { + func localizedStringKey() -> String { + switch self { + case .inputTranslate: + "input_translate" + case .snipTranslate: + "snip_translate" + case .selectTranslate: + "select_translate" + case .silentScreenshotOcr: + "silent_screenshot_ocr" + case .showMiniWindow: + "show_mini_window" + case .clearInput: + "shortcut_clear_input" + case .clearAll: + "shortcut_clear_all" + case .copy: + "shortcut_copy" + case .copyFirstResult: + "shortcut_copy_first_translated_text" + case .focus: + "shortcut_focus" + case .play: + "shortcut_play" + case .retry: + "retry" + case .toggle: + "toggle_languages" + case .pin: + "pin" + case .hide: + "hide" + case .increaseFontSize: + "shortcut_increase_font" + case .decreaseFontSize: + "shortcut_decrease_font" + case .google: + "open_in_google" + case .eudic: + "open_in_eudic" + case .appleDic: + "open_in_apple_dictionary" + } + } } // Confict Message @@ -35,6 +99,14 @@ class Shortcut: NSObject { @objc static func setupShortcut() { let shortcut = Shortcut.shared shortcut.restoreShortcut() + + if Defaults[.firstLaunch] { + Defaults[.firstLaunch] = false + // set defalut for app shortcut + shortcut.setDefaultForAppShortcut() + } else { + // do nothing + } } // Make sure the class has only one instance @@ -78,7 +150,7 @@ extension Shortcut { HotKeyCenter.shared.unregisterHotKey(with: type.rawValue) return } - var hotKey: HotKey + var hotKey: HotKey? switch type { case .inputTranslate: hotKey = HotKey(identifier: type.rawValue, @@ -105,54 +177,10 @@ extension Shortcut { keyCombo: keyCombo, target: Shortcut.shared, action: #selector(Shortcut.showMiniFloatingWindow)) + default: () } - hotKey.register() - } -} - -// shortcut binding func -extension Shortcut { - @objc func selectTextTranslate() { - EZWindowManager.shared().selectTextTranslate() - } - @objc func snipTranslate() { - EZWindowManager.shared().snipTranslate() - } - - @objc func inputTranslate() { - EZWindowManager.shared().inputTranslate() - } - - @objc func showMiniFloatingWindow() { - EZWindowManager.shared().showMiniFloatingWindow() - } - - @objc func screenshotOCR() { - EZWindowManager.shared().screenshotOCR() - } -} - -// fetch shortcut KeyCombo -extension Shortcut { - public func shortcutKeyCombo(_ type: ShortcutType) -> KeyCombo? { - switch type { - case .inputTranslate: - guard let keyCombo = Defaults[.inputShortcut] else { return nil } - return keyCombo - case .snipTranslate: - guard let keyCombo = Defaults[.snipShortcut] else { return nil } - return keyCombo - case .selectTranslate: - guard let keyCombo = Defaults[.selectionShortcut] else { return nil } - return keyCombo - case .silentScreenshotOcr: - guard let keyCombo = Defaults[.screenshotOCRShortcut] else { return nil } - return keyCombo - case .showMiniWindow: - guard let keyCombo = Defaults[.showMiniWindowShortcut] else { return nil } - return keyCombo - } + hotKey?.register() } } @@ -169,6 +197,36 @@ struct KeyboardShortcut: ViewModifier { .screenshotOCRShortcut case .showMiniWindow: .showMiniWindowShortcut + case .clearInput: + .clearInputShortcut + case .clearAll: + .clearAllShortcut + case .copy: + .copyShortcut + case .copyFirstResult: + .copyFirstResultShortcut + case .focus: + .focusShortcut + case .play: + .playShortcut + case .retry: + .retryShortcut + case .toggle: + .toggleShortcut + case .pin: + .pinShortcut + case .hide: + .hideShortcut + case .increaseFontSize: + .increaseFontSize + case .decreaseFontSize: + .decreaseFontSize + case .google: + .googleShortcut + case .eudic: + .eudicShortcut + case .appleDic: + .appleDictionaryShortcut } _shortcut = .init(key) diff --git a/Easydict/NewApp/View/MenuView/MainMenuCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuCommand.swift new file mode 100644 index 000000000..84231b7bf --- /dev/null +++ b/Easydict/NewApp/View/MenuView/MainMenuCommand.swift @@ -0,0 +1,18 @@ +// +// MainMenuCommand.swift +// Easydict +// +// Created by Sharker on 2024/2/4. +// Copyright © 2024 izual. All rights reserved. +// + +import SwiftUI + +struct EasyDictMainMenu: Commands { + var body: some Commands { + // shortcut + MainMenuShortcutCommand() + } + + func showAPIWebSite() {} +} diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift new file mode 100644 index 000000000..82ff53423 --- /dev/null +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -0,0 +1,40 @@ +// +// MainMenuShortcutCommand.swift +// Easydict +// +// Created by Sharker on 2024/2/4. +// Copyright © 2024 izual. All rights reserved. +// + +import SwiftUI + +extension EasyDictMainMenu { + struct MainMenuShortcutCommand: Commands { + @State private var appShortcutCommandList = [ + MainMenuShortcutCommandDataItem(type: .clearInput), + MainMenuShortcutCommandDataItem(type: .clearAll), + MainMenuShortcutCommandDataItem(type: .copy), + MainMenuShortcutCommandDataItem(type: .copyFirstResult), + MainMenuShortcutCommandDataItem(type: .focus), + MainMenuShortcutCommandDataItem(type: .play), + MainMenuShortcutCommandDataItem(type: .retry), + MainMenuShortcutCommandDataItem(type: .toggle), + MainMenuShortcutCommandDataItem(type: .pin), + MainMenuShortcutCommandDataItem(type: .hide), + MainMenuShortcutCommandDataItem(type: .increaseFontSize), + MainMenuShortcutCommandDataItem(type: .decreaseFontSize), + MainMenuShortcutCommandDataItem(type: .google), + MainMenuShortcutCommandDataItem(type: .eudic), + MainMenuShortcutCommandDataItem(type: .appleDic), + ] + + var body: some Commands { + // shortcut Commands + CommandMenu("shortcut") { + ForEach(appShortcutCommandList) { item in + MainMenuShortcutCommandItem(dataItem: item) + } + } + } + } +} diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift new file mode 100644 index 000000000..669057c9f --- /dev/null +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift @@ -0,0 +1,61 @@ +// +// MainMenuShortcutCommandItem.swift +// Easydict +// +// Created by Sharker on 2024/2/6. +// Copyright © 2024 izual. All rights reserved. +// + +import SwiftUI + +struct MainMenuShortcutCommandDataItem: Identifiable { + public var id: String { type.localizedStringKey() } + var type: ShortcutType +} + +struct MainMenuShortcutCommandItem: View { + public var dataItem: MainMenuShortcutCommandDataItem + + var body: some View { + Button(LocalizedStringKey(dataItem.type.localizedStringKey())) { + switch dataItem.type { + case .clearInput: + Shortcut.shared.clearInput() + case .clearAll: + Shortcut.shared.clearAll() + case .copy: + Shortcut.shared.shortcutCopy() + case .copyFirstResult: + Shortcut.shared.shortcutCopyFirstResult() + case .focus: + Shortcut.shared.shortcutFocus() + case .play: + Shortcut.shared.shortcutPlay() + case .retry: + Shortcut.shared.shortcutRetry() + case .toggle: + Shortcut.shared.shortcutToggle() + case .pin: + Shortcut.shared.shortcutPin() + case .hide: + Shortcut.shared.shortcutHide() + case .increaseFontSize: + Shortcut.shared.increaseFontSize() + case .decreaseFontSize: + Shortcut.shared.decreaseFontSize() + case .google: + Shortcut.shared.shortcutGoogle() + case .eudic: + Shortcut.shared.shortcutEudic() + case .appleDic: + Shortcut.shared.shortcutAppleDic() + default: () + } + } + .keyboardShortcut(dataItem.type) + + if dataItem.type == .toggle || dataItem.type == .decreaseFontSize { + Divider() + } + } +} diff --git a/Easydict/NewApp/View/SettingView/SettingView.swift b/Easydict/NewApp/View/SettingView/SettingView.swift index 643ee1c23..2d73db6f0 100644 --- a/Easydict/NewApp/View/SettingView/SettingView.swift +++ b/Easydict/NewApp/View/SettingView/SettingView.swift @@ -36,13 +36,14 @@ struct SettingView: View { DisabledAppTab() .tabItem { Label("disabled_app_list", systemImage: "nosign") } .tag(SettingTab.disabled) - AdvancedTab() - .tabItem { Label("advanced", systemImage: "gearshape.2") } - .tag(SettingTab.advanced) ShortcutTab() .tabItem { Label("shortcut", systemImage: "command.square") } .tag(SettingTab.shortcut) + + AdvancedTab() + .tabItem { Label("advanced", systemImage: "gearshape.2") } + .tag(SettingTab.advanced) PrivacyTab() .tabItem { Label("privacy", systemImage: "hand.raised.square") } .tag(SettingTab.privacy) @@ -65,24 +66,22 @@ struct SettingView: View { func resizeWindowFrame() { guard let window else { return } - // Disable zoom button, ref: https://stackoverflow.com/a/66039864/8378840 + // Disable zoom button, refer: https://stackoverflow.com/a/66039864/8378840 window.standardWindowButton(.zoomButton)?.isEnabled = false // Keep the settings page windows all the same width to avoid strange animations. - let maxWidth = 750 + let maxWidth = 780 let height = switch selection { - case .general: - maxWidth - 100 - case .service: - 600 - case .disabled, .shortcut: + case .disabled: 500 + case .advanced: + 400 case .privacy: 320 case .about: 450 default: - 400 + maxWidth - 110 } let newSize = CGSize(width: maxWidth, height: height) diff --git a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift index 52daaabe6..558bcb5cc 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift @@ -13,9 +13,11 @@ struct ShortcutTab: View { var body: some View { Form { // Global shortcut - GeneralShortcutSettingView() + GlobalShortcutSettingView() // In app shortcut - }.formStyle(.grouped) + AppShortcutSettingView() + } + .formStyle(.grouped) } } diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift new file mode 100644 index 000000000..62773bb6e --- /dev/null +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -0,0 +1,59 @@ +// +// AppShortcutSetting.swift +// Easydict +// +// Created by Sharker on 2024/2/4. +// Copyright © 2024 izual. All rights reserved. +// + +import SwiftUI + +@available(macOS 13, *) +extension ShortcutTab { + struct AppShortcutSettingView: View { + @State private var shortcutDataList = [ + KeyHolderDataItem(type: .clearInput), + KeyHolderDataItem(type: .clearAll), + KeyHolderDataItem(type: .copy), + KeyHolderDataItem(type: .copyFirstResult), + KeyHolderDataItem(type: .focus), + KeyHolderDataItem(type: .play), + KeyHolderDataItem(type: .retry), + KeyHolderDataItem(type: .toggle), + KeyHolderDataItem(type: .pin), + KeyHolderDataItem(type: .hide), + KeyHolderDataItem(type: .increaseFontSize), + KeyHolderDataItem(type: .decreaseFontSize), + KeyHolderDataItem(type: .google), + KeyHolderDataItem(type: .eudic), + KeyHolderDataItem(type: .appleDic), + ] + @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") + var body: some View { + let showAlter = Binding( + get: { + !confictAlterMessage.message.isEmpty + }, + set: { _ in } + ) + Section { + ForEach(shortcutDataList) { item in + KeyHolderRowView(title: item.type.localizedStringKey(), type: item.type, confictAlterMessage: $confictAlterMessage) + } + } header: { + Text("app_shortcut_setting") + } + + .alert(String(localized: "shortcut_confict \(confictAlterMessage.title)"), + isPresented: showAlter, + presenting: confictAlterMessage) + { _ in + Button(String(localized: "shortcut_confict_confirm")) { + confictAlterMessage = ShortcutConfictAlertMessage(title: "", message: "") + } + } message: { message in + Text(message.message) + } + } + } +} diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralShortcutSetting.swift deleted file mode 100644 index 7387a5b32..000000000 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralShortcutSetting.swift +++ /dev/null @@ -1,69 +0,0 @@ -// -// GeneralShortcutSetting.swift -// Easydict -// -// Created by Sharker on 2024/1/1. -// Copyright © 2024 izual. All rights reserved. -// - -import SwiftUI - -@available(macOS 13, *) -extension ShortcutTab { - struct GeneralShortcutSettingView: View { - @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") - - var body: some View { - let showAlter = Binding( - get: { - if !confictAlterMessage.message.isEmpty { - true - } else { - false - } - }, set: { _ in - } - ) - Section { - HStack { - Text("input_translate") - Spacer() - GeneralKeyHolderWrapper(shortcutType: .inputTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("snip_translate") - Spacer() - GeneralKeyHolderWrapper(shortcutType: .snipTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("select_translate") - Spacer() - GeneralKeyHolderWrapper(shortcutType: .selectTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("show_mini_window") - Spacer() - GeneralKeyHolderWrapper(shortcutType: .showMiniWindow, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("silent_screenshot_ocr") - Spacer() - GeneralKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - } header: { - Text("global_shortcut_setting") - } - - .alert(String(localized: "shortcut_confict \(confictAlterMessage.title)"), - isPresented: showAlter, - presenting: confictAlterMessage) - { _ in - Button(String(localized: "shortcut_confict_confirm")) { - confictAlterMessage = ShortcutConfictAlertMessage(title: "", message: "") - } - } message: { message in - Text(message.message) - } - } - } -} diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift new file mode 100644 index 000000000..0fdcb9083 --- /dev/null +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift @@ -0,0 +1,49 @@ +// +// GlobalShortcutSetting.swift +// Easydict +// +// Created by Sharker on 2024/1/1. +// Copyright © 2024 izual. All rights reserved. +// + +import SwiftUI + +@available(macOS 13, *) +extension ShortcutTab { + struct GlobalShortcutSettingView: View { + @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") + @State private var shortcutDataList = [ + KeyHolderDataItem(type: .inputTranslate), + KeyHolderDataItem(type: .snipTranslate), + KeyHolderDataItem(type: .selectTranslate), + KeyHolderDataItem(type: .showMiniWindow), + KeyHolderDataItem(type: .silentScreenshotOcr), + ] + var body: some View { + let showAlter = Binding( + get: { + !confictAlterMessage.message.isEmpty + }, set: { _ in + } + ) + Section { + ForEach(shortcutDataList) { item in + KeyHolderRowView(title: item.type.localizedStringKey(), type: item.type, confictAlterMessage: $confictAlterMessage) + } + } header: { + Text("global_shortcut_setting") + } + + .alert(String(localized: "shortcut_confict \(confictAlterMessage.title)"), + isPresented: showAlter, + presenting: confictAlterMessage) + { _ in + Button(String(localized: "shortcut_confict_confirm")) { + confictAlterMessage = ShortcutConfictAlertMessage(title: "", message: "") + } + } message: { message in + Text(message.message) + } + } + } +} diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderAlterView.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderAlterView.swift new file mode 100644 index 000000000..5fa9fe233 --- /dev/null +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderAlterView.swift @@ -0,0 +1,42 @@ +// +// KeyHolderAlterView.swift +// Easydict +// +// Created by Sharker on 2024/2/6. +// Copyright © 2024 izual. All rights reserved. +// + +import SwiftUI + +@available(macOS 13, *) +struct KeyHolderAlterView: ViewModifier { + init(showAlter: Binding, confictAlterMessage: Binding) { + _showAlter = showAlter + _confictAlterMessage = confictAlterMessage + } + + @Binding var showAlter: Bool + @Binding public var confictAlterMessage: ShortcutConfictAlertMessage + + func body(content: Content) -> some View { + content + .alert(String(localized: "shortcut_confict \(confictAlterMessage.title)"), + isPresented: $showAlter, + presenting: confictAlterMessage) + { _ in + Button(String(localized: "shortcut_confict_confirm")) { + confictAlterMessage = ShortcutConfictAlertMessage(title: "", message: "") + } + } message: { message in + Text(message.message) + } + } +} + +@available(macOS 13, *) +public extension View { + @ViewBuilder + func keyHolderConfictAlter(_ showAlter: Binding, _ confictAlterMessage: Binding) -> some View { + modifier(KeyHolderAlterView(showAlter: showAlter, confictAlterMessage: confictAlterMessage)) + } +} diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift new file mode 100644 index 000000000..42cbc41d2 --- /dev/null +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift @@ -0,0 +1,24 @@ +// +// KeyHolderRowView.swift +// Easydict +// +// Created by Sharker on 2024/2/6. +// Copyright © 2024 izual. All rights reserved. +// + +import SwiftUI + +@available(macOS 13, *) +struct KeyHolderRowView: View { + @State public var title: String + @State public var type: ShortcutType + @Binding public var confictAlterMessage: ShortcutConfictAlertMessage + + var body: some View { + HStack { + Text(LocalizedStringKey(title)) + Spacer() + KeyHolderWrapper(shortcutType: type, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 26) + } + } +} diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralKeyHolderWrapper.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift similarity index 62% rename from Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralKeyHolderWrapper.swift rename to Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift index e94dfda4e..80ef418be 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralKeyHolderWrapper.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift @@ -1,5 +1,5 @@ // -// GeneralKeyHolderWrapper.swift +// KeyHolderWrapper.swift // Easydict // // Created by Sharker on 2024/1/2. @@ -12,7 +12,12 @@ import KeyHolder import Magnet import SwiftUI -struct GeneralKeyHolderWrapper: NSViewRepresentable { +public struct KeyHolderDataItem: Identifiable { + public var id: String { type.localizedStringKey() } + var type: ShortcutType +} + +struct KeyHolderWrapper: NSViewRepresentable { func makeCoordinator() -> Coordinator { .init(shortcutType: type, confictAlterMessage: $confictAlterMessage) } @@ -39,7 +44,7 @@ struct GeneralKeyHolderWrapper: NSViewRepresentable { func updateNSView(_: NSViewType, context _: Context) {} } -extension GeneralKeyHolderWrapper { +extension KeyHolderWrapper { class Coordinator: NSObject, RecordViewDelegate { private var type: ShortcutType @Binding var confictAlterMessage: ShortcutConfictAlertMessage @@ -91,6 +96,36 @@ extension GeneralKeyHolderWrapper { keyCombo = Defaults[.screenshotOCRShortcut] case .showMiniWindow: keyCombo = Defaults[.showMiniWindowShortcut] + case .clearInput: + keyCombo = Defaults[.clearInputShortcut] + case .clearAll: + keyCombo = Defaults[.clearAllShortcut] + case .copy: + keyCombo = Defaults[.copyShortcut] + case .copyFirstResult: + keyCombo = Defaults[.copyFirstResultShortcut] + case .focus: + keyCombo = Defaults[.focusShortcut] + case .play: + keyCombo = Defaults[.playShortcut] + case .retry: + keyCombo = Defaults[.retryShortcut] + case .toggle: + keyCombo = Defaults[.toggleShortcut] + case .pin: + keyCombo = Defaults[.pinShortcut] + case .hide: + keyCombo = Defaults[.hideShortcut] + case .increaseFontSize: + keyCombo = Defaults[.increaseFontSize] + case .decreaseFontSize: + keyCombo = Defaults[.decreaseFontSize] + case .google: + keyCombo = Defaults[.googleShortcut] + case .eudic: + keyCombo = Defaults[.eudicShortcut] + case .appleDic: + keyCombo = Defaults[.appleDictionaryShortcut] } recordView.keyCombo = keyCombo Shortcut.shared.bindingShortcut(keyCombo: keyCombo, type: type) @@ -109,6 +144,36 @@ extension GeneralKeyHolderWrapper { Defaults[.screenshotOCRShortcut] = keyCombo case .showMiniWindow: Defaults[.showMiniWindowShortcut] = keyCombo + case .clearInput: + Defaults[.clearInputShortcut] = keyCombo + case .clearAll: + Defaults[.clearAllShortcut] = keyCombo + case .copy: + Defaults[.copyShortcut] = keyCombo + case .copyFirstResult: + Defaults[.copyFirstResultShortcut] = keyCombo + case .focus: + Defaults[.focusShortcut] = keyCombo + case .play: + Defaults[.playShortcut] = keyCombo + case .retry: + Defaults[.retryShortcut] = keyCombo + case .toggle: + Defaults[.toggleShortcut] = keyCombo + case .pin: + Defaults[.pinShortcut] = keyCombo + case .hide: + Defaults[.hideShortcut] = keyCombo + case .increaseFontSize: + Defaults[.increaseFontSize] = keyCombo + case .decreaseFontSize: + Defaults[.decreaseFontSize] = keyCombo + case .google: + Defaults[.googleShortcut] = keyCombo + case .eudic: + Defaults[.eudicShortcut] = keyCombo + case .appleDic: + Defaults[.appleDictionaryShortcut] = keyCombo } } }