@theia/mini-browser 1.18.0-next.d3501165 → 1.19.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.
@@ -18,7 +18,7 @@ import { Widget } from '@theia/core/shared/@phosphor/widgets';
18
18
  import { injectable, inject, optional } from '@theia/core/shared/inversify';
19
19
  import URI from '@theia/core/lib/common/uri';
20
20
  import { MaybePromise } from '@theia/core/lib/common/types';
21
- import { QuickInputService } from '@theia/core/lib/browser';
21
+ import { codicon, QuickInputService } from '@theia/core/lib/browser';
22
22
  import { ApplicationShell } from '@theia/core/lib/browser/shell';
23
23
  import { Command, CommandContribution, CommandRegistry } from '@theia/core/lib/common/command';
24
24
  import { MenuContribution, MenuModelRegistry } from '@theia/core/lib/common/menu';
@@ -31,29 +31,39 @@ import { WidgetOpenerOptions } from '@theia/core/lib/browser/widget-open-handler
31
31
  import { MiniBrowserService } from '../common/mini-browser-service';
32
32
  import { MiniBrowser, MiniBrowserProps } from './mini-browser';
33
33
  import { LocationMapperService } from './location-mapper-service';
34
+ import { nls } from '@theia/core/lib/common/nls';
34
35
 
35
36
  export namespace MiniBrowserCommands {
36
- export const PREVIEW: Command = {
37
+
38
+ export const PREVIEW_CATEGORY_KEY = 'vscode/extensionEditor/preview';
39
+ export const PREVIEW_CATEGORY = 'Preview';
40
+
41
+ export const PREVIEW = Command.toLocalizedCommand({
37
42
  id: 'mini-browser.preview',
38
43
  label: 'Open Preview',
39
- iconClass: 'theia-open-preview-icon'
40
- };
44
+ iconClass: codicon('open-preview')
45
+ }, 'vscode/mainThreadFileSystemEventService/preview');
41
46
  export const OPEN_SOURCE: Command = {
42
47
  id: 'mini-browser.open.source',
43
- iconClass: 'theia-open-file-icon'
48
+ iconClass: codicon('go-to-file')
44
49
  };
45
- export const OPEN_URL: Command = {
50
+ export const OPEN_URL = Command.toLocalizedCommand({
46
51
  id: 'mini-browser.openUrl',
47
- category: 'Preview',
52
+ category: PREVIEW_CATEGORY,
48
53
  label: 'Open URL'
49
- };
54
+ }, 'vscode/url.contribution/openUrl', PREVIEW_CATEGORY_KEY);
50
55
  }
51
56
 
52
57
  /**
53
58
  * Further options for opening a new `Mini Browser` widget.
54
59
  */
55
60
  export interface MiniBrowserOpenerOptions extends WidgetOpenerOptions, MiniBrowserProps {
56
-
61
+ /**
62
+ * Controls how the mini-browser widget should be opened.
63
+ * - `source`: editable source.
64
+ * - `preview`: rendered content of the source.
65
+ */
66
+ openFor?: 'source' | 'preview';
57
67
  }
58
68
 
59
69
  @injectable()
@@ -73,7 +83,7 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
73
83
  protected readonly supportedExtensions: Map<string, number> = new Map();
74
84
 
75
85
  readonly id = MiniBrowser.ID;
76
- readonly label = 'Preview';
86
+ readonly label = nls.localize(MiniBrowserCommands.PREVIEW_CATEGORY_KEY, MiniBrowserCommands.PREVIEW_CATEGORY);
77
87
 
78
88
  @inject(OpenerService)
79
89
  protected readonly openerService: OpenerService;
@@ -99,14 +109,20 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
99
109
  });
100
110
  }
101
111
 
102
- canHandle(uri: URI): number {
112
+ canHandle(uri: URI, options?: MiniBrowserOpenerOptions): number {
103
113
  // It does not guard against directories. For instance, a folder with this name: `Hahahah.html`.
104
114
  // We could check with the FS, but then, this method would become async again.
105
115
  const extension = uri.toString().split('.').pop();
106
- if (extension) {
116
+ if (!extension) {
117
+ return 0;
118
+ }
119
+ if (options?.openFor === 'source') {
120
+ return -100;
121
+ } else if (options?.openFor === 'preview') {
122
+ return 200; // higher than that of the editor.
123
+ } else {
107
124
  return this.supportedExtensions.get(extension.toLocaleLowerCase()) || 0;
108
125
  }
109
- return 0;
110
126
  }
111
127
 
112
128
  async open(uri: URI, options?: MiniBrowserOpenerOptions): Promise<MiniBrowser> {
@@ -204,12 +220,12 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
204
220
  toolbar.registerItem({
205
221
  id: MiniBrowserCommands.PREVIEW.id,
206
222
  command: MiniBrowserCommands.PREVIEW.id,
207
- tooltip: 'Open Preview to the Side'
223
+ tooltip: nls.localize('theia/preview/openPreviewSide', 'Open Preview to the Side')
208
224
  });
209
225
  toolbar.registerItem({
210
226
  id: MiniBrowserCommands.OPEN_SOURCE.id,
211
227
  command: MiniBrowserCommands.OPEN_SOURCE.id,
212
- tooltip: 'Open Source'
228
+ tooltip: nls.localize('theia/preview/openSource', 'Open Source')
213
229
  });
214
230
  }
215
231
 
@@ -240,7 +256,8 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
240
256
  }
241
257
  await this.open(uri, {
242
258
  mode: 'reveal',
243
- widgetOptions: { ref, mode: 'open-to-right' }
259
+ widgetOptions: { ref, mode: 'open-to-right' },
260
+ openFor: 'preview'
244
261
  });
245
262
  }
246
263
 
@@ -248,7 +265,8 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
248
265
  const uri = this.getSourceUri(ref);
249
266
  if (uri) {
250
267
  await open(this.openerService, uri, {
251
- widgetOptions: { ref, mode: 'open-to-left' }
268
+ widgetOptions: { ref, mode: 'tab-after' },
269
+ openFor: 'source'
252
270
  });
253
271
  }
254
272
  }
@@ -263,8 +281,8 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
263
281
 
264
282
  protected async openUrl(arg?: string): Promise<void> {
265
283
  const url = arg ? arg : await this.quickInputService?.input({
266
- prompt: 'URL to open',
267
- placeHolder: 'Type a URL'
284
+ prompt: nls.localize('vscode/url.contribution/urlToOpen', 'URL to open'),
285
+ placeHolder: nls.localize('theia/mini-browser/typeUrl', 'Type a URL')
268
286
  });
269
287
  if (url) {
270
288
  await this.openPreview(url);
@@ -279,14 +297,15 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
279
297
  protected async getOpenPreviewProps(startPage: string): Promise<MiniBrowserOpenerOptions> {
280
298
  const resetBackground = await this.resetBackground(new URI(startPage));
281
299
  return {
282
- name: 'Preview',
300
+ name: nls.localize(MiniBrowserCommands.PREVIEW_CATEGORY_KEY, MiniBrowserCommands.PREVIEW_CATEGORY),
283
301
  startPage,
284
302
  toolbar: 'read-only',
285
303
  widgetOptions: {
286
304
  area: 'right'
287
305
  },
288
306
  resetBackground,
289
- iconClass: 'theia-mini-browser-icon'
307
+ iconClass: codicon('preview'),
308
+ openFor: 'preview'
290
309
  };
291
310
  }
292
311
 
@@ -19,7 +19,7 @@ import { Message } from '@theia/core/shared/@phosphor/messaging';
19
19
  import URI from '@theia/core/lib/common/uri';
20
20
  import { NavigatableWidget, StatefulWidget } from '@theia/core/lib/browser';
21
21
  import { DisposableCollection } from '@theia/core/lib/common/disposable';
22
- import { BaseWidget, PanelLayout } from '@theia/core/lib/browser/widgets/widget';
22
+ import { BaseWidget, codicon, PanelLayout } from '@theia/core/lib/browser/widgets/widget';
23
23
  import { MiniBrowserProps, MiniBrowserContentFactory } from './mini-browser-content';
24
24
 
25
25
  export { MiniBrowserProps };
@@ -33,7 +33,7 @@ export class MiniBrowserOptions {
33
33
  export class MiniBrowser extends BaseWidget implements NavigatableWidget, StatefulWidget {
34
34
 
35
35
  static ID = 'mini-browser';
36
- static ICON = 'fa fa-globe';
36
+ static ICON = codicon('globe');
37
37
 
38
38
  @inject(MiniBrowserOptions)
39
39
  protected readonly options: MiniBrowserOptions;
@@ -24,11 +24,6 @@
24
24
  height: 100%;
25
25
  }
26
26
 
27
- .theia-mini-browser-icon {
28
- mask: url('mini-browser.svg');
29
- -webkit-mask: url('mini-browser.svg');
30
- }
31
-
32
27
  .theia-mini-browser-toolbar {
33
28
  margin-top: 8px;
34
29
  display: flex;