Skip to content

Commit

Permalink
fix: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
AkaShark committed Feb 7, 2024
1 parent 51a7a0f commit 49685cd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 42 deletions.
30 changes: 15 additions & 15 deletions Easydict/NewApp/View/MenuView/MainMenuShortcutCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import SwiftUI

struct MainMenuShortcutCommandDataItem: Identifiable {
public var id: String { title }
var title: String
public var id: String { type.localizedStringKey() }
var type: ShortcutType
}

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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bool>(
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 49685cd

Please sign in to comment.