Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
| 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google Inc. nor the names of its |
| 15 | * contributors may be used to endorse or promote products derived from |
| 16 | * this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | /** |
| 32 | * @unrestricted |
| 33 | */ |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 34 | export default class ShortcutsScreen { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 35 | constructor() { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 36 | /** @type {!Object.<string, !ShortcutsSection>} */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 37 | this._sections = {}; |
| 38 | } |
| 39 | |
| 40 | static registerShortcuts() { |
| 41 | // Elements panel |
| 42 | const elementsSection = UI.shortcutsScreen.section(Common.UIString('Elements Panel')); |
| 43 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 44 | const navigate = ElementsPanelShortcuts.NavigateUp.concat(ElementsPanelShortcuts.NavigateDown); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 45 | elementsSection.addRelatedKeys(navigate, Common.UIString('Navigate elements')); |
| 46 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 47 | const expandCollapse = ElementsPanelShortcuts.Expand.concat(ElementsPanelShortcuts.Collapse); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 48 | elementsSection.addRelatedKeys(expandCollapse, Common.UIString('Expand/collapse')); |
| 49 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 50 | elementsSection.addAlternateKeys(ElementsPanelShortcuts.EditAttribute, Common.UIString('Edit attribute')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 51 | elementsSection.addAlternateKeys( |
Joel Einbinder | a66e5bf | 2018-05-31 01:26:37 | [diff] [blame] | 52 | UI.shortcutRegistry.shortcutDescriptorsForAction('elements.hide-element'), Common.UIString('Hide element')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 53 | elementsSection.addAlternateKeys( |
Joel Einbinder | a66e5bf | 2018-05-31 01:26:37 | [diff] [blame] | 54 | UI.shortcutRegistry.shortcutDescriptorsForAction('elements.edit-as-html'), |
| 55 | Common.UIString('Toggle edit as HTML')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 56 | |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 57 | // Styles pane |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 58 | const stylesPaneSection = UI.shortcutsScreen.section(Common.UIString('Styles Pane')); |
| 59 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 60 | const nextPreviousProperty = ElementsPanelShortcuts.NextProperty.concat(ElementsPanelShortcuts.PreviousProperty); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 61 | stylesPaneSection.addRelatedKeys(nextPreviousProperty, Common.UIString('Next/previous property')); |
| 62 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 63 | stylesPaneSection.addRelatedKeys(ElementsPanelShortcuts.IncrementValue, Common.UIString('Increment value')); |
| 64 | stylesPaneSection.addRelatedKeys(ElementsPanelShortcuts.DecrementValue, Common.UIString('Decrement value')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 65 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 66 | stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.IncrementBy10, Common.UIString('Increment by %f', 10)); |
| 67 | stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.DecrementBy10, Common.UIString('Decrement by %f', 10)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 68 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 69 | stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.IncrementBy100, Common.UIString('Increment by %f', 100)); |
| 70 | stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.DecrementBy100, Common.UIString('Decrement by %f', 100)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 71 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 72 | stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.IncrementBy01, Common.UIString('Increment by %f', 0.1)); |
| 73 | stylesPaneSection.addAlternateKeys(ElementsPanelShortcuts.DecrementBy01, Common.UIString('Decrement by %f', 0.1)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 74 | |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 75 | // Console |
| 76 | const consoleSection = UI.shortcutsScreen.section(Common.UIString('Console')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 77 | |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 78 | consoleSection.addAlternateKeys( |
| 79 | UI.shortcutRegistry.shortcutDescriptorsForAction('console.clear'), Common.UIString('Clear console')); |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 80 | consoleSection.addRelatedKeys(ConsolePanelShortcuts.AcceptSuggestion, Common.UIString('Accept suggestion')); |
| 81 | consoleSection.addAlternateKeys(ConsolePanelShortcuts.ClearConsolePrompt, Common.UIString('Clear console prompt')); |
| 82 | consoleSection.addRelatedKeys(ConsolePanelShortcuts.NextPreviousLine, Common.UIString('Next/previous line')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 83 | |
| 84 | if (Host.isMac()) { |
| 85 | consoleSection.addRelatedKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 86 | ConsolePanelShortcuts.NextPreviousCommand, Common.UIString('Next/previous command')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 87 | } |
| 88 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 89 | consoleSection.addKey(ConsolePanelShortcuts.ExecuteCommand, Common.UIString('Execute command')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 90 | |
| 91 | // Debugger |
| 92 | const debuggerSection = UI.shortcutsScreen.section(Common.UIString('Debugger')); |
| 93 | |
| 94 | debuggerSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 95 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-pause'), Common.UIString('Pause/ Continue')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 96 | debuggerSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 97 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-over'), Common.UIString('Step over')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 98 | debuggerSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-into'), Common.UIString('Step into')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 100 | debuggerSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 101 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.step-out'), Common.UIString('Step out')); |
| 102 | |
| 103 | const nextAndPrevFrameKeys = |
| 104 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.next-call-frame') |
| 105 | .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.previous-call-frame')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 106 | debuggerSection.addRelatedKeys(nextAndPrevFrameKeys, Common.UIString('Next/previous call frame')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 107 | |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 108 | debuggerSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 109 | SourcesPanelShortcuts.EvaluateSelectionInConsole, Common.UIString('Evaluate selection in console')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 110 | debuggerSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 111 | SourcesPanelShortcuts.AddSelectionToWatch, Common.UIString('Add selection to watch')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 112 | debuggerSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 113 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoint'), |
| 114 | Common.UIString('Toggle breakpoint')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 115 | debuggerSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 116 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoint-enabled'), |
| 117 | Common.UIString('Toggle breakpoint enabled')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 118 | debuggerSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 119 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.toggle-breakpoints-active'), |
| 120 | Common.UIString('Toggle all breakpoints')); |
Olivia Flynn | 8e746e0 | 2019-06-19 17:06:23 | [diff] [blame] | 121 | debuggerSection.addAlternateKeys( |
| 122 | UI.shortcutRegistry.shortcutDescriptorsForAction('debugger.breakpoint-input-window'), |
| 123 | ls`Open breakpoint editor`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 124 | |
| 125 | // Editing |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 126 | const editingSection = UI.shortcutsScreen.section(Common.UIString('Text Editor')); |
| 127 | |
| 128 | editingSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 129 | UI.shortcutRegistry.shortcutDescriptorsForAction('sources.go-to-member'), Common.UIString('Go to member')); |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 130 | editingSection.addAlternateKeys(SourcesPanelShortcuts.ToggleAutocompletion, Common.UIString('Autocompletion')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 131 | editingSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 132 | UI.shortcutRegistry.shortcutDescriptorsForAction('sources.go-to-line'), Common.UIString('Go to line')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 133 | editingSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 134 | UI.shortcutRegistry.shortcutDescriptorsForAction('sources.jump-to-previous-location'), |
| 135 | Common.UIString('Jump to previous editing location')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 136 | editingSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 137 | UI.shortcutRegistry.shortcutDescriptorsForAction('sources.jump-to-next-location'), |
| 138 | Common.UIString('Jump to next editing location')); |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 139 | editingSection.addAlternateKeys(SourcesPanelShortcuts.ToggleComment, Common.UIString('Toggle comment')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 140 | editingSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 141 | SourcesPanelShortcuts.IncreaseCSSUnitByOne, Common.UIString('Increment CSS unit by 1')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 142 | editingSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 143 | SourcesPanelShortcuts.DecreaseCSSUnitByOne, Common.UIString('Decrement CSS unit by 1')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 144 | editingSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 145 | SourcesPanelShortcuts.IncreaseCSSUnitByTen, Common.UIString('Increment CSS unit by 10')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 146 | editingSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 147 | SourcesPanelShortcuts.DecreaseCSSUnitByTen, Common.UIString('Decrement CSS unit by 10')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 148 | editingSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 149 | SourcesPanelShortcuts.SelectNextOccurrence, Common.UIString('Select next occurrence')); |
| 150 | editingSection.addAlternateKeys(SourcesPanelShortcuts.SoftUndo, Common.UIString('Soft undo')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 151 | editingSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 152 | SourcesPanelShortcuts.GotoMatchingBracket, Common.UIString('Go to matching bracket')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 153 | editingSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 154 | UI.shortcutRegistry.shortcutDescriptorsForAction('sources.close-editor-tab'), |
| 155 | Common.UIString('Close editor tab')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 156 | editingSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 157 | UI.shortcutRegistry.shortcutDescriptorsForAction('sources.switch-file'), |
| 158 | Common.UIString('Switch between files with the same name and different extensions.')); |
| 159 | |
| 160 | // Performance panel |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 161 | const performanceSection = UI.shortcutsScreen.section(Common.UIString('Performance Panel')); |
| 162 | |
| 163 | performanceSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 164 | UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.toggle-recording'), |
| 165 | Common.UIString('Start/stop recording')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 166 | performanceSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 167 | UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.record-reload'), |
| 168 | Common.UIString('Record page reload')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 169 | performanceSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 170 | UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.save-to-file'), Common.UIString('Save profile')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 171 | performanceSection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 172 | UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.load-from-file'), Common.UIString('Load profile')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 173 | performanceSection.addRelatedKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 174 | UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.jump-to-previous-frame') |
| 175 | .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.jump-to-next-frame')), |
| 176 | Common.UIString('Jump to previous/next frame')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 177 | performanceSection.addRelatedKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 178 | UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.show-history'), |
| 179 | Common.UIString('Pick a recording from history')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 180 | performanceSection.addRelatedKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 181 | UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.previous-recording') |
| 182 | .concat(UI.shortcutRegistry.shortcutDescriptorsForAction('timeline.next-recording')), |
| 183 | Common.UIString('Show previous/next recording')); |
| 184 | |
| 185 | // Memory panel |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 186 | const memorySection = UI.shortcutsScreen.section(Common.UIString('Memory Panel')); |
| 187 | |
| 188 | memorySection.addAlternateKeys( |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 189 | UI.shortcutRegistry.shortcutDescriptorsForAction('profiler.heap-toggle-recording'), |
| 190 | Common.UIString('Start/stop recording')); |
| 191 | |
| 192 | // Layers panel |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 193 | const layersSection = UI.shortcutsScreen.section(Common.UIString('Layers Panel')); |
| 194 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 195 | layersSection.addAlternateKeys(LayersPanelShortcuts.ResetView, Common.UIString('Reset view')); |
| 196 | layersSection.addAlternateKeys(LayersPanelShortcuts.PanMode, Common.UIString('Switch to pan mode')); |
| 197 | layersSection.addAlternateKeys(LayersPanelShortcuts.RotateMode, Common.UIString('Switch to rotate mode')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 198 | layersSection.addAlternateKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 199 | LayersPanelShortcuts.TogglePanRotate, Common.UIString('Temporarily toggle pan/rotate mode while held')); |
| 200 | layersSection.addAlternateKeys(LayersPanelShortcuts.ZoomIn, Common.UIString('Zoom in')); |
| 201 | layersSection.addAlternateKeys(LayersPanelShortcuts.ZoomOut, Common.UIString('Zoom out')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 202 | layersSection.addRelatedKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 203 | LayersPanelShortcuts.Up.concat(LayersPanelShortcuts.Down), Common.UIString('Pan or rotate up/down')); |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 204 | layersSection.addRelatedKeys( |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 205 | LayersPanelShortcuts.Left.concat(LayersPanelShortcuts.Right), Common.UIString('Pan or rotate left/right')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /** |
| 209 | * @param {string} name |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 210 | * @return {!ShortcutsSection} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 211 | */ |
| 212 | section(name) { |
| 213 | let section = this._sections[name]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 214 | if (!section) { |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 215 | this._sections[name] = section = new ShortcutsSection(name); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 216 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 217 | return section; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * @return {!UI.Widget} |
| 222 | */ |
| 223 | createShortcutsTabView() { |
| 224 | const orderedSections = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 225 | for (const section in this._sections) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 226 | orderedSections.push(this._sections[section]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 227 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 228 | function compareSections(a, b) { |
| 229 | return a.order - b.order; |
| 230 | } |
| 231 | orderedSections.sort(compareSections); |
| 232 | |
| 233 | const widget = new UI.Widget(); |
| 234 | |
| 235 | widget.element.className = 'settings-tab-container'; // Override |
Chandani Shrestha | 83bd7c9 | 2019-06-11 21:21:59 | [diff] [blame] | 236 | widget.element.createChild('header').createChild('h1').createTextChild(ls`Shortcuts`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 237 | const scrollPane = widget.element.createChild('div', 'settings-container-wrapper'); |
| 238 | const container = scrollPane.createChild('div'); |
| 239 | container.className = 'settings-content settings-container'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 240 | for (let i = 0; i < orderedSections.length; ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 241 | orderedSections[i].renderSection(container); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 242 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 243 | |
| 244 | const note = scrollPane.createChild('p', 'settings-footnote'); |
| 245 | note.appendChild(UI.createDocumentationLink( |
| 246 | 'iterate/inspect-styles/shortcuts', Common.UIString('Full list of DevTools keyboard shortcuts and gestures'))); |
| 247 | |
| 248 | return widget; |
| 249 | } |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 250 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 251 | |
| 252 | /** |
| 253 | * We cannot initialize it here as localized strings are not loaded yet. |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 254 | * @type {!ShortcutsScreen} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 255 | */ |
| 256 | UI.shortcutsScreen; |
| 257 | |
| 258 | /** |
| 259 | * @unrestricted |
| 260 | */ |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 261 | export class ShortcutsSection { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 262 | /** |
| 263 | * @param {string} name |
| 264 | */ |
| 265 | constructor(name) { |
| 266 | this.name = name; |
| 267 | this._lines = /** @type {!Array.<!{key: !Node, text: string}>} */ ([]); |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 268 | this.order = ++ShortcutsSection._sequenceNumber; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @param {!UI.KeyboardShortcut.Descriptor} key |
| 273 | * @param {string} description |
| 274 | */ |
| 275 | addKey(key, description) { |
| 276 | this._addLine(this._renderKey(key), description); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} keys |
| 281 | * @param {string} description |
| 282 | */ |
| 283 | addRelatedKeys(keys, description) { |
| 284 | this._addLine(this._renderSequence(keys, '/'), description); |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} keys |
| 289 | * @param {string} description |
| 290 | */ |
| 291 | addAlternateKeys(keys, description) { |
| 292 | this._addLine(this._renderSequence(keys, Common.UIString('or')), description); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * @param {!Node} keyElement |
| 297 | * @param {string} description |
| 298 | */ |
| 299 | _addLine(keyElement, description) { |
| 300 | this._lines.push({key: keyElement, text: description}); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * @param {!Element} container |
| 305 | */ |
| 306 | renderSection(container) { |
| 307 | const parent = container.createChild('div', 'settings-block'); |
| 308 | |
| 309 | const headLine = parent.createChild('div', 'settings-line'); |
| 310 | headLine.createChild('div', 'settings-key-cell'); |
| 311 | headLine.createChild('div', 'settings-section-title settings-cell').textContent = this.name; |
Amanda Baker | 11630de | 2019-07-12 02:54:33 | [diff] [blame] | 312 | UI.ARIAUtils.markAsHeading(headLine, /* level */ 2); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 313 | |
| 314 | for (let i = 0; i < this._lines.length; ++i) { |
| 315 | const line = parent.createChild('div', 'settings-line'); |
| 316 | const keyCell = line.createChild('div', 'settings-key-cell'); |
| 317 | keyCell.appendChild(this._lines[i].key); |
| 318 | keyCell.appendChild(this._createSpan('settings-key-delimiter', ':')); |
| 319 | line.createChild('div', 'settings-cell').textContent = this._lines[i].text; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | /** |
| 324 | * @param {!Array.<!UI.KeyboardShortcut.Descriptor>} sequence |
| 325 | * @param {string} delimiter |
| 326 | * @return {!Node} |
| 327 | */ |
| 328 | _renderSequence(sequence, delimiter) { |
| 329 | const delimiterSpan = this._createSpan('settings-key-delimiter', delimiter); |
| 330 | return this._joinNodes(sequence.map(this._renderKey.bind(this)), delimiterSpan); |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * @param {!UI.KeyboardShortcut.Descriptor} key |
| 335 | * @return {!Node} |
| 336 | */ |
| 337 | _renderKey(key) { |
| 338 | const keyName = key.name; |
| 339 | const plus = this._createSpan('settings-combine-keys', '+'); |
| 340 | return this._joinNodes(keyName.split(' + ').map(this._createSpan.bind(this, 'settings-key')), plus); |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * @param {string} className |
| 345 | * @param {string} textContent |
| 346 | * @return {!Element} |
| 347 | */ |
| 348 | _createSpan(className, textContent) { |
| 349 | const node = createElement('span'); |
| 350 | node.className = className; |
| 351 | node.textContent = textContent; |
| 352 | return node; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * @param {!Array.<!Element>} nodes |
| 357 | * @param {!Element} delimiter |
| 358 | * @return {!Node} |
| 359 | */ |
| 360 | _joinNodes(nodes, delimiter) { |
| 361 | const result = createDocumentFragment(); |
| 362 | for (let i = 0; i < nodes.length; ++i) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 363 | if (i > 0) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 364 | result.appendChild(delimiter.cloneNode(true)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 365 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 366 | result.appendChild(nodes[i]); |
| 367 | } |
| 368 | return result; |
| 369 | } |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 370 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 371 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 372 | ShortcutsSection._sequenceNumber = 0; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 373 | |
| 374 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 375 | export const ElementsPanelShortcuts = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 376 | NavigateUp: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Up)], |
| 377 | |
| 378 | NavigateDown: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Down)], |
| 379 | |
| 380 | Expand: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Right)], |
| 381 | |
| 382 | Collapse: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Left)], |
| 383 | |
| 384 | EditAttribute: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Enter)], |
| 385 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 386 | NextProperty: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Tab)], |
| 387 | |
| 388 | PreviousProperty: |
| 389 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Tab, UI.KeyboardShortcut.Modifiers.Shift)], |
| 390 | |
| 391 | IncrementValue: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Up)], |
| 392 | |
| 393 | DecrementValue: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Down)], |
| 394 | |
| 395 | IncrementBy10: [ |
| 396 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.PageUp), |
| 397 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Up, UI.KeyboardShortcut.Modifiers.Shift) |
| 398 | ], |
| 399 | |
| 400 | DecrementBy10: [ |
| 401 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.PageDown), |
| 402 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Down, UI.KeyboardShortcut.Modifiers.Shift) |
| 403 | ], |
| 404 | |
| 405 | IncrementBy100: |
| 406 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.PageUp, UI.KeyboardShortcut.Modifiers.Shift)], |
| 407 | |
| 408 | DecrementBy100: |
| 409 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.PageDown, UI.KeyboardShortcut.Modifiers.Shift)], |
| 410 | |
| 411 | IncrementBy01: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Up, UI.KeyboardShortcut.Modifiers.Alt)], |
| 412 | |
| 413 | DecrementBy01: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Down, UI.KeyboardShortcut.Modifiers.Alt)] |
| 414 | }; |
| 415 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 416 | export const ConsolePanelShortcuts = { |
Fabio Rocha | f0d9547 | 2019-05-28 21:35:19 | [diff] [blame] | 417 | AcceptSuggestion: [ |
| 418 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Tab), |
| 419 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Right) |
| 420 | ], |
| 421 | |
| 422 | ClearConsolePrompt: [UI.KeyboardShortcut.makeDescriptor('u', UI.KeyboardShortcut.Modifiers.Ctrl)], |
| 423 | |
| 424 | ExecuteCommand: UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Enter), |
| 425 | |
| 426 | NextPreviousLine: [ |
| 427 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Down), |
| 428 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Up) |
| 429 | ], |
| 430 | |
| 431 | NextPreviousCommand: [ |
| 432 | UI.KeyboardShortcut.makeDescriptor('N', UI.KeyboardShortcut.Modifiers.Alt), |
| 433 | UI.KeyboardShortcut.makeDescriptor('P', UI.KeyboardShortcut.Modifiers.Alt) |
| 434 | ], |
| 435 | }; |
| 436 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 437 | export const SourcesPanelShortcuts = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 438 | SelectNextOccurrence: [UI.KeyboardShortcut.makeDescriptor('d', UI.KeyboardShortcut.Modifiers.CtrlOrMeta)], |
| 439 | |
| 440 | SoftUndo: [UI.KeyboardShortcut.makeDescriptor('u', UI.KeyboardShortcut.Modifiers.CtrlOrMeta)], |
| 441 | |
| 442 | GotoMatchingBracket: [UI.KeyboardShortcut.makeDescriptor('m', UI.KeyboardShortcut.Modifiers.Ctrl)], |
| 443 | |
| 444 | ToggleAutocompletion: |
| 445 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Space, UI.KeyboardShortcut.Modifiers.Ctrl)], |
| 446 | |
| 447 | IncreaseCSSUnitByOne: |
| 448 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Up, UI.KeyboardShortcut.Modifiers.Alt)], |
| 449 | |
| 450 | DecreaseCSSUnitByOne: |
| 451 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Down, UI.KeyboardShortcut.Modifiers.Alt)], |
| 452 | |
| 453 | IncreaseCSSUnitByTen: |
| 454 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.PageUp, UI.KeyboardShortcut.Modifiers.Alt)], |
| 455 | |
| 456 | DecreaseCSSUnitByTen: |
| 457 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.PageDown, UI.KeyboardShortcut.Modifiers.Alt)], |
| 458 | EvaluateSelectionInConsole: [UI.KeyboardShortcut.makeDescriptor( |
| 459 | 'e', UI.KeyboardShortcut.Modifiers.Shift | UI.KeyboardShortcut.Modifiers.Ctrl)], |
| 460 | |
| 461 | AddSelectionToWatch: [UI.KeyboardShortcut.makeDescriptor( |
| 462 | 'a', UI.KeyboardShortcut.Modifiers.Shift | UI.KeyboardShortcut.Modifiers.Ctrl)], |
| 463 | |
| 464 | ToggleComment: |
| 465 | [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Slash, UI.KeyboardShortcut.Modifiers.CtrlOrMeta)], |
| 466 | }; |
| 467 | |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 468 | export const LayersPanelShortcuts = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 469 | ResetView: [UI.KeyboardShortcut.makeDescriptor('0')], |
| 470 | |
| 471 | PanMode: [UI.KeyboardShortcut.makeDescriptor('x')], |
| 472 | |
| 473 | RotateMode: [UI.KeyboardShortcut.makeDescriptor('v')], |
| 474 | |
| 475 | TogglePanRotate: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Shift)], |
| 476 | |
| 477 | ZoomIn: [ |
| 478 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Plus, UI.KeyboardShortcut.Modifiers.Shift), |
| 479 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.NumpadPlus) |
| 480 | ], |
| 481 | |
| 482 | ZoomOut: [ |
| 483 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Minus, UI.KeyboardShortcut.Modifiers.Shift), |
| 484 | UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.NumpadMinus) |
| 485 | ], |
| 486 | |
| 487 | Up: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Up), UI.KeyboardShortcut.makeDescriptor('w')], |
| 488 | |
| 489 | Down: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Down), UI.KeyboardShortcut.makeDescriptor('s')], |
| 490 | |
| 491 | Left: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Left), UI.KeyboardShortcut.makeDescriptor('a')], |
| 492 | |
| 493 | Right: [UI.KeyboardShortcut.makeDescriptor(UI.KeyboardShortcut.Keys.Right), UI.KeyboardShortcut.makeDescriptor('d')] |
| 494 | }; |
Tim van der Lippe | 0830b3d | 2019-10-03 13:20:07 | [diff] [blame^] | 495 | |
| 496 | /* Legacy exported object*/ |
| 497 | self.UI = self.UI || {}; |
| 498 | |
| 499 | /* Legacy exported object*/ |
| 500 | UI = UI || {}; |
| 501 | |
| 502 | /** @constructor */ |
| 503 | UI.ShortcutsScreen = ShortcutsScreen; |
| 504 | |
| 505 | /** @constructor */ |
| 506 | UI.ShortcutsSection = ShortcutsSection; |
| 507 | |
| 508 | UI.ShortcutsScreen.ElementsPanelShortcuts = ElementsPanelShortcuts; |
| 509 | UI.ShortcutsScreen.ConsolePanelShortcuts = ConsolePanelShortcuts; |
| 510 | UI.ShortcutsScreen.SourcesPanelShortcuts = SourcesPanelShortcuts; |
| 511 | UI.ShortcutsScreen.LayersPanelShortcuts = LayersPanelShortcuts; |