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

キーバインド設定で右クリックから設定をリセットできるようにする #217

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion macSKK/Settings/KeyBinding/KeyBindingInputsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class KeyBindingInput: ObservableObject, Identifiable, Hashable {
// あるキーバインドを変更するビュー。
struct KeyBindingInputsView: View {
@StateObject var settingsViewModel: SettingsViewModel
@Environment (\.dismiss) var dismiss
@Environment(\.dismiss) var dismiss
@Binding var action: KeyBinding.Action
@Binding var inputs: [KeyBindingInput]
@State var selectedInput: KeyBindingInput?
Expand Down
5 changes: 5 additions & 0 deletions macSKK/Settings/KeyBinding/KeyBindingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ struct KeyBindingView: View {
}
}
.disabled(!settingsViewModel.selectedKeyBindingSet.canEdit)
Button("Reset") {
if let action = keyBindingActions.first {
settingsViewModel.resetKeyBindingInputs(action: action)
}
}
} primaryAction: { keyBindingActions in
if settingsViewModel.selectedKeyBindingSet.canEdit {
if let action = keyBindingActions.first, let keyBinding = settingsViewModel.selectedKeyBindingSet.values.first(where: { $0.action == action }) {
Expand Down
13 changes: 13 additions & 0 deletions macSKK/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,19 @@ final class SettingsViewModel: ObservableObject {
}
}

// 選択中のKeyBindingSetのactionへの割り当てをデフォルトのものにリセットする
func resetKeyBindingInputs(action: KeyBinding.Action) {
if let index = keyBindingSets.firstIndex(of: selectedKeyBindingSet) {
if let defaultKeyBinding = KeyBindingSet.defaultKeyBindingSet.values.first(where: { $0.action == action }) {
logger.log("キーバインドのセット \"\(self.selectedKeyBindingSet.id, privacy: .public)\" の \"\(action.localizedAction, privacy: .public)\" のキーバインドをリセットしました")
keyBindingSets[index] = selectedKeyBindingSet.update(for: action, inputs: defaultKeyBinding.inputs)
selectedKeyBindingSet = keyBindingSets[index]
} else {
logger.error("キーバインドのセット \"\(self.selectedKeyBindingSet.id, privacy: .public)\" が見つかりません")
}
}
}

/// 利用可能なキー配列を読み込む
func loadInputSources() {
if let inputSources = InputSource.fetch() {
Expand Down
1 change: 1 addition & 0 deletions macSKK/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"Are you sure you want to delete %@?" = "Are you sure you want to delete %@?";
"Modifier Flags (Required)" = "Modifier Flags (Required)";
"Modifier Flags (Optional)" = "Modifier Flags (Optional)";
"Reset" = "Reset";

"KeyBindingActionHiragana" = "Hiragana Mode";
"KeyBindingActionTogglekana" = "Toggle Kana";
Expand Down
1 change: 1 addition & 0 deletions macSKK/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"Are you sure you want to delete %@?" = "%@を本当に削除しますか?";
"Modifier Flags (Required)" = "修飾キー (必須)";
"Modifier Flags (Optional)" = "修飾キー (任意)";
"Reset" = "リセット";

"KeyBindingActionHiragana" = "ひらがなモード";
"KeyBindingActionTogglekana" = "かなカナ切り替え";
Expand Down
Loading