Skip to content

Commit

Permalink
Merge pull request #187 from mtgto/keybindingset-delete
Browse files Browse the repository at this point in the history
キーバインドの設定画面から削除を選択したときに削除する処理を実装
  • Loading branch information
mtgto authored Jul 20, 2024
2 parents 15225e0 + 590d30e commit c24aeea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions macSKK/Settings/KeyBinding/KeyBindingSetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ struct KeyBindingSetView: View {
if case .duplicate(let keyBindingSet) = mode {
settingsViewModel.keyBindingSets.append(keyBindingSet.copy(id: id))
settingsViewModel.selectedKeyBindingSet = settingsViewModel.keyBindingSets.last!
logger.log("キーバインドのセット \(keyBindingSet.id, privacy: .public) から \(id, privacy: .public) を複製しました")
} else if case .rename(let keyBindingSet) = mode {
if let index = settingsViewModel.keyBindingSets.firstIndex(of: keyBindingSet) {
settingsViewModel.keyBindingSets[index] = keyBindingSet.copy(id: id)
settingsViewModel.selectedKeyBindingSet = settingsViewModel.keyBindingSets[index]
logger.log("キーバインドのセット \(keyBindingSet.id, privacy: .public) の名前を \(id, privacy: .public) に変更しました")
}
}
mode = nil
Expand Down
8 changes: 8 additions & 0 deletions macSKK/Settings/KeyBinding/KeyBindingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ struct KeyBindingView: View {
isShowingConfirmDeleteAlert = false
}
Button("Delete", role: .destructive) {
let index = settingsViewModel.keyBindingSets.firstIndex { keyBindingSet in
keyBindingSet.id == settingsViewModel.selectedKeyBindingSet.id
}
if let index {
logger.log("キーバインドのセット \(settingsViewModel.selectedKeyBindingSet.id, privacy: .public) を削除しました")
settingsViewModel.selectedKeyBindingSet = settingsViewModel.keyBindingSets[index - 1]
settingsViewModel.keyBindingSets.remove(at: index)
}
isShowingConfirmDeleteAlert = false
}
} message: {
Expand Down
5 changes: 4 additions & 1 deletion macSKK/Settings/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ final class SettingsViewModel: ObservableObject {

$selectedKeyBindingSet.sink { selectedKeyBindingSet in
if Global.keyBinding.id != selectedKeyBindingSet.id {
logger.log("キーバインドのセットが \(selectedKeyBindingSet.id, privacy: .public) に変更されました。")
logger.log("キーバインドのセットを \(Global.keyBinding.id, privacy: .public) から \(selectedKeyBindingSet.id, privacy: .public) に変更しました")
UserDefaults.standard.set(selectedKeyBindingSet.id, forKey: UserDefaultsKeys.selectedKeyBindingSetId)
Global.keyBinding = selectedKeyBindingSet
}
Expand Down Expand Up @@ -525,6 +525,9 @@ final class SettingsViewModel: ObservableObject {
if let index = keyBindingSets.firstIndex(of: selectedKeyBindingSet) {
keyBindingSets[index] = selectedKeyBindingSet.update(for: action, inputs: inputs)
selectedKeyBindingSet = keyBindingSets[index]
logger.log("キーバインドのセット \"\(self.selectedKeyBindingSet.id, privacy: .public)\"\"\(action.localizedAction, privacy: .public)\" のキーバインドが更新されました")
} else {
logger.error("キーバインドのセット \"\(self.selectedKeyBindingSet.id, privacy: .public)\" が見つかりません")
}
}

Expand Down

0 comments on commit c24aeea

Please sign in to comment.