hotkeys.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import { Injectable } from '@angular/core'
  2. import { ProfilesService } from './services/profiles.service'
  3. import { HotkeyDescription, HotkeyProvider } from './api/hotkeyProvider'
  4. import { PartialProfile, Profile } from './api'
  5. /** @hidden */
  6. @Injectable()
  7. export class AppHotkeyProvider extends HotkeyProvider {
  8. hotkeys: HotkeyDescription[] = [
  9. {
  10. id: 'profile-selector',
  11. name: 'Show profile selector',
  12. },
  13. {
  14. id: 'toggle-fullscreen',
  15. name: 'Toggle fullscreen mode',
  16. },
  17. {
  18. id: 'rename-tab',
  19. name: 'Rename Tab',
  20. },
  21. {
  22. id: 'close-tab',
  23. name: 'Close tab',
  24. },
  25. {
  26. id: 'reopen-tab',
  27. name: 'Reopen last tab',
  28. },
  29. {
  30. id: 'toggle-last-tab',
  31. name: 'Toggle last tab',
  32. },
  33. {
  34. id: 'next-tab',
  35. name: 'Next tab',
  36. },
  37. {
  38. id: 'previous-tab',
  39. name: 'Previous tab',
  40. },
  41. {
  42. id: 'move-tab-left',
  43. name: 'Move tab to the left',
  44. },
  45. {
  46. id: 'move-tab-right',
  47. name: 'Move tab to the right',
  48. },
  49. {
  50. id: 'rearrange-panes',
  51. name: 'Show pane labels (for rearranging)',
  52. },
  53. {
  54. id: 'duplicate-tab',
  55. name: 'Duplicate tab',
  56. },
  57. {
  58. id: 'tab-1',
  59. name: 'Tab 1',
  60. },
  61. {
  62. id: 'tab-2',
  63. name: 'Tab 2',
  64. },
  65. {
  66. id: 'tab-3',
  67. name: 'Tab 3',
  68. },
  69. {
  70. id: 'tab-4',
  71. name: 'Tab 4',
  72. },
  73. {
  74. id: 'tab-5',
  75. name: 'Tab 5',
  76. },
  77. {
  78. id: 'tab-6',
  79. name: 'Tab 6',
  80. },
  81. {
  82. id: 'tab-7',
  83. name: 'Tab 7',
  84. },
  85. {
  86. id: 'tab-8',
  87. name: 'Tab 8',
  88. },
  89. {
  90. id: 'tab-9',
  91. name: 'Tab 9',
  92. },
  93. {
  94. id: 'tab-10',
  95. name: 'Tab 10',
  96. },
  97. {
  98. id: 'tab-11',
  99. name: 'Tab 11',
  100. },
  101. {
  102. id: 'tab-12',
  103. name: 'Tab 12',
  104. },
  105. {
  106. id: 'tab-13',
  107. name: 'Tab 13',
  108. },
  109. {
  110. id: 'tab-14',
  111. name: 'Tab 14',
  112. },
  113. {
  114. id: 'tab-15',
  115. name: 'Tab 15',
  116. },
  117. {
  118. id: 'tab-16',
  119. name: 'Tab 16',
  120. },
  121. {
  122. id: 'tab-17',
  123. name: 'Tab 17',
  124. },
  125. {
  126. id: 'tab-18',
  127. name: 'Tab 18',
  128. },
  129. {
  130. id: 'tab-19',
  131. name: 'Tab 19',
  132. },
  133. {
  134. id: 'tab-20',
  135. name: 'Tab 20',
  136. },
  137. {
  138. id: 'split-right',
  139. name: 'Split to the right',
  140. },
  141. {
  142. id: 'split-bottom',
  143. name: 'Split to the bottom',
  144. },
  145. {
  146. id: 'split-left',
  147. name: 'Split to the left',
  148. },
  149. {
  150. id: 'split-top',
  151. name: 'Split to the top',
  152. },
  153. {
  154. id: 'pane-maximize',
  155. name: 'Maximize the active pane',
  156. },
  157. {
  158. id: 'pane-nav-up',
  159. name: 'Focus the pane above',
  160. },
  161. {
  162. id: 'pane-nav-down',
  163. name: 'Focus the pane below',
  164. },
  165. {
  166. id: 'pane-nav-left',
  167. name: 'Focus the pane on the left',
  168. },
  169. {
  170. id: 'pane-nav-right',
  171. name: 'Focus the pane on the right',
  172. },
  173. {
  174. id: 'pane-nav-previous',
  175. name: 'Focus previous pane',
  176. },
  177. {
  178. id: 'pane-nav-next',
  179. name: 'Focus next pane',
  180. },
  181. {
  182. id: 'switch-profile',
  183. name: 'Switch profile in the active pane',
  184. },
  185. {
  186. id: 'close-pane',
  187. name: 'Close focused pane',
  188. },
  189. ]
  190. constructor (
  191. private profilesService: ProfilesService,
  192. ) { super() }
  193. async provide (): Promise<HotkeyDescription[]> {
  194. const profiles = await this.profilesService.getProfiles()
  195. return [
  196. ...this.hotkeys,
  197. ...profiles.map(profile => ({
  198. id: `profile.${AppHotkeyProvider.getProfileHotkeyName(profile)}`,
  199. name: `New tab: ${profile.name}`,
  200. })),
  201. ...this.profilesService.getProviders().map(provider => ({
  202. id: `profile-selectors.${provider.id}`,
  203. name: `Show ${provider.name} profile selector`,
  204. })),
  205. ]
  206. }
  207. static getProfileHotkeyName (profile: PartialProfile<Profile>): string {
  208. return (profile.id ?? profile.name).replace(/\./g, '-')
  209. }
  210. }