Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In app shortcut #389

Merged
merged 28 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
78b445d
feat: split global shortcut
AkaShark Feb 4, 2024
f1ea923
fix: restore app shortcut
AkaShark Feb 4, 2024
7d1e942
feat: add main menu shortcut part
AkaShark Feb 4, 2024
bb9bc40
feat: add default app shortcut
AkaShark Feb 4, 2024
4d37a08
feat: change add default app shortcut place
AkaShark Feb 4, 2024
d1fa819
feat: add Divider
AkaShark Feb 4, 2024
0e48f84
fix: review localized string
AkaShark Feb 5, 2024
a973974
fix: create keyCombo clearly
AkaShark Feb 5, 2024
b2499d3
Merge branch 'dev' into in_app_shortcut
tisfeng Feb 6, 2024
5107005
fix: optimize AppshortcutSetting and GlobalShortcut
AkaShark Feb 6, 2024
abc5f2b
Merge branch 'in_app_shortcut' of github.com:AkaShark/Easydict into i…
AkaShark Feb 6, 2024
4a83cbf
fix: remove unused code
AkaShark Feb 6, 2024
11da684
fix: refactor command
AkaShark Feb 6, 2024
5d56e65
fix: UI optimize
AkaShark Feb 6, 2024
ea3d1d4
fix: remove unused code
AkaShark Feb 6, 2024
088feca
fix: remove unused code
AkaShark Feb 6, 2024
25bcc75
Merge branch 'dev' into in_app_shortcut
tisfeng Feb 6, 2024
7fce991
fix: try fix bug
AkaShark Feb 6, 2024
9f61ca1
Merge branch 'in_app_shortcut' of github.com:AkaShark/Easydict into i…
AkaShark Feb 6, 2024
c0ea7cf
perf: adjust settings page size
tisfeng Feb 6, 2024
4ecd691
perf: adjust shortcut view size
tisfeng Feb 6, 2024
9a7b3a7
Apply suggestions from code review
AkaShark Feb 6, 2024
afd12af
Update Easydict/NewApp/View/SettingView/Tabs/View/Shortcut/AppShortcu…
tisfeng Feb 6, 2024
4003d18
fix: appshortcutsetting shortcut type
AkaShark Feb 6, 2024
64c51a2
Merge branch 'in_app_shortcut' of github.com:AkaShark/Easydict into i…
AkaShark Feb 6, 2024
d96c0d9
fix: review localizable
AkaShark Feb 6, 2024
51a7a0f
fix: optimize code
AkaShark Feb 6, 2024
49685cd
fix: optimize code
AkaShark Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 54 additions & 16 deletions Easydict.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

155 changes: 154 additions & 1 deletion 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 @@ -3637,6 +3688,108 @@
}
}
},
"shortcut_copy" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Copy"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "拷贝文本"
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
},
"shortcut_copy_first_teanslated_text" : {
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Copy first translated text"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "自动复制第一个翻译结果"
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
},
"shortcut_decrease_font" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Decrease Font"
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
}
},
"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" : "needs_review",
phlpsong marked this conversation as resolved.
Show resolved Hide resolved
"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()
}
}
31 changes: 31 additions & 0 deletions Easydict/NewApp/Feature/Shortcut/Shortcut+Default.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Shortcut+Default.swift
// Easydict
//
// Created by Sharker on 2024/2/5.
// Copyright © 2024 izual. All rights reserved.
//

import Defaults
import Magnet

extension Shortcut {
// set defalut for app shortcut
func setDefaultForAppShortcut() {
Defaults[.clearInputShortcut] = KeyCombo(key: .k, cocoaModifiers: .command)
Defaults[.clearAllShortcut] = KeyCombo(key: .k, cocoaModifiers: [.command, .shift])
Defaults[.copyShortcut] = KeyCombo(key: .c, cocoaModifiers: [.command, .shift])
Defaults[.copyFirstResultShortcut] = KeyCombo(key: .j, cocoaModifiers: [.command, .shift])
Defaults[.focusShortcut] = KeyCombo(key: .i, cocoaModifiers: .command)
Defaults[.playShortcut] = KeyCombo(key: .s, cocoaModifiers: .command)
Defaults[.retryShortcut] = KeyCombo(key: .r, cocoaModifiers: .command)
Defaults[.toggleShortcut] = KeyCombo(key: .t, cocoaModifiers: .command)
Defaults[.pinShortcut] = KeyCombo(key: .p, cocoaModifiers: .command)
Defaults[.hideShortcut] = KeyCombo(key: .y, cocoaModifiers: .command)
Defaults[.increaseFontSize] = KeyCombo(key: .keypadPlus, cocoaModifiers: .command)
Defaults[.decreaseFontSize] = KeyCombo(key: .keypadMinus, cocoaModifiers: .command)
Defaults[.googleShortcut] = KeyCombo(key: .return, cocoaModifiers: .command)
Defaults[.eudicShortcut] = KeyCombo(key: .return, cocoaModifiers: [.command, .shift])
Defaults[.appleDictionaryShortcut] = KeyCombo(key: .d, cocoaModifiers: [.command, .shift])
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ShortcutValidator.swift
// Shortcut+Validator.swift
// Easydict
//
// Created by Sharker on 2024/1/29.
Expand Down
Loading