From 7a75be0d000d55adf28733a02f0324965923a6f0 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Fri, 7 Feb 2020 18:51:36 +0100 Subject: [PATCH] Refactor slightly --- VimR/VimR/DefaultShortcuts.swift | 201 +++++-------------------------- VimR/VimR/ShortcutsPref.swift | 2 +- 2 files changed, 34 insertions(+), 169 deletions(-) diff --git a/VimR/VimR/DefaultShortcuts.swift b/VimR/VimR/DefaultShortcuts.swift index 4338d459..f6085218 100644 --- a/VimR/VimR/DefaultShortcuts.swift +++ b/VimR/VimR/DefaultShortcuts.swift @@ -35,176 +35,41 @@ let defaultShortcuts: [String: Shortcut?] = [ "com.qvacua.vimr.menuitems.view.font.bigger": Shortcut(keyEquivalent: "⌘+"), "com.qvacua.vimr.menuitems.view.font.reset-to-default-size": Shortcut(keyEquivalent: "⌘0"), "com.qvacua.vimr.menuitems.view.font.smaller": Shortcut(keyEquivalent: "⌘-"), - "com.qvacua.vimr.menuitems.window.bring-all-to-front": Shortcut(keyEquivalent: ""), + "com.qvacua.vimr.menuitems.window.bring-all-to-front": Shortcut(keyEquivalent: ""), "com.qvacua.vimr.menuitems.window.minimize": Shortcut(keyEquivalent: "⌘M"), "com.qvacua.vimr.menuitems.window.zoom": Shortcut(keyEquivalent: ""), ] -let legacyDefaultShortcuts: [String: [String: Any]] = [ - "com.qvacua.vimr.menuitems.edit.copy": [ - SRShortcutCharacters: "c", - SRShortcutCharactersIgnoringModifiers: "c", - SRShortcutKeyCode: 8, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.edit.cut": [ - SRShortcutCharacters: "x", - SRShortcutCharactersIgnoringModifiers: "x", - SRShortcutKeyCode: 7, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.edit.delete": [String: Any](), - "com.qvacua.vimr.menuitems.edit.paste": [ - SRShortcutCharacters: "v", - SRShortcutCharactersIgnoringModifiers: "v", - SRShortcutKeyCode: 9, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.edit.redo": [ - SRShortcutCharacters: "z", - SRShortcutCharactersIgnoringModifiers: "Z", - SRShortcutKeyCode: 6, - SRShortcutModifierFlagsKey: 1179914, - ], - "com.qvacua.vimr.menuitems.edit.select-all": [ - SRShortcutCharacters: "a", - SRShortcutCharactersIgnoringModifiers: "a", - SRShortcutKeyCode: 0, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.edit.undo": [ - SRShortcutCharacters: "z", - SRShortcutCharactersIgnoringModifiers: "z", - SRShortcutKeyCode: 6, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.file.close": [ - SRShortcutCharacters: "w", - SRShortcutCharactersIgnoringModifiers: "w", - SRShortcutKeyCode: 13, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.file.close-window": [ - SRShortcutCharacters: "w", - SRShortcutCharactersIgnoringModifiers: "W", - SRShortcutKeyCode: 13, - SRShortcutModifierFlagsKey: 1179914, - ], - "com.qvacua.vimr.menuitems.file.new": [ - SRShortcutCharacters: "n", - SRShortcutCharactersIgnoringModifiers: "n", - SRShortcutKeyCode: 45, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.file.new-tab": [ - SRShortcutCharacters: "t", - SRShortcutCharactersIgnoringModifiers: "t", - SRShortcutKeyCode: 17, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.file.open-in-new-window": [ - SRShortcutCharacters: "ø", - SRShortcutCharactersIgnoringModifiers: "o", - SRShortcutKeyCode: 31, - SRShortcutModifierFlagsKey: 1573160, - ], - "com.qvacua.vimr.menuitems.file.open-quickly": [ - SRShortcutCharacters: "o", - SRShortcutCharactersIgnoringModifiers: "O", - SRShortcutKeyCode: 31, - SRShortcutModifierFlagsKey: 1179914, - ], - "com.qvacua.vimr.menuitems.file.open": [ - SRShortcutCharacters: "o", - SRShortcutCharactersIgnoringModifiers: "o", - SRShortcutKeyCode: 31, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.file.save-as": [ - SRShortcutCharacters: "s", - SRShortcutCharactersIgnoringModifiers: "S", - SRShortcutKeyCode: 1, - SRShortcutModifierFlagsKey: 1179914, - ], - "com.qvacua.vimr.menuitems.file.save": [ - SRShortcutCharacters: "s", - SRShortcutCharactersIgnoringModifiers: "s", - SRShortcutKeyCode: 1, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.help.vimr-help": [String: Any](), - "com.qvacua.vimr.menuitems.tools.focus-neovim-view": [ - SRShortcutCharacters: ".", - SRShortcutCharactersIgnoringModifiers: ".", - SRShortcutKeyCode: 47, - SRShortcutModifierFlagsKey: 1048576, - ], - "com.qvacua.vimr.menuitems.tools.toggle-all-tools": [ - SRShortcutCharacters: "\\", - SRShortcutCharactersIgnoringModifiers: "\\", - SRShortcutKeyCode: 42, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.tools.toggle-file-browser": [ - SRShortcutCharacters: "1", - SRShortcutCharactersIgnoringModifiers: "1", - SRShortcutKeyCode: 18, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.tools.toggle-buffer-list": [ - SRShortcutCharacters: "1", - SRShortcutCharactersIgnoringModifiers: "2", - SRShortcutKeyCode: 19, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.tools.toggle-markdown-preview": [ - SRShortcutCharacters: "1", - SRShortcutCharactersIgnoringModifiers: "3", - SRShortcutKeyCode: 20, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.tools.toggle-html-preview": [ - SRShortcutCharacters: "1", - SRShortcutCharactersIgnoringModifiers: "4", - SRShortcutKeyCode: 21, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.tools.toggle-tool-buttons": [ - SRShortcutCharacters: "\\", - SRShortcutCharactersIgnoringModifiers: "|", - SRShortcutKeyCode: 42, - SRShortcutModifierFlagsKey: 1179914, - ], - "com.qvacua.vimr.menuitems.view.enter-full-screen": [ - SRShortcutCharacters: "\006", - SRShortcutCharactersIgnoringModifiers: "f", - SRShortcutKeyCode: 3, - SRShortcutModifierFlagsKey: 1319176, - ], - "com.qvacua.vimr.menuitems.view.font.bigger": [ - SRShortcutCharacters: "=", - SRShortcutCharactersIgnoringModifiers: "=", - SRShortcutKeyCode: 24, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.view.font.reset-to-default-size": [ - SRShortcutCharacters: "0", - SRShortcutCharactersIgnoringModifiers: "0", - SRShortcutKeyCode: 29, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.view.font.smaller": [ - SRShortcutCharacters: "-", - SRShortcutCharactersIgnoringModifiers: "-", - SRShortcutKeyCode: 27, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.window.bring-all-to-front": [String: Any](), - "com.qvacua.vimr.menuitems.window.minimize": [ - SRShortcutCharacters: "m", - SRShortcutCharactersIgnoringModifiers: "m", - SRShortcutKeyCode: 46, - SRShortcutModifierFlagsKey: 1048840, - ], - "com.qvacua.vimr.menuitems.window.zoom": [String: Any](), +let legacyDefaultShortcuts: [String] = [ + "com.qvacua.vimr.menuitems.edit.copy", + "com.qvacua.vimr.menuitems.edit.cut", + "com.qvacua.vimr.menuitems.edit.delete", + "com.qvacua.vimr.menuitems.edit.paste", + "com.qvacua.vimr.menuitems.edit.redo", + "com.qvacua.vimr.menuitems.edit.select-all", + "com.qvacua.vimr.menuitems.edit.undo", + "com.qvacua.vimr.menuitems.file.close", + "com.qvacua.vimr.menuitems.file.close-window", + "com.qvacua.vimr.menuitems.file.new", + "com.qvacua.vimr.menuitems.file.new-tab", + "com.qvacua.vimr.menuitems.file.open-in-new-window", + "com.qvacua.vimr.menuitems.file.open-quickly", + "com.qvacua.vimr.menuitems.file.open", + "com.qvacua.vimr.menuitems.file.save-as", + "com.qvacua.vimr.menuitems.file.save", + "com.qvacua.vimr.menuitems.help.vimr-help", + "com.qvacua.vimr.menuitems.tools.focus-neovim-view", + "com.qvacua.vimr.menuitems.tools.toggle-all-tools", + "com.qvacua.vimr.menuitems.tools.toggle-file-browser", + "com.qvacua.vimr.menuitems.tools.toggle-buffer-list", + "com.qvacua.vimr.menuitems.tools.toggle-markdown-preview", + "com.qvacua.vimr.menuitems.tools.toggle-html-preview", + "com.qvacua.vimr.menuitems.tools.toggle-tool-buttons", + "com.qvacua.vimr.menuitems.view.enter-full-screen", + "com.qvacua.vimr.menuitems.view.font.bigger", + "com.qvacua.vimr.menuitems.view.font.reset-to-default-size", + "com.qvacua.vimr.menuitems.view.font.smaller", + "com.qvacua.vimr.menuitems.window.bring-all-to-front", + "com.qvacua.vimr.menuitems.window.minimize", + "com.qvacua.vimr.menuitems.window.zoom", ] diff --git a/VimR/VimR/ShortcutsPref.swift b/VimR/VimR/ShortcutsPref.swift index 78ca97d1..e4ca0fa2 100644 --- a/VimR/VimR/ShortcutsPref.swift +++ b/VimR/VimR/ShortcutsPref.swift @@ -76,7 +76,7 @@ class ShortcutsPref: PrefPane, return } - legacyDefaultShortcuts.keys.forEach { id in + legacyDefaultShortcuts.forEach { id in let shortcut: Shortcut? if let dict = self.shortcutsUserDefaults?.value(forKey: id) as? [String: Any] { shortcut = Shortcut(dictionary: dict)