Skip to content

Commit

Permalink
In app shortcut (#389)
Browse files Browse the repository at this point in the history
* feat: split global shortcut

* fix: restore app shortcut

* feat: add main menu shortcut part

* feat: add default app shortcut

* feat: change  add default app shortcut place

* feat: add Divider

* fix: review localized string

* fix: create keyCombo clearly

* fix: optimize AppshortcutSetting and GlobalShortcut

* fix: remove unused code

* fix: refactor command

* fix: UI optimize

* fix: remove unused code

* fix: remove unused code

* fix: try fix bug

* perf: adjust settings page size

* perf: adjust shortcut view size

* Apply suggestions from code review

Co-authored-by: Tisfeng <[email protected]>

* Update Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcutSetting.swift

* fix: appshortcutsetting shortcut type

* fix: review localizable

* fix: optimize code

* fix: optimize code

---------

Co-authored-by: Tisfeng <[email protected]>
  • Loading branch information
AkaShark and tisfeng authored Feb 7, 2024
1 parent cfe29c7 commit 82e6961
Show file tree
Hide file tree
Showing 19 changed files with 866 additions and 158 deletions.
70 changes: 54 additions & 16 deletions Easydict.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

173 changes: 170 additions & 3 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -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" : {
Expand Down Expand Up @@ -2376,7 +2393,7 @@
},
"zh-Hans" : {
"stringUnit" : {
"state" : "needs_review",
"state" : "translated",
"value" : "打开窗口时自动选中查询文本"
}
}
Expand Down Expand Up @@ -3563,6 +3580,40 @@
}
}
},
"shortcut_clear_all" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Clear All"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "清空所有"
}
}
}
},
"shortcut_clear_input" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Clear Input"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "清空查询内容"
}
}
}
},
"shortcut_confict %@" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -3598,7 +3649,14 @@
}
},
"shortcut_confict_message (Shortcut.shared.confictMenuItem?.title ?? \"\")" : {

"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : ""
}
}
}
},
"shortcut_confict_message %@" : {
"extractionState" : "manual",
Expand All @@ -3618,7 +3676,14 @@
}
},
"shortcut_confict_title (keyCombo!.keyEquivalentModifierMaskString + keyCombo!.characters)" : {

"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : ""
}
}
}
},
"shortcut_confict_title %@" : {
"extractionState" : "manual",
Expand All @@ -3637,6 +3702,108 @@
}
}
},
"shortcut_copy" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Copy"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "复制文本"
}
}
}
},
"shortcut_copy_first_translated_text" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Copy first translated text"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "复制第一个翻译结果"
}
}
}
},
"shortcut_decrease_font" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Decrease Font Size"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "减小字体"
}
}
}
},
"shortcut_focus" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Focus"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "聚焦"
}
}
}
},
"shortcut_increase_font" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Increase Font Size"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "增大字体"
}
}
}
},
"shortcut_play" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Play"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "播放单词发音"
}
}
}
},
"shortcut_select_translate_window_type" : {
"localizations" : {
"en" : {
Expand Down
34 changes: 29 additions & 5 deletions Easydict/NewApp/Configuration/Configuration+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import Defaults
import Foundation
import Magnet

/// Utils
extension Defaults.Keys {
/// is first launch
static let firstLaunch = Key<Bool>("EZConfiguration_kFirstLaunch", default: true)
}

// Setting
extension Defaults.Keys {
// rename `from`
Expand Down Expand Up @@ -171,9 +177,27 @@ extension Defaults.Keys {

/// shortcut
extension Defaults.Keys {
static let selectionShortcut = Key<KeyCombo?>("EZSelectionShortcutKey_keyHolder", default: nil)
static let snipShortcut = Key<KeyCombo?>("EZSnipShortcutKey_keyHolder", default: nil)
static let inputShortcut = Key<KeyCombo?>("EZInputShortcutKey_keyHolder", default: nil)
static let screenshotOCRShortcut = Key<KeyCombo?>("EZScreenshotOCRShortcutKey_keyHolder", default: nil)
static let showMiniWindowShortcut = Key<KeyCombo?>("EZShowMiniShortcutKey_keyHolder", default: nil)
// Global
static let selectionShortcut = Key<KeyCombo?>("EZSelectionShortcutKey_keyHolder")
static let snipShortcut = Key<KeyCombo?>("EZSnipShortcutKey_keyHolder")
static let inputShortcut = Key<KeyCombo?>("EZInputShortcutKey_keyHolder")
static let screenshotOCRShortcut = Key<KeyCombo?>("EZScreenshotOCRShortcutKey_keyHolder")
static let showMiniWindowShortcut = Key<KeyCombo?>("EZShowMiniShortcutKey_keyHolder")

// App
static let clearInputShortcut = Key<KeyCombo?>("EZClearInputShortcutKey_keyHolder")
static let clearAllShortcut = Key<KeyCombo?>("EZClearAllShortcutKey_keyHolder")
static let copyShortcut = Key<KeyCombo?>("EZCopyShortcutKey_keyHolder")
static let copyFirstResultShortcut = Key<KeyCombo?>("EZCopyFirstResultShortcutKey_keyHolder")
static let focusShortcut = Key<KeyCombo?>("EZFocusShortcutKey_keyHolder")
static let playShortcut = Key<KeyCombo?>("EZPlayShortcutKey_keyHolder")
static let retryShortcut = Key<KeyCombo?>("EZRetryShortcutKey_keyHolder")
static let toggleShortcut = Key<KeyCombo?>("EZToggleShortcutKey_keyHolder")
static let pinShortcut = Key<KeyCombo?>("EZPinShortcutKey_keyHolder")
static let hideShortcut = Key<KeyCombo?>("EZHideShortcutKey_keyHolder")
static let increaseFontSize = Key<KeyCombo?>("EZIncreaseFontSizeShortcutKey_keyHolder")
static let decreaseFontSize = Key<KeyCombo?>("EZDecreaseFontSizeShortcutKey_keyHolder")
static let googleShortcut = Key<KeyCombo?>("EZGoogleShortcutKey_keyHolder")
static let eudicShortcut = Key<KeyCombo?>("EZEudicShortcutKey_keyHolder")
static let appleDictionaryShortcut = Key<KeyCombo?>("EZAppleDictionaryShortcutKey_keyHolder")
}
6 changes: 5 additions & 1 deletion Easydict/NewApp/EasydictApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ struct EasydictApp: App {
.scaledToFit()
}
.help("Easydict 🍃")
}.menuBarExtraStyle(.menu)
}
.menuBarExtraStyle(.menu)
.commands {
EasyDictMainMenu() // main menu
}
Settings {
SettingView()
}
Expand Down
96 changes: 96 additions & 0 deletions Easydict/NewApp/Feature/Shortcut/Shortcut+Bind.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
Loading

0 comments on commit 82e6961

Please sign in to comment.