From 78b445d2e6f45b48ac9fd687849f8e20dfa6f64b Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Sun, 4 Feb 2024 15:52:18 +0800 Subject: [PATCH 01/23] feat: split global shortcut --- Easydict.xcodeproj/project.pbxproj | 26 +-- Easydict/App/Localizable.xcstrings | 153 ++++++++++++++++++ .../Configuration+Defaults.swift | 4 + .../NewApp/Feature/Shortcut/Shortcut.swift | 24 ++- .../NewApp/View/SettingView/SettingView.swift | 7 +- .../View/SettingView/Tabs/ShortcutTab.swift | 3 +- .../View/Shortcut/AppShortcutSetting.swift | 118 ++++++++++++++ ...ting.swift => GlobalShortcutSetting.swift} | 14 +- ...erWrapper.swift => KeyHolderWrapper.swift} | 9 +- 9 files changed, 329 insertions(+), 29 deletions(-) create mode 100644 Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift rename Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/{GeneralShortcutSetting.swift => GlobalShortcutSetting.swift} (68%) rename Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/{GeneralKeyHolderWrapper.swift => KeyHolderWrapper.swift} (95%) diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 12acca6f2..743cb1055 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -262,8 +262,9 @@ 62ED29A22B15F1F500901F51 /* EZWrapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 62ED29A12B15F1F500901F51 /* EZWrapView.m */; }; 960835502B6791F200C6A931 /* ShortcutValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9608354F2B6791F200C6A931 /* ShortcutValidator.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 */; }; 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 */; }; @@ -279,9 +280,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 */; }; @@ -767,8 +767,9 @@ 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 = ""; }; 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 = ""; }; 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 = ""; }; @@ -785,9 +786,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 = ""; }; @@ -2202,8 +2202,9 @@ 9627F9342B59956800B1E999 /* Shortcut */ = { isa = PBXGroup; children = ( - 9627F9352B59956800B1E999 /* GeneralShortcutSetting.swift */, - 9627F9362B59956800B1E999 /* GeneralKeyHolderWrapper.swift */, + 9627F9352B59956800B1E999 /* GlobalShortcutSetting.swift */, + 9627F9362B59956800B1E999 /* KeyHolderWrapper.swift */, + 9643D9382B6F49E0000FBEA6 /* AppShortcutSetting.swift */, ); path = Shortcut; sourceTree = ""; @@ -2743,7 +2744,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 */, @@ -2799,6 +2800,7 @@ 03882F8F29D95044005B5A52 /* CTScreen.m 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 */, @@ -2904,7 +2906,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 */, diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 257c47129..504793858 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" : { @@ -3137,6 +3154,40 @@ } } }, + "shortcut_clear_all" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Clear All" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "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" : { @@ -3211,6 +3262,108 @@ } } }, + "shortcut_copy" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Copy" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "拷贝文本" + } + } + } + }, + "shortcut_copy_first_teanslated_text" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Copy first translated text" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "自动复制第一个翻译结果" + } + } + } + }, + "shortcut_decrease_font" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Decrease Font" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "减小字体" + } + } + } + }, + "shortcut_focus" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Focus" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "聚焦" + } + } + } + }, + "shortcut_increase_font" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Increase Font" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "value" : "增大字体" + } + } + } + }, + "shortcut_play" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Play" + } + }, + "zh-Hans" : { + "stringUnit" : { + "state" : "needs_review", + "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 3b3305739..7c033135f 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -168,9 +168,13 @@ extension Defaults.Keys { /// shortcut extension Defaults.Keys { + // Global 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) + + // App + static let clearInputShortcut = Key("EZClearInputShortcutKey_keyHolder", default: nil) } diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift index 434c33c77..2c3d3b49c 100644 --- a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift @@ -13,11 +13,14 @@ 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" } // Confict Message @@ -78,7 +81,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,12 +108,22 @@ extension Shortcut { keyCombo: keyCombo, target: Shortcut.shared, action: #selector(Shortcut.showMiniFloatingWindow)) + default: () + } + + if hotKey != nil { + hotKey!.register() } - hotKey.register() } } -// shortcut binding func +extension Shortcut { + @objc func clearInput() { + print("clear") + } +} + +// global shortcut binding func extension Shortcut { @objc func selectTextTranslate() { EZWindowManager.shared().selectTextTranslate() @@ -152,6 +165,9 @@ extension Shortcut { case .showMiniWindow: guard let keyCombo = Defaults[.showMiniWindowShortcut] else { return nil } return keyCombo + case .clearInput: + guard let keyCombo = Defaults[.clearInputShortcut] else { return nil } + return keyCombo } } } @@ -169,6 +185,8 @@ struct KeyboardShortcut: ViewModifier { .screenshotOCRShortcut case .showMiniWindow: .showMiniWindowShortcut + case .clearInput: + .clearInputShortcut } _shortcut = .init(key) diff --git a/Easydict/NewApp/View/SettingView/SettingView.swift b/Easydict/NewApp/View/SettingView/SettingView.swift index bb631a6e0..81a302066 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) diff --git a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift index 52daaabe6..b07da4f05 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift @@ -13,8 +13,9 @@ struct ShortcutTab: View { var body: some View { Form { // Global shortcut - GeneralShortcutSettingView() + GobalShortcutSettingView() // In app shortcut + 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..c0bf876ee --- /dev/null +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -0,0 +1,118 @@ +// +// 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 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("shortcut_clear_input") + Spacer() + KeyHolderWrapper(shortcutType: .clearInput, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } +// HStack { +// Text("shortcut_clear_all") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .selectTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("shortcut_copy") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .selectTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("shortcut_copy_first_teanslated_text") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .showMiniWindow, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("shortcut_focus") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("shortcut_play") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("retry") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("toggle_languages") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("pin") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("hide") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("shortcut_increase_font") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("shortcut_decrease_font") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("open_in_google") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("open_in_eudic") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } +// HStack { +// Text("open_in_apple_dictionary") +// Spacer() +// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) +// } + } 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/GlobalShortcutSetting.swift similarity index 68% rename from Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralShortcutSetting.swift rename to Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift index 7387a5b32..db83a9d6b 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift @@ -1,5 +1,5 @@ // -// GeneralShortcutSetting.swift +// GlobalShortcutSetting.swift // Easydict // // Created by Sharker on 2024/1/1. @@ -10,7 +10,7 @@ import SwiftUI @available(macOS 13, *) extension ShortcutTab { - struct GeneralShortcutSettingView: View { + struct GobalShortcutSettingView: View { @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") var body: some View { @@ -28,27 +28,27 @@ extension ShortcutTab { HStack { Text("input_translate") Spacer() - GeneralKeyHolderWrapper(shortcutType: .inputTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + KeyHolderWrapper(shortcutType: .inputTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) } HStack { Text("snip_translate") Spacer() - GeneralKeyHolderWrapper(shortcutType: .snipTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + KeyHolderWrapper(shortcutType: .snipTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) } HStack { Text("select_translate") Spacer() - GeneralKeyHolderWrapper(shortcutType: .selectTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + KeyHolderWrapper(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) + KeyHolderWrapper(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) + KeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) } } header: { Text("global_shortcut_setting") diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralKeyHolderWrapper.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift similarity index 95% rename from Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GeneralKeyHolderWrapper.swift rename to Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift index e94dfda4e..53a195bf9 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,7 @@ import KeyHolder import Magnet import SwiftUI -struct GeneralKeyHolderWrapper: NSViewRepresentable { +struct KeyHolderWrapper: NSViewRepresentable { func makeCoordinator() -> Coordinator { .init(shortcutType: type, confictAlterMessage: $confictAlterMessage) } @@ -39,7 +39,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 +91,7 @@ extension GeneralKeyHolderWrapper { keyCombo = Defaults[.screenshotOCRShortcut] case .showMiniWindow: keyCombo = Defaults[.showMiniWindowShortcut] + default: () } recordView.keyCombo = keyCombo Shortcut.shared.bindingShortcut(keyCombo: keyCombo, type: type) @@ -109,6 +110,8 @@ extension GeneralKeyHolderWrapper { Defaults[.screenshotOCRShortcut] = keyCombo case .showMiniWindow: Defaults[.showMiniWindowShortcut] = keyCombo + case .clearInput: + Defaults[.clearInputShortcut] = keyCombo } } } From f1ea923da2c289eb1bb1a85e1b0c961ded68d3b4 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Sun, 4 Feb 2024 16:11:01 +0800 Subject: [PATCH 02/23] fix: restore app shortcut --- .../View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift index 53a195bf9..6dbfabd3a 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift @@ -91,7 +91,8 @@ extension KeyHolderWrapper { keyCombo = Defaults[.screenshotOCRShortcut] case .showMiniWindow: keyCombo = Defaults[.showMiniWindowShortcut] - default: () + case .clearInput: + keyCombo = Defaults[.clearInputShortcut] } recordView.keyCombo = keyCombo Shortcut.shared.bindingShortcut(keyCombo: keyCombo, type: type) From 7d1e942a007f21b3f7bfd098d2249d3b03d74c17 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Sun, 4 Feb 2024 23:36:38 +0800 Subject: [PATCH 03/23] feat: add main menu shortcut part --- Easydict.xcodeproj/project.pbxproj | 28 +++- .../Configuration+Defaults.swift | 26 +++- Easydict/NewApp/EasydictApp.swift | 6 +- .../Feature/Shortcut/Shortcut+Bind.swift | 96 ++++++++++++ ...lidator.swift => Shortcut+Validator.swift} | 2 +- .../NewApp/Feature/Shortcut/Shortcut.swift | 97 ++++++------ .../View/MenuView/MainMenuCommand.swift | 18 +++ .../MenuView/MainMenuShortcutCommand.swift | 75 ++++++++++ .../View/Shortcut/AppShortcutSetting.swift | 140 +++++++++--------- .../Tabs/View/Shortcut/KeyHolderWrapper.swift | 56 +++++++ 10 files changed, 407 insertions(+), 137 deletions(-) create mode 100644 Easydict/NewApp/Feature/Shortcut/Shortcut+Bind.swift rename Easydict/NewApp/Feature/Shortcut/{ShortcutValidator.swift => Shortcut+Validator.swift} (99%) create mode 100644 Easydict/NewApp/View/MenuView/MainMenuCommand.swift create mode 100644 Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 743cb1055..090c0f1d2 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -260,11 +260,14 @@ 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 /* 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 */; }; 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 */; }; @@ -765,11 +768,14 @@ 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 /* 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 = ""; }; 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 = ""; }; @@ -2111,6 +2117,7 @@ 27FE98062B3DD525000AD654 /* View */ = { isa = PBXGroup; children = ( + 9643D93E2B6FC405000FBEA6 /* MenuView */, 27FE980A2B3DD5D1000AD654 /* MenuItemView.swift */, 0AC11B212B4D16A500F07198 /* WindowAccessor.swift */, 0AC11B232B4E46B300F07198 /* TapHandlerView.swift */, @@ -2209,6 +2216,15 @@ path = Shortcut; sourceTree = ""; }; + 9643D93E2B6FC405000FBEA6 /* MenuView */ = { + isa = PBXGroup; + children = ( + 9643D93C2B6F829C000FBEA6 /* MainMenuCommand.swift */, + 9643D93F2B6FC426000FBEA6 /* MainMenuShortcutCommand.swift */, + ); + path = MenuView; + sourceTree = ""; + }; 967712EB2B5B93E200105E0F /* Feature */ = { isa = PBXGroup; children = ( @@ -2221,7 +2237,8 @@ isa = PBXGroup; children = ( 967712ED2B5B943400105E0F /* Shortcut.swift */, - 9608354F2B6791F200C6A931 /* ShortcutValidator.swift */, + 9643D9412B6FE4AF000FBEA6 /* Shortcut+Bind.swift */, + 9608354F2B6791F200C6A931 /* Shortcut+Validator.swift */, ); path = Shortcut; sourceTree = ""; @@ -2769,7 +2786,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 */, @@ -2853,6 +2870,7 @@ 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 */, 039CC90D292F664E0037B91E /* NSObject+EZWindowType.m in Sources */, @@ -2860,6 +2878,7 @@ 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 */, @@ -2899,6 +2918,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 */, diff --git a/Easydict/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index 7c033135f..8f9fe2087 100644 --- a/Easydict/NewApp/Configuration/Configuration+Defaults.swift +++ b/Easydict/NewApp/Configuration/Configuration+Defaults.swift @@ -169,12 +169,26 @@ extension Defaults.Keys { /// shortcut extension Defaults.Keys { // Global - 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) + 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", default: nil) + 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/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 2c3d3b49c..ec0e31841 100644 --- a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift @@ -21,6 +21,20 @@ public enum ShortcutType: String { 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" } // Confict Message @@ -117,61 +131,6 @@ extension Shortcut { } } -extension Shortcut { - @objc func clearInput() { - print("clear") - } -} - -// 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() - } -} - -// 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 - case .clearInput: - guard let keyCombo = Defaults[.clearInputShortcut] else { return nil } - return keyCombo - } - } -} - struct KeyboardShortcut: ViewModifier { init(type: ShortcutType) { let key: Defaults.Key = switch type { @@ -187,6 +146,34 @@ struct KeyboardShortcut: ViewModifier { .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..a4a11f441 --- /dev/null +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -0,0 +1,75 @@ +// +// MainMenuShortcutCommand.swift +// Easydict +// +// Created by Sharker on 2024/2/4. +// Copyright © 2024 izual. All rights reserved. +// + +import SwiftUI + +extension EasyDictMainMenu { + struct MainMenuShortcutCommand: Commands { + var body: some Commands { + // shortcut Commands + CommandMenu("shortcut") { + Button("shortcut_clear_input") { + Shortcut.shared.clearInput() + } + .keyboardShortcut(.clearInput) + Button("shortcut_clear_all") { + Shortcut.shared.clearAll() + } + .keyboardShortcut(.clearAll) + Button("shortcut_copy") { + Shortcut.shared.shortcutCopy() + } + .keyboardShortcut(.copy) + Button("shortcut_copy_first_teanslated_text") { + Shortcut.shared.shortcutCopyFirstResult() + } + .keyboardShortcut(.copyFirstResult) + Button("shortcut_focus") { + Shortcut.shared.shortcutFocus() + } + .keyboardShortcut(.focus) + Button("shortcut_play") { + Shortcut.shared.shortcutPlay() + } + .keyboardShortcut(.play) + Button("retry") { + Shortcut.shared.shortcutRetry() + } + .keyboardShortcut(.retry) + Button("pin") { + Shortcut.shared.shortcutPin() + } + .keyboardShortcut(.pin) + Button("hide") { + Shortcut.shared.shortcutHide() + } + .keyboardShortcut(.hide) + Button("shortcut_increase_font") { + Shortcut.shared.increaseFontSize() + } + .keyboardShortcut(.increaseFontSize) + Button("shortcut_decrease_font") { + Shortcut.shared.decreaseFontSize() + } + .keyboardShortcut(.decreaseFontSize) + Button("open_in_google") { + Shortcut.shared.shortcutGoogle() + } + .keyboardShortcut(.google) + Button("open_in_eudic") { + Shortcut.shared.shortcutEudic() + } + .keyboardShortcut(.eudic) + Button("open_in_apple_dictionary") { + Shortcut.shared.shortcutAppleDic() + } + .keyboardShortcut(.appleDic) + } + } + } +} diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index c0bf876ee..f386ebed6 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -29,76 +29,76 @@ extension ShortcutTab { Spacer() KeyHolderWrapper(shortcutType: .clearInput, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) } -// HStack { -// Text("shortcut_clear_all") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .selectTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("shortcut_copy") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .selectTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("shortcut_copy_first_teanslated_text") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .showMiniWindow, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("shortcut_focus") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("shortcut_play") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("retry") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("toggle_languages") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("pin") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("hide") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("shortcut_increase_font") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("shortcut_decrease_font") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("open_in_google") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("open_in_eudic") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } -// HStack { -// Text("open_in_apple_dictionary") -// Spacer() -// GlobalKeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) -// } + HStack { + Text("shortcut_clear_all") + Spacer() + KeyHolderWrapper(shortcutType: .clearAll, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("shortcut_copy") + Spacer() + KeyHolderWrapper(shortcutType: .copy, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("shortcut_copy_first_teanslated_text") + Spacer() + KeyHolderWrapper(shortcutType: .copyFirstResult, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("shortcut_focus") + Spacer() + KeyHolderWrapper(shortcutType: .focus, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("shortcut_play") + Spacer() + KeyHolderWrapper(shortcutType: .play, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("retry") + Spacer() + KeyHolderWrapper(shortcutType: .retry, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("toggle_languages") + Spacer() + KeyHolderWrapper(shortcutType: .toggle, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("pin") + Spacer() + KeyHolderWrapper(shortcutType: .pin, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("hide") + Spacer() + KeyHolderWrapper(shortcutType: .hide, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("shortcut_increase_font") + Spacer() + KeyHolderWrapper(shortcutType: .increaseFontSize, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("shortcut_decrease_font") + Spacer() + KeyHolderWrapper(shortcutType: .decreaseFontSize, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("open_in_google") + Spacer() + KeyHolderWrapper(shortcutType: .google, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("open_in_eudic") + Spacer() + KeyHolderWrapper(shortcutType: .eudic, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } + HStack { + Text("open_in_apple_dictionary") + Spacer() + KeyHolderWrapper(shortcutType: .appleDic, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + } } header: { Text("app_shortcut_setting") } diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift index 6dbfabd3a..f25418f58 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift @@ -93,6 +93,34 @@ extension KeyHolderWrapper { 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) @@ -113,6 +141,34 @@ extension KeyHolderWrapper { 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 } } } From bb9bc40174a4252e3da73862c642daab306435b3 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Mon, 5 Feb 2024 00:48:45 +0800 Subject: [PATCH 04/23] feat: add default app shortcut --- Easydict.xcodeproj/project.pbxproj | 4 +++ .../Configuration+Defaults.swift | 6 ++++ .../Feature/Shortcut/Shortcut+Default.swift | 31 +++++++++++++++++++ .../View/SettingView/Tabs/ShortcutTab.swift | 17 +++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 090c0f1d2..098e63510 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -268,6 +268,7 @@ 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 */; }; 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 */; }; @@ -776,6 +777,7 @@ 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 = ""; }; 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 = ""; }; @@ -2237,6 +2239,7 @@ isa = PBXGroup; children = ( 967712ED2B5B943400105E0F /* Shortcut.swift */, + 9643D9432B6FEF5F000FBEA6 /* Shortcut+Default.swift */, 9643D9412B6FE4AF000FBEA6 /* Shortcut+Bind.swift */, 9608354F2B6791F200C6A931 /* Shortcut+Validator.swift */, ); @@ -2944,6 +2947,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/NewApp/Configuration/Configuration+Defaults.swift b/Easydict/NewApp/Configuration/Configuration+Defaults.swift index 8f9fe2087..4d4b7a334 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` diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift new file mode 100644 index 000000000..1de845dca --- /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(QWERTYKeyCode: 40, cocoaModifiers: .command) + Defaults[.clearAllShortcut] = KeyCombo(QWERTYKeyCode: 40, cocoaModifiers: [.command, .shift]) + Defaults[.copyShortcut] = KeyCombo(QWERTYKeyCode: 8, cocoaModifiers: [.command, .shift]) + Defaults[.copyFirstResultShortcut] = KeyCombo(QWERTYKeyCode: 38, cocoaModifiers: [.command, .shift]) + Defaults[.focusShortcut] = KeyCombo(QWERTYKeyCode: 34, cocoaModifiers: .command) + Defaults[.playShortcut] = KeyCombo(QWERTYKeyCode: 1, cocoaModifiers: .command) + Defaults[.retryShortcut] = KeyCombo(QWERTYKeyCode: 15, cocoaModifiers: .command) + Defaults[.toggleShortcut] = KeyCombo(QWERTYKeyCode: 17, cocoaModifiers: .command) + Defaults[.pinShortcut] = KeyCombo(QWERTYKeyCode: 35, cocoaModifiers: .command) + Defaults[.hideShortcut] = KeyCombo(QWERTYKeyCode: 16, cocoaModifiers: .command) + Defaults[.increaseFontSize] = KeyCombo(QWERTYKeyCode: 24, cocoaModifiers: .command) + Defaults[.decreaseFontSize] = KeyCombo(QWERTYKeyCode: 27, cocoaModifiers: .command) + Defaults[.googleShortcut] = KeyCombo(QWERTYKeyCode: 36, cocoaModifiers: .command) + Defaults[.eudicShortcut] = KeyCombo(QWERTYKeyCode: 36, cocoaModifiers: [.command, .shift]) + Defaults[.appleDictionaryShortcut] = KeyCombo(QWERTYKeyCode: 2, cocoaModifiers: [.command, .shift]) + } +} diff --git a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift index b07da4f05..b0bb823ff 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift @@ -6,6 +6,7 @@ // Copyright © 2024 izual. All rights reserved. // +import Defaults import SwiftUI @available(macOS 13, *) @@ -16,7 +17,21 @@ struct ShortcutTab: View { GobalShortcutSettingView() // In app shortcut AppShortcutSettingView() - }.formStyle(.grouped) + } + .formStyle(.grouped) + .onAppear { + setDefaultAppShortcut() + } + } + + func setDefaultAppShortcut() { + if Defaults[.firstLaunch] { + Defaults[.firstLaunch] = false + // set defalut for app shortcut + Shortcut.shared.setDefaultForAppShortcut() + } else { + // do nothing + } } } From 4d37a08207107ba2f4b5b3a4eca573f642199434 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Mon, 5 Feb 2024 00:56:15 +0800 Subject: [PATCH 05/23] feat: change add default app shortcut place --- Easydict/NewApp/Feature/Shortcut/Shortcut.swift | 8 ++++++++ .../NewApp/View/SettingView/Tabs/ShortcutTab.swift | 13 ------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift index ec0e31841..26796f38f 100644 --- a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift @@ -52,6 +52,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 diff --git a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift index b0bb823ff..89a6337bb 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift @@ -19,19 +19,6 @@ struct ShortcutTab: View { AppShortcutSettingView() } .formStyle(.grouped) - .onAppear { - setDefaultAppShortcut() - } - } - - func setDefaultAppShortcut() { - if Defaults[.firstLaunch] { - Defaults[.firstLaunch] = false - // set defalut for app shortcut - Shortcut.shared.setDefaultForAppShortcut() - } else { - // do nothing - } } } From d1fa819c4692f6453fea1b629b9db93c604258de Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Mon, 5 Feb 2024 01:02:55 +0800 Subject: [PATCH 06/23] feat: add Divider --- Easydict/NewApp/Feature/Shortcut/Shortcut.swift | 2 +- Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift index 26796f38f..d881d8350 100644 --- a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift @@ -52,7 +52,7 @@ class Shortcut: NSObject { @objc static func setupShortcut() { let shortcut = Shortcut.shared shortcut.restoreShortcut() - + if Defaults[.firstLaunch] { Defaults[.firstLaunch] = false // set defalut for app shortcut diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift index a4a11f441..c185b7203 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -41,6 +41,11 @@ extension EasyDictMainMenu { Shortcut.shared.shortcutRetry() } .keyboardShortcut(.retry) + Button("toggle_languages") { + Shortcut.shared.shortcutToggle() + } + .keyboardShortcut(.toggle) + Divider() Button("pin") { Shortcut.shared.shortcutPin() } @@ -57,6 +62,7 @@ extension EasyDictMainMenu { Shortcut.shared.decreaseFontSize() } .keyboardShortcut(.decreaseFontSize) + Divider() Button("open_in_google") { Shortcut.shared.shortcutGoogle() } From 0e48f8414db307d6f0b184f846ab2e790ce059ec Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Mon, 5 Feb 2024 23:01:28 +0800 Subject: [PATCH 07/23] fix: review localized string --- Easydict/App/Localizable.xcstrings | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 504793858..6e00aa7aa 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -2393,7 +2393,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "打开窗口时自动选中查询文本" } } @@ -3165,8 +3165,8 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", - "value" : "清空" + "state" : "translated", + "value" : "清空所有" } } } @@ -3273,7 +3273,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "拷贝文本" } } @@ -3290,7 +3290,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "自动复制第一个翻译结果" } } @@ -3324,7 +3324,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "聚焦" } } @@ -3341,7 +3341,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "增大字体" } } @@ -3358,7 +3358,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "播放单词发音" } } From a973974aba101a72af099d2a29c6cb796b28f2c7 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Mon, 5 Feb 2024 23:22:47 +0800 Subject: [PATCH 08/23] fix: create keyCombo clearly --- .../Feature/Shortcut/Shortcut+Default.swift | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift index 1de845dca..d48d74d1d 100644 --- a/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift @@ -12,20 +12,20 @@ import Magnet extension Shortcut { // set defalut for app shortcut func setDefaultForAppShortcut() { - Defaults[.clearInputShortcut] = KeyCombo(QWERTYKeyCode: 40, cocoaModifiers: .command) - Defaults[.clearAllShortcut] = KeyCombo(QWERTYKeyCode: 40, cocoaModifiers: [.command, .shift]) - Defaults[.copyShortcut] = KeyCombo(QWERTYKeyCode: 8, cocoaModifiers: [.command, .shift]) - Defaults[.copyFirstResultShortcut] = KeyCombo(QWERTYKeyCode: 38, cocoaModifiers: [.command, .shift]) - Defaults[.focusShortcut] = KeyCombo(QWERTYKeyCode: 34, cocoaModifiers: .command) - Defaults[.playShortcut] = KeyCombo(QWERTYKeyCode: 1, cocoaModifiers: .command) - Defaults[.retryShortcut] = KeyCombo(QWERTYKeyCode: 15, cocoaModifiers: .command) - Defaults[.toggleShortcut] = KeyCombo(QWERTYKeyCode: 17, cocoaModifiers: .command) - Defaults[.pinShortcut] = KeyCombo(QWERTYKeyCode: 35, cocoaModifiers: .command) - Defaults[.hideShortcut] = KeyCombo(QWERTYKeyCode: 16, cocoaModifiers: .command) - Defaults[.increaseFontSize] = KeyCombo(QWERTYKeyCode: 24, cocoaModifiers: .command) - Defaults[.decreaseFontSize] = KeyCombo(QWERTYKeyCode: 27, cocoaModifiers: .command) - Defaults[.googleShortcut] = KeyCombo(QWERTYKeyCode: 36, cocoaModifiers: .command) - Defaults[.eudicShortcut] = KeyCombo(QWERTYKeyCode: 36, cocoaModifiers: [.command, .shift]) - Defaults[.appleDictionaryShortcut] = KeyCombo(QWERTYKeyCode: 2, cocoaModifiers: [.command, .shift]) + 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]) } } From 5107005bccadf00f9944abd840faabba44ea52d0 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 12:57:33 +0800 Subject: [PATCH 09/23] fix: optimize AppshortcutSetting and GlobalShortcut --- Easydict.xcodeproj/project.pbxproj | 8 ++ Easydict/App/Localizable.xcstrings | 4 +- .../NewApp/Feature/Shortcut/Shortcut.swift | 4 +- .../View/SettingView/Tabs/ShortcutTab.swift | 1 - .../View/Shortcut/AppShortcutSetting.swift | 103 ++++-------------- .../View/Shortcut/GlobalShortcutSetting.swift | 40 ++----- .../View/Shortcut/KeyHolderAlterView.swift | 42 +++++++ .../Tabs/View/Shortcut/KeyHolderRowView.swift | 24 ++++ .../Tabs/View/Shortcut/KeyHolderWrapper.swift | 6 + 9 files changed, 115 insertions(+), 117 deletions(-) create mode 100644 Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderAlterView.swift create mode 100644 Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 098e63510..2886e874d 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -269,6 +269,8 @@ 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 */; }; 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 */; }; @@ -778,6 +780,8 @@ 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 = ""; }; 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 = ""; }; @@ -2214,6 +2218,8 @@ 9627F9352B59956800B1E999 /* GlobalShortcutSetting.swift */, 9627F9362B59956800B1E999 /* KeyHolderWrapper.swift */, 9643D9382B6F49E0000FBEA6 /* AppShortcutSetting.swift */, + 9643D9452B71D103000FBEA6 /* KeyHolderRowView.swift */, + 9643D9492B71EABE000FBEA6 /* KeyHolderAlterView.swift */, ); path = Shortcut; sourceTree = ""; @@ -2841,6 +2847,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 */, @@ -2890,6 +2897,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 */, diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 6e00aa7aa..862a709ed 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -3336,12 +3336,12 @@ "en" : { "stringUnit" : { "state" : "translated", - "value" : "Increase Font" + "value" : "Increase Font Size" } }, "zh-Hans" : { "stringUnit" : { - "state" : "translated", + "state" : "needs_review", "value" : "增大字体" } } diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift index d881d8350..1dc9ab8e3 100644 --- a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift @@ -133,9 +133,7 @@ extension Shortcut { default: () } - if hotKey != nil { - hotKey!.register() - } + hotKey?.register() } } diff --git a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift index 89a6337bb..d1d123a24 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift @@ -6,7 +6,6 @@ // Copyright © 2024 izual. All rights reserved. // -import Defaults import SwiftUI @available(macOS 13, *) diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index f386ebed6..d360532c6 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -11,93 +11,34 @@ import SwiftUI @available(macOS 13, *) extension ShortcutTab { struct AppShortcutSettingView: View { + private var shortcutDataList = [ + KeyHolderDataItem(title: "shortcut_clear_input", type: .clearInput), + KeyHolderDataItem(title: "shortcut_clear_all", type: .clearAll), + KeyHolderDataItem(title: "shortcut_copy", type: .copy), + KeyHolderDataItem(title: "shortcut_copy_first_teanslated_text", type: .copyFirstResult), + KeyHolderDataItem(title: "shortcut_focus", type: .focus), + KeyHolderDataItem(title: "shortcut_play", type: .play), + KeyHolderDataItem(title: "retry", type: .retry), + KeyHolderDataItem(title: "toggle_languages", type: .toggle), + KeyHolderDataItem(title: "pin", type: .pin), + KeyHolderDataItem(title: "hide", type: .hide), + KeyHolderDataItem(title: "shortcut_increase_font", type: .increaseFontSize), + KeyHolderDataItem(title: "shortcut_decrease_font", type: .decreaseFontSize), + KeyHolderDataItem(title: "open_in_google", type: .google), + KeyHolderDataItem(title: "open_in_eudic", type: .increaseFontSize), + KeyHolderDataItem(title: "open_in_apple_dictionary", type: .increaseFontSize), + ] @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") var body: some View { let showAlter = Binding( get: { - if !confictAlterMessage.message.isEmpty { - true - } else { - false - } - }, set: { _ in - } + !confictAlterMessage.message.isEmpty + }, + set: { _ in } ) Section { - HStack { - Text("shortcut_clear_input") - Spacer() - KeyHolderWrapper(shortcutType: .clearInput, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("shortcut_clear_all") - Spacer() - KeyHolderWrapper(shortcutType: .clearAll, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("shortcut_copy") - Spacer() - KeyHolderWrapper(shortcutType: .copy, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("shortcut_copy_first_teanslated_text") - Spacer() - KeyHolderWrapper(shortcutType: .copyFirstResult, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("shortcut_focus") - Spacer() - KeyHolderWrapper(shortcutType: .focus, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("shortcut_play") - Spacer() - KeyHolderWrapper(shortcutType: .play, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("retry") - Spacer() - KeyHolderWrapper(shortcutType: .retry, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("toggle_languages") - Spacer() - KeyHolderWrapper(shortcutType: .toggle, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("pin") - Spacer() - KeyHolderWrapper(shortcutType: .pin, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("hide") - Spacer() - KeyHolderWrapper(shortcutType: .hide, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("shortcut_increase_font") - Spacer() - KeyHolderWrapper(shortcutType: .increaseFontSize, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("shortcut_decrease_font") - Spacer() - KeyHolderWrapper(shortcutType: .decreaseFontSize, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("open_in_google") - Spacer() - KeyHolderWrapper(shortcutType: .google, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("open_in_eudic") - Spacer() - KeyHolderWrapper(shortcutType: .eudic, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("open_in_apple_dictionary") - Spacer() - KeyHolderWrapper(shortcutType: .appleDic, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + ForEach(shortcutDataList) { item in + KeyHolderRowView(title: item.title, type: item.type, confictAlterMessage: $confictAlterMessage) } } header: { Text("app_shortcut_setting") diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift index db83a9d6b..b3fdf8ca8 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift @@ -12,43 +12,23 @@ import SwiftUI extension ShortcutTab { struct GobalShortcutSettingView: View { @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") - + private var shortcutDataList = [ + KeyHolderDataItem(title: "input_translate", type: .inputTranslate), + KeyHolderDataItem(title: "snip_translate", type: .snipTranslate), + KeyHolderDataItem(title: "select_translate", type: .selectTranslate), + KeyHolderDataItem(title: "show_mini_window", type: .showMiniWindow), + KeyHolderDataItem(title: "silent_screenshot_ocr", type: .silentScreenshotOcr), + ] var body: some View { let showAlter = Binding( get: { - if !confictAlterMessage.message.isEmpty { - true - } else { - false - } + !confictAlterMessage.message.isEmpty }, set: { _ in } ) Section { - HStack { - Text("input_translate") - Spacer() - KeyHolderWrapper(shortcutType: .inputTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("snip_translate") - Spacer() - KeyHolderWrapper(shortcutType: .snipTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("select_translate") - Spacer() - KeyHolderWrapper(shortcutType: .selectTranslate, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("show_mini_window") - Spacer() - KeyHolderWrapper(shortcutType: .showMiniWindow, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) - } - HStack { - Text("silent_screenshot_ocr") - Spacer() - KeyHolderWrapper(shortcutType: .silentScreenshotOcr, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + ForEach(shortcutDataList) { item in + KeyHolderRowView(title: item.title, type: item.type, confictAlterMessage: $confictAlterMessage) } } header: { Text("global_shortcut_setting") 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..98e0789a9 --- /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: 24) + } + } +} diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift index f25418f58..beec39ae5 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift @@ -12,6 +12,12 @@ import KeyHolder import Magnet import SwiftUI +public struct KeyHolderDataItem: Identifiable { + public var id: String { title } + var title: String + var type: ShortcutType +} + struct KeyHolderWrapper: NSViewRepresentable { func makeCoordinator() -> Coordinator { .init(shortcutType: type, confictAlterMessage: $confictAlterMessage) From 4a83cbf788bd350e8cd87ae7138042aca7372dba Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 13:00:07 +0800 Subject: [PATCH 10/23] fix: remove unused code --- Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift | 2 +- .../SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift index d1d123a24..558bcb5cc 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ShortcutTab.swift @@ -13,7 +13,7 @@ struct ShortcutTab: View { var body: some View { Form { // Global shortcut - GobalShortcutSettingView() + GlobalShortcutSettingView() // In app shortcut AppShortcutSettingView() } diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift index b3fdf8ca8..781ed7fc3 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift @@ -10,7 +10,7 @@ import SwiftUI @available(macOS 13, *) extension ShortcutTab { - struct GobalShortcutSettingView: View { + struct GlobalShortcutSettingView: View { @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") private var shortcutDataList = [ KeyHolderDataItem(title: "input_translate", type: .inputTranslate), From 11da684f545644d91951480c2539565dd73c0b43 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 15:14:36 +0800 Subject: [PATCH 11/23] fix: refactor command --- Easydict.xcodeproj/project.pbxproj | 4 + .../MenuView/MainMenuShortcutCommand.swift | 81 +++++-------------- .../MainMenuShortcutCommandItem.swift | 58 +++++++++++++ 3 files changed, 82 insertions(+), 61 deletions(-) create mode 100644 Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index 6c58e7c3b..4f0d47908 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -282,6 +282,7 @@ 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 */; }; @@ -804,6 +805,7 @@ 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 = ""; }; @@ -2251,6 +2253,7 @@ children = ( 9643D93C2B6F829C000FBEA6 /* MainMenuCommand.swift */, 9643D93F2B6FC426000FBEA6 /* MainMenuShortcutCommand.swift */, + 9643D94B2B71F74D000FBEA6 /* MainMenuShortcutCommandItem.swift */, ); path = MenuView; sourceTree = ""; @@ -2920,6 +2923,7 @@ 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 */, diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift index c185b7203..86af3fbd1 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -10,71 +10,30 @@ import SwiftUI extension EasyDictMainMenu { struct MainMenuShortcutCommand: Commands { + @State private var appShortcutCommandList = [ + MainMenuShortcutCommandDataItem(title: "shortcut_clear_input", type: .clearInput), + MainMenuShortcutCommandDataItem(title: "shortcut_clear_all", type: .clearAll), + MainMenuShortcutCommandDataItem(title: "shortcut_copy", type: .copy), + MainMenuShortcutCommandDataItem(title: "shortcut_copy_first_teanslated_text", type: .copyFirstResult), + MainMenuShortcutCommandDataItem(title: "shortcut_focus", type: .focus), + MainMenuShortcutCommandDataItem(title: "shortcut_play", type: .play), + MainMenuShortcutCommandDataItem(title: "retry", type: .retry), + MainMenuShortcutCommandDataItem(title: "toggle_languages", type: .toggle), + MainMenuShortcutCommandDataItem(title: "pin", type: .pin), + MainMenuShortcutCommandDataItem(title: "hide", type: .hide), + MainMenuShortcutCommandDataItem(title: "shortcut_increase_font", type: .increaseFontSize), + MainMenuShortcutCommandDataItem(title: "shortcut_decrease_font", type: .decreaseFontSize), + MainMenuShortcutCommandDataItem(title: "open_in_google", type: .google), + MainMenuShortcutCommandDataItem(title: "open_in_eudic", type: .eudic), + MainMenuShortcutCommandDataItem(title: "open_in_apple_dictionary", type: .appleDic), + ] + var body: some Commands { // shortcut Commands CommandMenu("shortcut") { - Button("shortcut_clear_input") { - Shortcut.shared.clearInput() - } - .keyboardShortcut(.clearInput) - Button("shortcut_clear_all") { - Shortcut.shared.clearAll() - } - .keyboardShortcut(.clearAll) - Button("shortcut_copy") { - Shortcut.shared.shortcutCopy() - } - .keyboardShortcut(.copy) - Button("shortcut_copy_first_teanslated_text") { - Shortcut.shared.shortcutCopyFirstResult() - } - .keyboardShortcut(.copyFirstResult) - Button("shortcut_focus") { - Shortcut.shared.shortcutFocus() - } - .keyboardShortcut(.focus) - Button("shortcut_play") { - Shortcut.shared.shortcutPlay() - } - .keyboardShortcut(.play) - Button("retry") { - Shortcut.shared.shortcutRetry() - } - .keyboardShortcut(.retry) - Button("toggle_languages") { - Shortcut.shared.shortcutToggle() - } - .keyboardShortcut(.toggle) - Divider() - Button("pin") { - Shortcut.shared.shortcutPin() - } - .keyboardShortcut(.pin) - Button("hide") { - Shortcut.shared.shortcutHide() - } - .keyboardShortcut(.hide) - Button("shortcut_increase_font") { - Shortcut.shared.increaseFontSize() - } - .keyboardShortcut(.increaseFontSize) - Button("shortcut_decrease_font") { - Shortcut.shared.decreaseFontSize() - } - .keyboardShortcut(.decreaseFontSize) - Divider() - Button("open_in_google") { - Shortcut.shared.shortcutGoogle() - } - .keyboardShortcut(.google) - Button("open_in_eudic") { - Shortcut.shared.shortcutEudic() - } - .keyboardShortcut(.eudic) - Button("open_in_apple_dictionary") { - Shortcut.shared.shortcutAppleDic() + ForEach(appShortcutCommandList) { item in + MainMenuShortcutCommandItem(dataItem: item) } - .keyboardShortcut(.appleDic) } } } diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift new file mode 100644 index 000000000..b0225ceb9 --- /dev/null +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift @@ -0,0 +1,58 @@ +// +// 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 { title } + var title: String + var type: ShortcutType +} + +struct MainMenuShortcutCommandItem: View { + @State public var dataItem: MainMenuShortcutCommandDataItem + + var body: some View { + Button(LocalizedStringKey(dataItem.title)) { + 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) + } +} From 5d56e65a82f68d6643bf66b41acb2fa6008e1c6f Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 15:34:23 +0800 Subject: [PATCH 12/23] fix: UI optimize --- Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift index 86af3fbd1..80b4e2fd4 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -33,6 +33,9 @@ extension EasyDictMainMenu { CommandMenu("shortcut") { ForEach(appShortcutCommandList) { item in MainMenuShortcutCommandItem(dataItem: item) + if item.title == "toggle_languages" || item.title == "shortcut_decrease_font" { + Divider() + } } } } From ea3d1d40769de338e34d09124cb87888b88ac36e Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 18:04:43 +0800 Subject: [PATCH 13/23] fix: remove unused code --- Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift index 80b4e2fd4..f8d7d26a9 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -10,7 +10,7 @@ import SwiftUI extension EasyDictMainMenu { struct MainMenuShortcutCommand: Commands { - @State private var appShortcutCommandList = [ + private var appShortcutCommandList = [ MainMenuShortcutCommandDataItem(title: "shortcut_clear_input", type: .clearInput), MainMenuShortcutCommandDataItem(title: "shortcut_clear_all", type: .clearAll), MainMenuShortcutCommandDataItem(title: "shortcut_copy", type: .copy), From 088fecaaae8182f0161a5ccc90f865b1c95d25e4 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 18:04:54 +0800 Subject: [PATCH 14/23] fix: remove unused code --- Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift index b0225ceb9..5fe5876e0 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift @@ -15,7 +15,7 @@ struct MainMenuShortcutCommandDataItem: Identifiable { } struct MainMenuShortcutCommandItem: View { - @State public var dataItem: MainMenuShortcutCommandDataItem + public var dataItem: MainMenuShortcutCommandDataItem var body: some View { Button(LocalizedStringKey(dataItem.title)) { From 7fce991c397060f2f19a608218e0b31492316f43 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 22:59:02 +0800 Subject: [PATCH 15/23] fix: try fix bug --- Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift | 2 +- .../SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift | 2 +- .../SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift index f8d7d26a9..80b4e2fd4 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -10,7 +10,7 @@ import SwiftUI extension EasyDictMainMenu { struct MainMenuShortcutCommand: Commands { - private var appShortcutCommandList = [ + @State private var appShortcutCommandList = [ MainMenuShortcutCommandDataItem(title: "shortcut_clear_input", type: .clearInput), MainMenuShortcutCommandDataItem(title: "shortcut_clear_all", type: .clearAll), MainMenuShortcutCommandDataItem(title: "shortcut_copy", type: .copy), diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index d360532c6..3ac1dd92a 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -11,7 +11,7 @@ import SwiftUI @available(macOS 13, *) extension ShortcutTab { struct AppShortcutSettingView: View { - private var shortcutDataList = [ + @State private var shortcutDataList = [ KeyHolderDataItem(title: "shortcut_clear_input", type: .clearInput), KeyHolderDataItem(title: "shortcut_clear_all", type: .clearAll), KeyHolderDataItem(title: "shortcut_copy", type: .copy), diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift index 781ed7fc3..f6263bc7d 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift @@ -12,7 +12,7 @@ import SwiftUI extension ShortcutTab { struct GlobalShortcutSettingView: View { @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") - private var shortcutDataList = [ + @State private var shortcutDataList = [ KeyHolderDataItem(title: "input_translate", type: .inputTranslate), KeyHolderDataItem(title: "snip_translate", type: .snipTranslate), KeyHolderDataItem(title: "select_translate", type: .selectTranslate), From c0ea7cf4a4ec91105651242b48cc8596828fc072 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Tue, 6 Feb 2024 23:27:07 +0800 Subject: [PATCH 16/23] perf: adjust settings page size --- Easydict/NewApp/View/SettingView/SettingView.swift | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Easydict/NewApp/View/SettingView/SettingView.swift b/Easydict/NewApp/View/SettingView/SettingView.swift index 665c01377..2d73db6f0 100644 --- a/Easydict/NewApp/View/SettingView/SettingView.swift +++ b/Easydict/NewApp/View/SettingView/SettingView.swift @@ -66,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) From 4ecd6915d47c2bad52ffb68efb0db1ab5c6e3dd3 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Tue, 6 Feb 2024 23:36:13 +0800 Subject: [PATCH 17/23] perf: adjust shortcut view size --- .../View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift index 98e0789a9..42cbc41d2 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderRowView.swift @@ -18,7 +18,7 @@ struct KeyHolderRowView: View { HStack { Text(LocalizedStringKey(title)) Spacer() - KeyHolderWrapper(shortcutType: type, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 24) + KeyHolderWrapper(shortcutType: type, confictAlterMessage: $confictAlterMessage).frame(width: 180, height: 26) } } } From 9a7b3a7c2c9d1dfa55c302dfc5487654dc23a95a Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 23:50:06 +0800 Subject: [PATCH 18/23] Apply suggestions from code review Co-authored-by: Tisfeng --- .../SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index 3ac1dd92a..6d7b2e2c4 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -25,7 +25,7 @@ extension ShortcutTab { KeyHolderDataItem(title: "shortcut_increase_font", type: .increaseFontSize), KeyHolderDataItem(title: "shortcut_decrease_font", type: .decreaseFontSize), KeyHolderDataItem(title: "open_in_google", type: .google), - KeyHolderDataItem(title: "open_in_eudic", type: .increaseFontSize), + KeyHolderDataItem(title: "open_in_eudic", type: .eudic), KeyHolderDataItem(title: "open_in_apple_dictionary", type: .increaseFontSize), ] @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") From afd12af1675cfb0021cfdc418c2a5c83cf2e536c Mon Sep 17 00:00:00 2001 From: Tisfeng Date: Tue, 6 Feb 2024 23:52:32 +0800 Subject: [PATCH 19/23] Update Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift --- .../SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index 6d7b2e2c4..6d0cfa868 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -26,7 +26,7 @@ extension ShortcutTab { KeyHolderDataItem(title: "shortcut_decrease_font", type: .decreaseFontSize), KeyHolderDataItem(title: "open_in_google", type: .google), KeyHolderDataItem(title: "open_in_eudic", type: .eudic), - KeyHolderDataItem(title: "open_in_apple_dictionary", type: .increaseFontSize), + KeyHolderDataItem(title: "open_in_apple_dictionary", type: .appleDic), ] @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") var body: some View { From 4003d18e1765dcc10df1d68a14225ff439ae9fdc Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Tue, 6 Feb 2024 23:52:52 +0800 Subject: [PATCH 20/23] fix: appshortcutsetting shortcut type --- .../SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index 3ac1dd92a..6d0cfa868 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -25,8 +25,8 @@ extension ShortcutTab { KeyHolderDataItem(title: "shortcut_increase_font", type: .increaseFontSize), KeyHolderDataItem(title: "shortcut_decrease_font", type: .decreaseFontSize), KeyHolderDataItem(title: "open_in_google", type: .google), - KeyHolderDataItem(title: "open_in_eudic", type: .increaseFontSize), - KeyHolderDataItem(title: "open_in_apple_dictionary", type: .increaseFontSize), + KeyHolderDataItem(title: "open_in_eudic", type: .eudic), + KeyHolderDataItem(title: "open_in_apple_dictionary", type: .appleDic), ] @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") var body: some View { From d96c0d940e3b71e1aa78c392d452b386f11bc5d1 Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Wed, 7 Feb 2024 00:28:23 +0800 Subject: [PATCH 21/23] fix: review localizable --- Easydict/App/Localizable.xcstrings | 28 ++++++++++++++----- .../MenuView/MainMenuShortcutCommand.swift | 2 +- .../View/Shortcut/AppShortcutSetting.swift | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Easydict/App/Localizable.xcstrings b/Easydict/App/Localizable.xcstrings index 21330b1fd..fe1356419 100644 --- a/Easydict/App/Localizable.xcstrings +++ b/Easydict/App/Localizable.xcstrings @@ -3649,7 +3649,14 @@ } }, "shortcut_confict_message (Shortcut.shared.confictMenuItem?.title ?? \"\")" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "" + } + } + } }, "shortcut_confict_message %@" : { "extractionState" : "manual", @@ -3669,7 +3676,14 @@ } }, "shortcut_confict_title (keyCombo!.keyEquivalentModifierMaskString + keyCombo!.characters)" : { - + "localizations" : { + "zh-Hans" : { + "stringUnit" : { + "state" : "translated", + "value" : "" + } + } + } }, "shortcut_confict_title %@" : { "extractionState" : "manual", @@ -3700,12 +3714,12 @@ "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "拷贝文本" + "value" : "复制文本" } } } }, - "shortcut_copy_first_teanslated_text" : { + "shortcut_copy_first_translated_text" : { "extractionState" : "manual", "localizations" : { "en" : { @@ -3717,7 +3731,7 @@ "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "自动复制第一个翻译结果" + "value" : "复制第一个翻译结果" } } } @@ -3728,7 +3742,7 @@ "en" : { "stringUnit" : { "state" : "translated", - "value" : "Decrease Font" + "value" : "Decrease Font Size" } }, "zh-Hans" : { @@ -3767,7 +3781,7 @@ }, "zh-Hans" : { "stringUnit" : { - "state" : "needs_review", + "state" : "translated", "value" : "增大字体" } } diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift index 80b4e2fd4..e8d4d79ca 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -14,7 +14,7 @@ extension EasyDictMainMenu { MainMenuShortcutCommandDataItem(title: "shortcut_clear_input", type: .clearInput), MainMenuShortcutCommandDataItem(title: "shortcut_clear_all", type: .clearAll), MainMenuShortcutCommandDataItem(title: "shortcut_copy", type: .copy), - MainMenuShortcutCommandDataItem(title: "shortcut_copy_first_teanslated_text", type: .copyFirstResult), + MainMenuShortcutCommandDataItem(title: "shortcut_copy_first_translated_text", type: .copyFirstResult), MainMenuShortcutCommandDataItem(title: "shortcut_focus", type: .focus), MainMenuShortcutCommandDataItem(title: "shortcut_play", type: .play), MainMenuShortcutCommandDataItem(title: "retry", type: .retry), diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index 6d0cfa868..fdaf5c31f 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -15,7 +15,7 @@ extension ShortcutTab { KeyHolderDataItem(title: "shortcut_clear_input", type: .clearInput), KeyHolderDataItem(title: "shortcut_clear_all", type: .clearAll), KeyHolderDataItem(title: "shortcut_copy", type: .copy), - KeyHolderDataItem(title: "shortcut_copy_first_teanslated_text", type: .copyFirstResult), + KeyHolderDataItem(title: "shortcut_copy_first_translated_text", type: .copyFirstResult), KeyHolderDataItem(title: "shortcut_focus", type: .focus), KeyHolderDataItem(title: "shortcut_play", type: .play), KeyHolderDataItem(title: "retry", type: .retry), From 51a7a0fdc71bab037d8fabd105352f5b8ca29e4e Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Wed, 7 Feb 2024 00:49:14 +0800 Subject: [PATCH 22/23] fix: optimize code --- .../NewApp/Feature/Shortcut/Shortcut.swift | 47 +++++++++++++++++++ .../MenuView/MainMenuShortcutCommand.swift | 33 ++++++------- .../MainMenuShortcutCommandItem.swift | 4 ++ .../View/Shortcut/AppShortcutSetting.swift | 30 ++++++------ .../View/Shortcut/GlobalShortcutSetting.swift | 10 ++-- 5 files changed, 86 insertions(+), 38 deletions(-) diff --git a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift index 1dc9ab8e3..c08c2dc2a 100644 --- a/Easydict/NewApp/Feature/Shortcut/Shortcut.swift +++ b/Easydict/NewApp/Feature/Shortcut/Shortcut.swift @@ -37,6 +37,53 @@ public enum ShortcutType: String { 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 public struct ShortcutConfictAlertMessage: Identifiable { public var id: String { message } diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift index e8d4d79ca..180cb45f0 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -11,21 +11,21 @@ import SwiftUI extension EasyDictMainMenu { struct MainMenuShortcutCommand: Commands { @State private var appShortcutCommandList = [ - MainMenuShortcutCommandDataItem(title: "shortcut_clear_input", type: .clearInput), - MainMenuShortcutCommandDataItem(title: "shortcut_clear_all", type: .clearAll), - MainMenuShortcutCommandDataItem(title: "shortcut_copy", type: .copy), - MainMenuShortcutCommandDataItem(title: "shortcut_copy_first_translated_text", type: .copyFirstResult), - MainMenuShortcutCommandDataItem(title: "shortcut_focus", type: .focus), - MainMenuShortcutCommandDataItem(title: "shortcut_play", type: .play), - MainMenuShortcutCommandDataItem(title: "retry", type: .retry), - MainMenuShortcutCommandDataItem(title: "toggle_languages", type: .toggle), - MainMenuShortcutCommandDataItem(title: "pin", type: .pin), - MainMenuShortcutCommandDataItem(title: "hide", type: .hide), - MainMenuShortcutCommandDataItem(title: "shortcut_increase_font", type: .increaseFontSize), - MainMenuShortcutCommandDataItem(title: "shortcut_decrease_font", type: .decreaseFontSize), - MainMenuShortcutCommandDataItem(title: "open_in_google", type: .google), - MainMenuShortcutCommandDataItem(title: "open_in_eudic", type: .eudic), - MainMenuShortcutCommandDataItem(title: "open_in_apple_dictionary", type: .appleDic), + MainMenuShortcutCommandDataItem(title: ShortcutType.clearInput.localizedStringKey(), type: .clearInput), + MainMenuShortcutCommandDataItem(title: ShortcutType.clearAll.localizedStringKey(), type: .clearAll), + MainMenuShortcutCommandDataItem(title: ShortcutType.copy.localizedStringKey(), type: .copy), + MainMenuShortcutCommandDataItem(title: ShortcutType.copyFirstResult.localizedStringKey(), type: .copyFirstResult), + MainMenuShortcutCommandDataItem(title: ShortcutType.focus.localizedStringKey(), type: .focus), + MainMenuShortcutCommandDataItem(title: ShortcutType.play.localizedStringKey(), type: .play), + MainMenuShortcutCommandDataItem(title: ShortcutType.retry.localizedStringKey(), type: .retry), + MainMenuShortcutCommandDataItem(title: ShortcutType.toggle.localizedStringKey(), type: .toggle), + MainMenuShortcutCommandDataItem(title: ShortcutType.pin.localizedStringKey(), type: .pin), + MainMenuShortcutCommandDataItem(title: ShortcutType.hide.localizedStringKey(), type: .hide), + MainMenuShortcutCommandDataItem(title: ShortcutType.increaseFontSize.localizedStringKey(), type: .increaseFontSize), + MainMenuShortcutCommandDataItem(title: ShortcutType.decreaseFontSize.localizedStringKey(), type: .decreaseFontSize), + MainMenuShortcutCommandDataItem(title: ShortcutType.google.localizedStringKey(), type: .google), + MainMenuShortcutCommandDataItem(title: ShortcutType.eudic.localizedStringKey(), type: .eudic), + MainMenuShortcutCommandDataItem(title: ShortcutType.appleDic.localizedStringKey(), type: .appleDic), ] var body: some Commands { @@ -33,9 +33,6 @@ extension EasyDictMainMenu { CommandMenu("shortcut") { ForEach(appShortcutCommandList) { item in MainMenuShortcutCommandItem(dataItem: item) - if item.title == "toggle_languages" || item.title == "shortcut_decrease_font" { - Divider() - } } } } diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift index 5fe5876e0..f0d0af319 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift @@ -54,5 +54,9 @@ struct MainMenuShortcutCommandItem: View { } } .keyboardShortcut(dataItem.type) + + if dataItem.type == .toggle || dataItem.type == .decreaseFontSize { + Divider() + } } } diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index fdaf5c31f..a499b54e5 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -12,21 +12,21 @@ import SwiftUI extension ShortcutTab { struct AppShortcutSettingView: View { @State private var shortcutDataList = [ - KeyHolderDataItem(title: "shortcut_clear_input", type: .clearInput), - KeyHolderDataItem(title: "shortcut_clear_all", type: .clearAll), - KeyHolderDataItem(title: "shortcut_copy", type: .copy), - KeyHolderDataItem(title: "shortcut_copy_first_translated_text", type: .copyFirstResult), - KeyHolderDataItem(title: "shortcut_focus", type: .focus), - KeyHolderDataItem(title: "shortcut_play", type: .play), - KeyHolderDataItem(title: "retry", type: .retry), - KeyHolderDataItem(title: "toggle_languages", type: .toggle), - KeyHolderDataItem(title: "pin", type: .pin), - KeyHolderDataItem(title: "hide", type: .hide), - KeyHolderDataItem(title: "shortcut_increase_font", type: .increaseFontSize), - KeyHolderDataItem(title: "shortcut_decrease_font", type: .decreaseFontSize), - KeyHolderDataItem(title: "open_in_google", type: .google), - KeyHolderDataItem(title: "open_in_eudic", type: .eudic), - KeyHolderDataItem(title: "open_in_apple_dictionary", type: .appleDic), + KeyHolderDataItem(title: ShortcutType.clearInput.localizedStringKey(), type: .clearInput), + KeyHolderDataItem(title: ShortcutType.clearAll.localizedStringKey(), type: .clearAll), + KeyHolderDataItem(title: ShortcutType.copy.localizedStringKey(), type: .copy), + KeyHolderDataItem(title: ShortcutType.copyFirstResult.localizedStringKey(), type: .copyFirstResult), + KeyHolderDataItem(title: ShortcutType.focus.localizedStringKey(), type: .focus), + KeyHolderDataItem(title: ShortcutType.play.localizedStringKey(), type: .play), + KeyHolderDataItem(title: ShortcutType.retry.localizedStringKey(), type: .retry), + KeyHolderDataItem(title: ShortcutType.toggle.localizedStringKey(), type: .toggle), + KeyHolderDataItem(title: ShortcutType.pin.localizedStringKey(), type: .pin), + KeyHolderDataItem(title: ShortcutType.hide.localizedStringKey(), type: .hide), + KeyHolderDataItem(title: ShortcutType.increaseFontSize.localizedStringKey(), type: .increaseFontSize), + KeyHolderDataItem(title: ShortcutType.decreaseFontSize.localizedStringKey(), type: .decreaseFontSize), + KeyHolderDataItem(title: ShortcutType.google.localizedStringKey(), type: .google), + KeyHolderDataItem(title: ShortcutType.eudic.localizedStringKey(), type: .eudic), + KeyHolderDataItem(title: ShortcutType.appleDic.localizedStringKey(), type: .appleDic), ] @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") var body: some View { diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift index f6263bc7d..c911e5c1a 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift @@ -13,11 +13,11 @@ extension ShortcutTab { struct GlobalShortcutSettingView: View { @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") @State private var shortcutDataList = [ - KeyHolderDataItem(title: "input_translate", type: .inputTranslate), - KeyHolderDataItem(title: "snip_translate", type: .snipTranslate), - KeyHolderDataItem(title: "select_translate", type: .selectTranslate), - KeyHolderDataItem(title: "show_mini_window", type: .showMiniWindow), - KeyHolderDataItem(title: "silent_screenshot_ocr", type: .silentScreenshotOcr), + KeyHolderDataItem(title: ShortcutType.inputTranslate.localizedStringKey(), type: .inputTranslate), + KeyHolderDataItem(title: ShortcutType.snipTranslate.localizedStringKey(), type: .snipTranslate), + KeyHolderDataItem(title: ShortcutType.selectTranslate.localizedStringKey(), type: .selectTranslate), + KeyHolderDataItem(title: ShortcutType.showMiniWindow.localizedStringKey(), type: .showMiniWindow), + KeyHolderDataItem(title: ShortcutType.silentScreenshotOcr.localizedStringKey(), type: .silentScreenshotOcr), ] var body: some View { let showAlter = Binding( From 49685cd2ce65397ba0d6ec4cd93478e60eca996c Mon Sep 17 00:00:00 2001 From: Sharker <1548742234@qq.com> Date: Wed, 7 Feb 2024 10:19:39 +0800 Subject: [PATCH 23/23] fix: optimize code --- .../MenuView/MainMenuShortcutCommand.swift | 30 ++++++++--------- .../MainMenuShortcutCommandItem.swift | 5 ++- .../View/Shortcut/AppShortcutSetting.swift | 32 +++++++++---------- .../View/Shortcut/GlobalShortcutSetting.swift | 12 +++---- .../Tabs/View/Shortcut/KeyHolderWrapper.swift | 3 +- 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift index 180cb45f0..82ff53423 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift @@ -11,21 +11,21 @@ import SwiftUI extension EasyDictMainMenu { struct MainMenuShortcutCommand: Commands { @State private var appShortcutCommandList = [ - MainMenuShortcutCommandDataItem(title: ShortcutType.clearInput.localizedStringKey(), type: .clearInput), - MainMenuShortcutCommandDataItem(title: ShortcutType.clearAll.localizedStringKey(), type: .clearAll), - MainMenuShortcutCommandDataItem(title: ShortcutType.copy.localizedStringKey(), type: .copy), - MainMenuShortcutCommandDataItem(title: ShortcutType.copyFirstResult.localizedStringKey(), type: .copyFirstResult), - MainMenuShortcutCommandDataItem(title: ShortcutType.focus.localizedStringKey(), type: .focus), - MainMenuShortcutCommandDataItem(title: ShortcutType.play.localizedStringKey(), type: .play), - MainMenuShortcutCommandDataItem(title: ShortcutType.retry.localizedStringKey(), type: .retry), - MainMenuShortcutCommandDataItem(title: ShortcutType.toggle.localizedStringKey(), type: .toggle), - MainMenuShortcutCommandDataItem(title: ShortcutType.pin.localizedStringKey(), type: .pin), - MainMenuShortcutCommandDataItem(title: ShortcutType.hide.localizedStringKey(), type: .hide), - MainMenuShortcutCommandDataItem(title: ShortcutType.increaseFontSize.localizedStringKey(), type: .increaseFontSize), - MainMenuShortcutCommandDataItem(title: ShortcutType.decreaseFontSize.localizedStringKey(), type: .decreaseFontSize), - MainMenuShortcutCommandDataItem(title: ShortcutType.google.localizedStringKey(), type: .google), - MainMenuShortcutCommandDataItem(title: ShortcutType.eudic.localizedStringKey(), type: .eudic), - MainMenuShortcutCommandDataItem(title: ShortcutType.appleDic.localizedStringKey(), type: .appleDic), + 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 { diff --git a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift index f0d0af319..669057c9f 100644 --- a/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift +++ b/Easydict/NewApp/View/MenuView/MainMenuShortcutCommandItem.swift @@ -9,8 +9,7 @@ import SwiftUI struct MainMenuShortcutCommandDataItem: Identifiable { - public var id: String { title } - var title: String + public var id: String { type.localizedStringKey() } var type: ShortcutType } @@ -18,7 +17,7 @@ struct MainMenuShortcutCommandItem: View { public var dataItem: MainMenuShortcutCommandDataItem var body: some View { - Button(LocalizedStringKey(dataItem.title)) { + Button(LocalizedStringKey(dataItem.type.localizedStringKey())) { switch dataItem.type { case .clearInput: Shortcut.shared.clearInput() diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift index a499b54e5..62773bb6e 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift @@ -12,21 +12,21 @@ import SwiftUI extension ShortcutTab { struct AppShortcutSettingView: View { @State private var shortcutDataList = [ - KeyHolderDataItem(title: ShortcutType.clearInput.localizedStringKey(), type: .clearInput), - KeyHolderDataItem(title: ShortcutType.clearAll.localizedStringKey(), type: .clearAll), - KeyHolderDataItem(title: ShortcutType.copy.localizedStringKey(), type: .copy), - KeyHolderDataItem(title: ShortcutType.copyFirstResult.localizedStringKey(), type: .copyFirstResult), - KeyHolderDataItem(title: ShortcutType.focus.localizedStringKey(), type: .focus), - KeyHolderDataItem(title: ShortcutType.play.localizedStringKey(), type: .play), - KeyHolderDataItem(title: ShortcutType.retry.localizedStringKey(), type: .retry), - KeyHolderDataItem(title: ShortcutType.toggle.localizedStringKey(), type: .toggle), - KeyHolderDataItem(title: ShortcutType.pin.localizedStringKey(), type: .pin), - KeyHolderDataItem(title: ShortcutType.hide.localizedStringKey(), type: .hide), - KeyHolderDataItem(title: ShortcutType.increaseFontSize.localizedStringKey(), type: .increaseFontSize), - KeyHolderDataItem(title: ShortcutType.decreaseFontSize.localizedStringKey(), type: .decreaseFontSize), - KeyHolderDataItem(title: ShortcutType.google.localizedStringKey(), type: .google), - KeyHolderDataItem(title: ShortcutType.eudic.localizedStringKey(), type: .eudic), - KeyHolderDataItem(title: ShortcutType.appleDic.localizedStringKey(), type: .appleDic), + 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 { @@ -38,7 +38,7 @@ extension ShortcutTab { ) Section { ForEach(shortcutDataList) { item in - KeyHolderRowView(title: item.title, type: item.type, confictAlterMessage: $confictAlterMessage) + KeyHolderRowView(title: item.type.localizedStringKey(), type: item.type, confictAlterMessage: $confictAlterMessage) } } header: { Text("app_shortcut_setting") diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift index c911e5c1a..0fdcb9083 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/GlobalShortcutSetting.swift @@ -13,11 +13,11 @@ extension ShortcutTab { struct GlobalShortcutSettingView: View { @State var confictAlterMessage: ShortcutConfictAlertMessage = .init(title: "", message: "") @State private var shortcutDataList = [ - KeyHolderDataItem(title: ShortcutType.inputTranslate.localizedStringKey(), type: .inputTranslate), - KeyHolderDataItem(title: ShortcutType.snipTranslate.localizedStringKey(), type: .snipTranslate), - KeyHolderDataItem(title: ShortcutType.selectTranslate.localizedStringKey(), type: .selectTranslate), - KeyHolderDataItem(title: ShortcutType.showMiniWindow.localizedStringKey(), type: .showMiniWindow), - KeyHolderDataItem(title: ShortcutType.silentScreenshotOcr.localizedStringKey(), type: .silentScreenshotOcr), + KeyHolderDataItem(type: .inputTranslate), + KeyHolderDataItem(type: .snipTranslate), + KeyHolderDataItem(type: .selectTranslate), + KeyHolderDataItem(type: .showMiniWindow), + KeyHolderDataItem(type: .silentScreenshotOcr), ] var body: some View { let showAlter = Binding( @@ -28,7 +28,7 @@ extension ShortcutTab { ) Section { ForEach(shortcutDataList) { item in - KeyHolderRowView(title: item.title, type: item.type, confictAlterMessage: $confictAlterMessage) + KeyHolderRowView(title: item.type.localizedStringKey(), type: item.type, confictAlterMessage: $confictAlterMessage) } } header: { Text("global_shortcut_setting") diff --git a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift index beec39ae5..80ef418be 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/KeyHolderWrapper.swift @@ -13,8 +13,7 @@ import Magnet import SwiftUI public struct KeyHolderDataItem: Identifiable { - public var id: String { title } - var title: String + public var id: String { type.localizedStringKey() } var type: ShortcutType }