@theia/core 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/lib/browser/color-registry.d.ts +3 -69
  2. package/lib/browser/color-registry.d.ts.map +1 -1
  3. package/lib/browser/color-registry.js +13 -27
  4. package/lib/browser/color-registry.js.map +1 -1
  5. package/lib/browser/common-frontend-contribution.d.ts +3 -3
  6. package/lib/browser/common-frontend-contribution.d.ts.map +1 -1
  7. package/lib/browser/common-frontend-contribution.js +64 -64
  8. package/lib/browser/common-frontend-contribution.js.map +1 -1
  9. package/lib/browser/core-preferences.d.ts.map +1 -1
  10. package/lib/browser/core-preferences.js +23 -20
  11. package/lib/browser/core-preferences.js.map +1 -1
  12. package/lib/browser/dialogs.d.ts.map +1 -1
  13. package/lib/browser/dialogs.js +4 -4
  14. package/lib/browser/dialogs.js.map +1 -1
  15. package/lib/browser/keyboard/browser-keyboard-frontend-contribution.js +2 -2
  16. package/lib/browser/keyboard/browser-keyboard-frontend-contribution.js.map +1 -1
  17. package/lib/browser/keyboard/browser-keyboard-layout-provider.d.ts +1 -1
  18. package/lib/browser/keyboard/browser-keyboard-layout-provider.d.ts.map +1 -1
  19. package/lib/browser/keyboard/browser-keyboard-layout-provider.spec.js +6 -4
  20. package/lib/browser/keyboard/browser-keyboard-layout-provider.spec.js.map +1 -1
  21. package/lib/browser/keyboard/keys.d.ts +2 -251
  22. package/lib/browser/keyboard/keys.d.ts.map +1 -1
  23. package/lib/browser/keyboard/keys.js +12 -614
  24. package/lib/browser/keyboard/keys.js.map +1 -1
  25. package/lib/browser/messaging/ws-connection-provider.d.ts +3 -3
  26. package/lib/browser/messaging/ws-connection-provider.d.ts.map +1 -1
  27. package/lib/browser/messaging/ws-connection-provider.js +14 -4
  28. package/lib/browser/messaging/ws-connection-provider.js.map +1 -1
  29. package/lib/browser/quick-input/quick-command-frontend-contribution.js +1 -1
  30. package/lib/browser/quick-input/quick-command-frontend-contribution.js.map +1 -1
  31. package/lib/browser/quick-input/quick-command-service.d.ts.map +1 -1
  32. package/lib/browser/quick-input/quick-command-service.js +2 -2
  33. package/lib/browser/quick-input/quick-command-service.js.map +1 -1
  34. package/lib/browser/quick-input/quick-input-service.d.ts +1 -201
  35. package/lib/browser/quick-input/quick-input-service.d.ts.map +1 -1
  36. package/lib/browser/quick-input/quick-input-service.js +11 -93
  37. package/lib/browser/quick-input/quick-input-service.js.map +1 -1
  38. package/lib/browser/shell/tab-bar-toolbar.js +1 -1
  39. package/lib/browser/shell/tab-bar-toolbar.js.map +1 -1
  40. package/lib/browser/storage-service.spec.js +1 -1
  41. package/lib/browser/storage-service.spec.js.map +1 -1
  42. package/lib/browser/theming.d.ts +5 -14
  43. package/lib/browser/theming.d.ts.map +1 -1
  44. package/lib/browser/theming.js +14 -0
  45. package/lib/browser/theming.js.map +1 -1
  46. package/lib/browser/window/default-window-service.js +1 -1
  47. package/lib/browser/window/default-window-service.js.map +1 -1
  48. package/lib/browser/window-contribution.d.ts.map +1 -1
  49. package/lib/browser/window-contribution.js +2 -2
  50. package/lib/browser/window-contribution.js.map +1 -1
  51. package/lib/common/color.d.ts +84 -0
  52. package/lib/common/color.d.ts.map +1 -0
  53. package/lib/common/color.js +44 -0
  54. package/lib/common/color.js.map +1 -0
  55. package/lib/common/command.d.ts +1 -0
  56. package/lib/common/command.d.ts.map +1 -1
  57. package/lib/common/command.js +4 -0
  58. package/lib/common/command.js.map +1 -1
  59. package/lib/common/i18n/localization.d.ts +9 -0
  60. package/lib/common/i18n/localization.d.ts.map +1 -1
  61. package/lib/common/i18n/localization.js +13 -2
  62. package/lib/common/i18n/localization.js.map +1 -1
  63. package/lib/common/keys.d.ts +269 -0
  64. package/lib/common/keys.d.ts.map +1 -0
  65. package/lib/common/keys.js +634 -0
  66. package/lib/common/keys.js.map +1 -0
  67. package/lib/common/messaging/abstract-connection-provider.d.ts +1 -1
  68. package/lib/common/messaging/abstract-connection-provider.d.ts.map +1 -1
  69. package/lib/common/messaging/abstract-connection-provider.js +3 -1
  70. package/lib/common/messaging/abstract-connection-provider.js.map +1 -1
  71. package/lib/common/messaging/proxy-factory.js +1 -1
  72. package/lib/common/messaging/proxy-factory.js.map +1 -1
  73. package/lib/common/nls.d.ts +5 -0
  74. package/lib/common/nls.d.ts.map +1 -1
  75. package/lib/common/nls.js +62 -0
  76. package/lib/common/nls.js.map +1 -1
  77. package/lib/common/path.d.ts +6 -0
  78. package/lib/common/path.d.ts.map +1 -1
  79. package/lib/common/path.js +16 -4
  80. package/lib/common/path.js.map +1 -1
  81. package/lib/common/path.spec.js +12 -0
  82. package/lib/common/path.spec.js.map +1 -1
  83. package/lib/common/promise-util.d.ts +2 -2
  84. package/lib/common/promise-util.d.ts.map +1 -1
  85. package/lib/common/promise-util.js.map +1 -1
  86. package/lib/common/quick-pick-service.d.ts +219 -1
  87. package/lib/common/quick-pick-service.d.ts.map +1 -1
  88. package/lib/common/quick-pick-service.js +108 -1
  89. package/lib/common/quick-pick-service.js.map +1 -1
  90. package/lib/common/theme.d.ts +30 -0
  91. package/lib/common/theme.d.ts.map +1 -0
  92. package/lib/common/theme.js +18 -0
  93. package/lib/common/theme.js.map +1 -0
  94. package/lib/electron-browser/menu/electron-menu-contribution.d.ts.map +1 -1
  95. package/lib/electron-browser/menu/electron-menu-contribution.js +17 -17
  96. package/lib/electron-browser/menu/electron-menu-contribution.js.map +1 -1
  97. package/lib/electron-browser/window/electron-window-preferences.js +2 -2
  98. package/lib/electron-browser/window/electron-window-preferences.js.map +1 -1
  99. package/package.json +5 -5
  100. package/src/browser/color-registry.ts +3 -85
  101. package/src/browser/common-frontend-contribution.ts +64 -64
  102. package/src/browser/core-preferences.ts +24 -21
  103. package/src/browser/dialogs.ts +4 -4
  104. package/src/browser/keyboard/browser-keyboard-frontend-contribution.ts +2 -2
  105. package/src/browser/keyboard/browser-keyboard-layout-provider.spec.ts +10 -4
  106. package/src/browser/keyboard/keys.ts +2 -675
  107. package/src/browser/messaging/ws-connection-provider.ts +13 -4
  108. package/src/browser/quick-input/quick-command-frontend-contribution.ts +1 -1
  109. package/src/browser/quick-input/quick-command-service.ts +2 -2
  110. package/src/browser/quick-input/quick-input-service.ts +1 -278
  111. package/src/browser/shell/tab-bar-toolbar.tsx +1 -1
  112. package/src/browser/storage-service.spec.ts +1 -1
  113. package/src/browser/theming.ts +6 -17
  114. package/src/browser/window/default-window-service.ts +1 -1
  115. package/src/browser/window-contribution.ts +2 -2
  116. package/src/common/color.ts +100 -0
  117. package/src/common/command.ts +10 -0
  118. package/src/common/i18n/localization.ts +13 -3
  119. package/src/common/i18n/nls.metadata.json +20421 -0
  120. package/src/common/keys.ts +693 -0
  121. package/src/common/messaging/abstract-connection-provider.ts +3 -1
  122. package/src/common/messaging/proxy-factory.ts +1 -1
  123. package/src/common/nls.ts +74 -0
  124. package/src/common/path.spec.ts +15 -0
  125. package/src/common/path.ts +16 -4
  126. package/src/common/promise-util.ts +3 -3
  127. package/src/common/quick-pick-service.ts +299 -4
  128. package/src/common/theme.ts +32 -0
  129. package/src/electron-browser/menu/electron-menu-contribution.ts +17 -17
  130. package/src/electron-browser/window/electron-window-preferences.ts +2 -2
@@ -49,7 +49,9 @@ export abstract class AbstractConnectionProvider<AbstractOptions extends object>
49
49
  protected readonly channels = new Map<number, WebSocketChannel>();
50
50
 
51
51
  protected readonly onIncomingMessageActivityEmitter: Emitter<void> = new Emitter();
52
- public onIncomingMessageActivity: Event<void> = this.onIncomingMessageActivityEmitter.event;
52
+ get onIncomingMessageActivity(): Event<void> {
53
+ return this.onIncomingMessageActivityEmitter.event;
54
+ }
53
55
 
54
56
  /**
55
57
  * Create a proxy object to remote interface of T type
@@ -240,7 +240,7 @@ export class JsonRpcProxyFactory<T extends object> implements ProxyHandler<T> {
240
240
  try {
241
241
  if (isNotify) {
242
242
  connection.sendNotification(method, ...args);
243
- resolve();
243
+ resolve(undefined);
244
244
  } else {
245
245
  const resultPromise = connection.sendRequest(method, ...args) as Promise<any>;
246
246
  resultPromise
package/src/common/nls.ts CHANGED
@@ -24,7 +24,81 @@ export namespace nls {
24
24
 
25
25
  export const locale = typeof window === 'object' && window && window.localStorage.getItem(localeId) || undefined;
26
26
 
27
+ let keyProvider: LocalizationKeyProvider | undefined;
28
+
29
+ /**
30
+ * Automatically localizes a text if that text also exists in the vscode repository.
31
+ */
32
+ export function localizeByDefault(defaultValue: string, ...args: FormatType[]): string {
33
+ const key = getDefaultKey(defaultValue);
34
+ if (key) {
35
+ return localize(key, defaultValue, ...args);
36
+ }
37
+ return Localization.format(defaultValue, args);
38
+ }
39
+
40
+ export function getDefaultKey(defaultValue: string): string {
41
+ if (localization) {
42
+ if (!keyProvider) {
43
+ keyProvider = new LocalizationKeyProvider();
44
+ }
45
+ const key = keyProvider.get(defaultValue);
46
+ if (key) {
47
+ return key;
48
+ } else {
49
+ console.warn(`Could not find translation key for default value: "${defaultValue}"`);
50
+ }
51
+ }
52
+ return '';
53
+ }
54
+
27
55
  export function localize(key: string, defaultValue: string, ...args: FormatType[]): string {
28
56
  return Localization.localize(localization, key, defaultValue, ...args);
29
57
  }
30
58
  }
59
+
60
+ interface NlsKeys {
61
+ [key: string]: (string | NlsInfo)[]
62
+ }
63
+
64
+ interface NlsInfo {
65
+ key: string
66
+ comment: string[]
67
+ }
68
+
69
+ class LocalizationKeyProvider {
70
+
71
+ private data = this.buildData();
72
+
73
+ get(defaultValue: string): string | undefined {
74
+ return this.data.get(defaultValue);
75
+ }
76
+
77
+ /**
78
+ * Transforms the data coming from the `nls.metadata.json` file into a map.
79
+ * The original data contains arrays of keys and messages.
80
+ * The result is a map that matches each message to the key that belongs to it.
81
+ *
82
+ * This allows us to skip the key in the localization process and map the original english default values to their translations in different languages.
83
+ */
84
+ private buildData(): Map<string, string> {
85
+ const bundles = require('../../src/common/i18n/nls.metadata.json');
86
+ const keys: NlsKeys = bundles.keys;
87
+ const messages: Record<string, string[]> = bundles.messages;
88
+ const data = new Map<string, string>();
89
+ for (const [fileKey, messageBundle] of Object.entries(messages)) {
90
+ const keyBundle = keys[fileKey];
91
+ for (let i = 0; i < messageBundle.length; i++) {
92
+ const message = Localization.normalize(messageBundle[i]);
93
+ const key = keyBundle[i];
94
+ const localizationKey = this.buildKey(typeof key === 'string' ? key : key.key, fileKey);
95
+ data.set(message, localizationKey);
96
+ }
97
+ }
98
+ return data;
99
+ }
100
+
101
+ private buildKey(key: string, filepath: string): string {
102
+ return `vscode/${Localization.transformKey(filepath)}/${key}`;
103
+ }
104
+ }
@@ -257,6 +257,20 @@ describe('Path', () => {
257
257
  });
258
258
  }
259
259
 
260
+ describe('Normalize path separator', () => {
261
+ it('should handle windows styled paths', async () => {
262
+ const path = 'C:\\a\\b\\c';
263
+ const expected = '/c:/a/b/c';
264
+ expect(new Path(path).toString()).eq(expected);
265
+ });
266
+
267
+ it('should prefix drive letter with /', async () => {
268
+ const path = 'c:/a/b/c';
269
+ const expected = '/c:/a/b/c';
270
+ expect(new Path(path).toString()).eq(expected);
271
+ });
272
+ });
273
+
260
274
  const linuxHome = '/home/test-user';
261
275
  const windowsHome = '/C:/Users/test-user';
262
276
 
@@ -340,5 +354,6 @@ describe('Path', () => {
340
354
  const expected = '~/a/b/theia';
341
355
  expect(Path.untildify(path, '')).eq(expected);
342
356
  });
357
+
343
358
  });
344
359
  });
@@ -53,11 +53,22 @@ export class Path {
53
53
  } else if (path.length >= 2 && path.charCodeAt(1) === 58 /* ':' */) {
54
54
  const code = path.charCodeAt(0);
55
55
  if (code >= 65 /* A */ && code <= 90 /* Z */) {
56
- path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "/c:".length === 3
56
+ path = `${String.fromCharCode(code + 32)}:${path.substr(2)}`; // "c:".length === 2
57
+ }
58
+ if (path.charCodeAt(0) !== 47 /* '/' */) {
59
+ path = `${String.fromCharCode(47)}${path}`;
57
60
  }
58
61
  }
59
62
  return path;
60
63
  }
64
+ /**
65
+ * Normalize path separator to use Path.separator
66
+ * @param Path candidate to normalize
67
+ * @returns Normalized string path
68
+ */
69
+ static normalizePathSeparator(path: string): string {
70
+ return path.split(/[\\]/).join(Path.separator);
71
+ }
61
72
 
62
73
  /**
63
74
  * Tildify path, replacing `home` with `~` if user's `home` is present at the beginning of the path.
@@ -112,11 +123,12 @@ export class Path {
112
123
  constructor(
113
124
  raw: string
114
125
  ) {
126
+ raw = Path.normalizePathSeparator(raw);
115
127
  this.raw = Path.normalizeDrive(raw);
116
- const firstIndex = raw.indexOf(Path.separator);
117
- const lastIndex = raw.lastIndexOf(Path.separator);
128
+ const firstIndex = this.raw.indexOf(Path.separator);
129
+ const lastIndex = this.raw.lastIndexOf(Path.separator);
118
130
  this.isAbsolute = firstIndex === 0;
119
- this.base = lastIndex === -1 ? raw : raw.substr(lastIndex + 1);
131
+ this.base = lastIndex === -1 ? this.raw : this.raw.substr(lastIndex + 1);
120
132
  this.isRoot = this.isAbsolute && firstIndex === lastIndex && (!this.base || Path.isDrive(this.base));
121
133
  this.root = this.computeRoot();
122
134
 
@@ -20,14 +20,14 @@ import { CancellationToken, cancelled } from './cancellation';
20
20
  * Simple implementation of the deferred pattern.
21
21
  * An object that exposes a promise and functions to resolve and reject it.
22
22
  */
23
- export class Deferred<T> {
23
+ export class Deferred<T = void> {
24
24
  state: 'resolved' | 'rejected' | 'unresolved' = 'unresolved';
25
- resolve: (value?: T) => void;
25
+ resolve: (value: T) => void;
26
26
  reject: (err?: any) => void; // eslint-disable-line @typescript-eslint/no-explicit-any
27
27
 
28
28
  promise = new Promise<T>((resolve, reject) => {
29
29
  this.resolve = result => {
30
- resolve(result as T);
30
+ resolve(result);
31
31
  if (this.state === 'unresolved') {
32
32
  this.state = 'resolved';
33
33
  }
@@ -13,18 +13,35 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
+
17
+ /********************************************************************************
18
+ * Copyright (c) 2021 SAP SE or an SAP affiliate company and others.
19
+ *
20
+ * This program and the accompanying materials are made available under the
21
+ * terms of the Eclipse Public License v. 2.0 which is available at
22
+ * http://www.eclipse.org/legal/epl-2.0.
23
+ *
24
+ * This Source Code may also be made available under the following Secondary
25
+ * Licenses when the conditions for such availability set forth in the Eclipse
26
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
27
+ * with the GNU Classpath Exception which is available at
28
+ * https://www.gnu.org/software/classpath/license.html.
29
+ *
30
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
31
+ ********************************************************************************/
32
+
33
+ import URI from './uri';
34
+ import * as fuzzy from 'fuzzy';
16
35
  import { Event } from './event';
17
- // eslint-disable-next-line @theia/runtime-import-check
18
- import { QuickInputButtonHandle, QuickPick, QuickPickItem, QuickPickOptions } from '../browser/quick-input/quick-input-service';
36
+ import { KeySequence } from './keys';
37
+ import { CancellationToken } from './cancellation';
19
38
 
20
39
  export const quickPickServicePath = '/services/quickPick';
21
40
  export const QuickPickService = Symbol('QuickPickService');
22
41
  export interface QuickPickService {
23
-
24
42
  show<T extends QuickPickItem>(items: Array<T>, options?: QuickPickOptions<T>): Promise<T | undefined>;
25
43
  setItems<T extends QuickPickItem>(items: Array<T>): void;
26
44
  hide(): void
27
-
28
45
  readonly onDidHide: Event<void>;
29
46
  readonly onDidAccept: Event<void>;
30
47
  readonly onDidChangeValue: Event<{ quickPick: QuickPick<QuickPickItem>, filter: string }>;
@@ -32,3 +49,281 @@ export interface QuickPickService {
32
49
  readonly onDidChangeSelection: Event<{ quickPick: QuickPick<QuickPickItem>, selectedItems: Array<QuickPickItem> }>;
33
50
  readonly onDidTriggerButton: Event<QuickInputButtonHandle>;
34
51
  }
52
+
53
+ export interface Match {
54
+ start: number;
55
+ end: number;
56
+ }
57
+ export interface QuickPickItemHighlights {
58
+ label?: Match[];
59
+ description?: Match[];
60
+ detail?: Match[];
61
+ }
62
+
63
+ export interface QuickPickItem {
64
+ type?: 'item' | 'separator';
65
+ id?: string;
66
+ label: string;
67
+ meta?: string;
68
+ ariaLabel?: string;
69
+ description?: string;
70
+ detail?: string;
71
+ keySequence?: KeySequence;
72
+ iconClasses?: string[];
73
+ alwaysShow?: boolean;
74
+ highlights?: QuickPickItemHighlights;
75
+ buttons?: QuickInputButton[];
76
+ execute?: () => void;
77
+ }
78
+
79
+ export namespace QuickPickItem {
80
+ export function is(item: QuickPickSeparator | QuickPickItem): item is QuickPickItem {
81
+ // if it's not a separator, it's an item
82
+ return item.type !== 'separator';
83
+ }
84
+ }
85
+
86
+ export interface QuickPickSeparator {
87
+ type: 'separator';
88
+ label?: string;
89
+ }
90
+
91
+ export namespace QuickPickSeparator {
92
+ export function is(item: QuickPickSeparator | QuickPickItem): item is QuickPickSeparator {
93
+ return item.type === 'separator';
94
+ }
95
+ }
96
+
97
+ export type QuickPicks = (QuickPickSeparator | QuickPickItem)[];
98
+
99
+ export interface QuickPickValue<V> extends QuickPickItem {
100
+ value: V
101
+ }
102
+
103
+ export interface QuickInputButton {
104
+ iconPath?: URI | { light: URI; dark: URI } | { id: string };
105
+ iconClass?: string;
106
+ tooltip?: string;
107
+ }
108
+
109
+ export interface QuickInputButtonHandle extends QuickInputButton {
110
+ index: number; // index of where they are in buttons array if QuickInputButton or -1 if QuickInputButtons.Back
111
+ }
112
+
113
+ export interface QuickInput {
114
+ readonly onDidHide: Event<void>;
115
+ readonly onDispose: Event<void>;
116
+ title: string | undefined;
117
+ description: string | undefined;
118
+ step: number | undefined;
119
+ totalSteps: number | undefined;
120
+ enabled: boolean;
121
+ contextKey: string | undefined;
122
+ busy: boolean;
123
+ ignoreFocusOut: boolean;
124
+ show(): void;
125
+ hide(): void;
126
+ dispose(): void;
127
+ }
128
+
129
+ export interface InputBox extends QuickInput {
130
+ value: string | undefined;
131
+ valueSelection: Readonly<[number, number]> | undefined;
132
+ placeholder: string | undefined;
133
+ password: boolean;
134
+ readonly onDidChangeValue: Event<string>;
135
+ readonly onDidAccept: Event<void>;
136
+ buttons: ReadonlyArray<QuickInputButton>;
137
+ readonly onDidTriggerButton: Event<QuickInputButton>;
138
+ prompt: string | undefined;
139
+ validationMessage: string | undefined;
140
+ }
141
+
142
+ export interface QuickPick<T extends QuickPickItem> extends QuickInput {
143
+ value: string;
144
+ placeholder: string | undefined;
145
+ items: ReadonlyArray<T | QuickPickSeparator>;
146
+ activeItems: ReadonlyArray<T>;
147
+ selectedItems: ReadonlyArray<T>;
148
+ canSelectMany: boolean;
149
+ matchOnDescription: boolean;
150
+ matchOnDetail: boolean;
151
+ readonly onDidAccept: Event<void>;
152
+ readonly onDidChangeValue: Event<string>;
153
+ readonly onDidTriggerButton: Event<QuickInputButton>;
154
+ readonly onDidTriggerItemButton: Event<QuickPickItemButtonEvent<T>>;
155
+ readonly onDidChangeActive: Event<T[]>;
156
+ readonly onDidChangeSelection: Event<T[]>;
157
+ }
158
+
159
+ export interface PickOptions<T extends QuickPickItem> {
160
+ placeHolder?: string;
161
+ matchOnDescription?: boolean;
162
+ matchOnDetail?: boolean;
163
+ matchOnLabel?: boolean;
164
+ autoFocusOnList?: boolean;
165
+ ignoreFocusLost?: boolean;
166
+ canPickMany?: boolean;
167
+ contextKey?: string;
168
+ activeItem?: Promise<T> | T;
169
+ onDidFocus?: (entry: T) => void;
170
+ }
171
+
172
+ export interface InputOptions {
173
+ value?: string;
174
+ valueSelection?: [number, number];
175
+ prompt?: string;
176
+ placeHolder?: string;
177
+ password?: boolean;
178
+ ignoreFocusLost?: boolean;
179
+ validateInput?(input: string): Promise<string | null | undefined> | undefined;
180
+ }
181
+
182
+ export interface QuickPickItemButtonEvent<T extends QuickPickItem> {
183
+ button: QuickInputButton;
184
+ item: T;
185
+ }
186
+
187
+ export interface QuickPickItemButtonContext<T extends QuickPickItem> extends QuickPickItemButtonEvent<T> {
188
+ removeItem(): void;
189
+ }
190
+
191
+ export interface QuickPickOptions<T extends QuickPickItem> {
192
+ busy?: boolean;
193
+ enabled?: boolean;
194
+ title?: string;
195
+ description?: string;
196
+ value?: string;
197
+ filterValue?: (value: string) => string;
198
+ ariaLabel?: string;
199
+ buttons?: Array<QuickInputButton>;
200
+ placeholder?: string;
201
+ canAcceptInBackground?: boolean;
202
+ customButton?: boolean;
203
+ customLabel?: string;
204
+ customHover?: string;
205
+ canSelectMany?: boolean;
206
+ matchOnDescription?: boolean;
207
+ matchOnDetail?: boolean;
208
+ matchOnLabel?: boolean;
209
+ sortByLabel?: boolean;
210
+ autoFocusOnList?: boolean;
211
+ ignoreFocusOut?: boolean;
212
+ valueSelection?: Readonly<[number, number]>;
213
+ validationMessage?: string;
214
+ hideInput?: boolean;
215
+ hideCheckAll?: boolean;
216
+ runIfSingle?: boolean
217
+ contextKey?: string;
218
+ activeItem?: T,
219
+ step?: number;
220
+ totalSteps?: number;
221
+
222
+ onDidAccept?: () => void,
223
+ onDidChangeActive?: (quickPick: QuickPick<T>, activeItems: Array<T>) => void,
224
+ onDidChangeSelection?: (quickPick: QuickPick<T>, selectedItems: Array<T>) => void,
225
+ onDidChangeValue?: (quickPick: QuickPick<T>, filter: string) => void,
226
+ onDidCustom?: () => void,
227
+ onDidHide?: () => void;
228
+ onDidTriggerButton?: (button: QuickInputButton) => void,
229
+ onDidTriggerItemButton?: (ItemButtonEvent: QuickPickItemButtonContext<T>) => void
230
+ }
231
+
232
+ export const QuickInputService = Symbol('QuickInputService');
233
+ export interface QuickInputService {
234
+ readonly backButton: QuickInputButton;
235
+ readonly onShow: Event<void>;
236
+ readonly onHide: Event<void>;
237
+ open(filter: string): void;
238
+ createInputBox(): InputBox;
239
+ input(options?: InputOptions, token?: CancellationToken): Promise<string | undefined>;
240
+ pick<T extends QuickPickItem, O extends PickOptions<T>>(picks: Promise<T[]> | T[], options?: O, token?: CancellationToken):
241
+ Promise<(O extends { canPickMany: true } ? T[] : T) | undefined>;
242
+ showQuickPick<T extends QuickPickItem>(items: Array<T>, options?: QuickPickOptions<T>): Promise<T>;
243
+ hide(): void;
244
+ /**
245
+ * Provides raw access to the quick pick controller.
246
+ */
247
+ createQuickPick<T extends QuickPickItem>(): QuickPick<T>;
248
+ }
249
+
250
+ /**
251
+ * Filter the list of quick pick items based on the provided filter.
252
+ * Items are filtered based on if:
253
+ * - their `label` satisfies the filter using `fuzzy`.
254
+ * - their `description` satisfies the filter using `fuzzy`.
255
+ * - their `detail` satisfies the filter using `fuzzy`.
256
+ * Filtered items are also updated to display proper highlights based on how they were filtered.
257
+ * @param items the list of quick pick items.
258
+ * @param filter the filter to search for.
259
+ * @returns the list of quick pick items that satisfy the filter.
260
+ */
261
+ export function filterItems(items: QuickPickItem[], filter: string): QuickPickItem[] {
262
+ filter = filter.trim().toLowerCase();
263
+
264
+ if (filter.length === 0) {
265
+ for (const item of items) {
266
+ item.highlights = undefined; // reset highlights from previous filtering.
267
+ }
268
+ return items;
269
+ }
270
+
271
+ const filteredItems: QuickPickItem[] = [];
272
+ for (const item of items) {
273
+ if (
274
+ fuzzy.test(filter, item.label) ||
275
+ (item.description && fuzzy.test(filter, item.description)) ||
276
+ (item.detail && fuzzy.test(filter, item.detail))
277
+ ) {
278
+ item.highlights = {
279
+ label: findMatches(item.label, filter),
280
+ description: item.description ? findMatches(item.description, filter) : undefined,
281
+ detail: item.detail ? findMatches(item.detail, filter) : undefined
282
+ };
283
+ filteredItems.push(item);
284
+ }
285
+ }
286
+ return filteredItems;
287
+ }
288
+
289
+ /**
290
+ * Find match highlights when testing a word against a pattern.
291
+ * @param word the word to test.
292
+ * @param pattern the word to match against.
293
+ * @returns the list of highlights if present.
294
+ */
295
+ export function findMatches(word: string, pattern: string): Array<{ start: number, end: number }> | undefined {
296
+ word = word.toLocaleLowerCase();
297
+ pattern = pattern.toLocaleLowerCase();
298
+
299
+ if (pattern.trim().length === 0) {
300
+ return undefined;
301
+ }
302
+
303
+ const delimiter = '\u0000'; // null byte that shouldn't appear in the input and is used to denote matches.
304
+ const matchResult = fuzzy.match(pattern.replace(/\u0000/gu, ''), word, { pre: delimiter, post: delimiter });
305
+ if (!matchResult) {
306
+ return undefined;
307
+ }
308
+
309
+ const match = matchResult.rendered;
310
+ const highlights: { start: number, end: number }[] = [];
311
+
312
+ let lastIndex = 0;
313
+ /** We need to account for the extra markers by removing them from the range */
314
+ let offset = 0;
315
+
316
+ while (true) {
317
+ const start = match.indexOf(delimiter, lastIndex);
318
+ if (start === -1) { break; }
319
+ const end = match.indexOf(delimiter, start + 1);
320
+ if (end === -1) { break; }
321
+ highlights.push({
322
+ start: start - offset++,
323
+ end: end - offset++
324
+ });
325
+ lastIndex = end + 1;
326
+ }
327
+
328
+ return highlights.length > 0 ? highlights : undefined;
329
+ }
@@ -0,0 +1,32 @@
1
+ /********************************************************************************
2
+ * Copyright (C) 2017 TypeFox and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ export type ThemeType = 'light' | 'dark' | 'hc';
18
+
19
+ export interface Theme {
20
+ readonly id: string;
21
+ readonly type: ThemeType;
22
+ readonly label: string;
23
+ readonly description?: string;
24
+ readonly editorTheme?: string;
25
+ activate(): void;
26
+ deactivate(): void;
27
+ }
28
+
29
+ export interface ThemeChangeEvent {
30
+ readonly newTheme: Theme;
31
+ readonly oldTheme?: Theme;
32
+ }
@@ -34,35 +34,35 @@ import { BrowserMenuBarContribution } from '../../browser/menu/browser-menu-plug
34
34
  import '../../../src/electron-browser/menu/electron-menu-style.css';
35
35
 
36
36
  export namespace ElectronCommands {
37
- export const TOGGLE_DEVELOPER_TOOLS = Command.toLocalizedCommand({
37
+ export const TOGGLE_DEVELOPER_TOOLS = Command.toDefaultLocalizedCommand({
38
38
  id: 'theia.toggleDevTools',
39
39
  label: 'Toggle Developer Tools'
40
- }, 'vscode/developerActions/toggleDevTools');
41
- export const RELOAD = Command.toLocalizedCommand({
40
+ });
41
+ export const RELOAD = Command.toDefaultLocalizedCommand({
42
42
  id: 'view.reload',
43
43
  label: 'Reload Window'
44
- }, 'vscode/windowActions/reloadWindow');
45
- export const ZOOM_IN = Command.toLocalizedCommand({
44
+ });
45
+ export const ZOOM_IN = Command.toDefaultLocalizedCommand({
46
46
  id: 'view.zoomIn',
47
47
  label: 'Zoom In'
48
- }, 'vscode/windowActions/zoomIn');
49
- export const ZOOM_OUT = Command.toLocalizedCommand({
48
+ });
49
+ export const ZOOM_OUT = Command.toDefaultLocalizedCommand({
50
50
  id: 'view.zoomOut',
51
51
  label: 'Zoom Out'
52
- }, 'vscode/windowActions/zoomOut');
53
- export const RESET_ZOOM = Command.toLocalizedCommand({
52
+ });
53
+ export const RESET_ZOOM = Command.toDefaultLocalizedCommand({
54
54
  id: 'view.resetZoom',
55
55
  label: 'Reset Zoom'
56
- }, 'vscode/windowActions/zoomReset');
57
- export const CLOSE_WINDOW = Command.toLocalizedCommand({
56
+ });
57
+ export const CLOSE_WINDOW = Command.toDefaultLocalizedCommand({
58
58
  id: 'close.window',
59
59
  label: 'Close Window'
60
- }, 'vscode/windowActions/close');
61
- export const TOGGLE_FULL_SCREEN = Command.toLocalizedCommand({
60
+ });
61
+ export const TOGGLE_FULL_SCREEN = Command.toDefaultLocalizedCommand({
62
62
  id: 'workbench.action.toggleFullScreen',
63
63
  category: CommonCommands.VIEW_CATEGORY,
64
64
  label: 'Toggle Full Screen'
65
- }, 'vscode/windowActions/toggleFullScreen', CommonCommands.VIEW_CATEGORY_KEY);
65
+ });
66
66
  }
67
67
 
68
68
  export namespace ElectronMenus {
@@ -228,12 +228,12 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
228
228
  protected async handleRequiredRestart(): Promise<void> {
229
229
  const msgNode = document.createElement('div');
230
230
  const message = document.createElement('p');
231
- message.textContent = nls.localize('vscode/relauncher.contribution/relaunchSettingMessage', 'A setting has changed that requires a restart to take effect');
231
+ message.textContent = nls.localizeByDefault('A setting has changed that requires a restart to take effect');
232
232
  const detail = document.createElement('p');
233
- detail.textContent = nls.localize('vscode/relauncher.contribution/relaunchSettingDetail',
233
+ detail.textContent = nls.localizeByDefault(
234
234
  'Press the restart button to restart {0} and enable the setting.', FrontendApplicationConfigProvider.get().applicationName);
235
235
  msgNode.append(message, detail);
236
- const restart = nls.localize('vscode/relauncher.contribution/restart', 'Restart');
236
+ const restart = nls.localizeByDefault('Restart');
237
237
  const dialog = new ConfirmDialog({
238
238
  title: restart,
239
239
  msg: msgNode,
@@ -38,7 +38,7 @@ export const electronWindowPreferencesSchema: PreferenceSchema = {
38
38
  'maximum': ZoomLevel.MAX,
39
39
  'scope': 'application',
40
40
  // eslint-disable-next-line max-len
41
- 'description': nls.localize('vscode/desktop.contribution/zoomLevel', 'Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1.0) or below (e.g. -1.0) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity.')
41
+ 'description': nls.localizeByDefault('Adjust the zoom level of the window. The original size is 0 and each increment above (e.g. 1.0) or below (e.g. -1.0) represents zooming 20% larger or smaller. You can also enter decimals to adjust the zoom level with a finer granularity.')
42
42
  },
43
43
  'window.titleBarStyle': {
44
44
  type: 'string',
@@ -46,7 +46,7 @@ export const electronWindowPreferencesSchema: PreferenceSchema = {
46
46
  default: isWindows ? 'custom' : 'native',
47
47
  scope: 'application',
48
48
  // eslint-disable-next-line max-len
49
- description: nls.localize('vscode/desktop.contribution/titleBarStyle', 'Adjust the appearance of the window title bar. On Linux and Windows, this setting also affects the application and context menu appearances. Changes require a full restart to apply.'),
49
+ description: nls.localizeByDefault('Adjust the appearance of the window title bar. On Linux and Windows, this setting also affects the application and context menu appearances. Changes require a full restart to apply.'),
50
50
  included: !isOSX
51
51
  },
52
52
  }