@theia/editor-preview 1.34.3 → 1.34.4

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 (28) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +52 -52
  3. package/lib/browser/editor-preview-contribution.d.ts +12 -12
  4. package/lib/browser/editor-preview-contribution.js +79 -79
  5. package/lib/browser/editor-preview-frontend-module.d.ts +4 -4
  6. package/lib/browser/editor-preview-frontend-module.js +42 -42
  7. package/lib/browser/editor-preview-manager.d.ts +24 -24
  8. package/lib/browser/editor-preview-manager.js +142 -142
  9. package/lib/browser/editor-preview-preferences.d.ts +11 -11
  10. package/lib/browser/editor-preview-preferences.js +47 -47
  11. package/lib/browser/editor-preview-tree-decorator.d.ts +23 -23
  12. package/lib/browser/editor-preview-tree-decorator.js +110 -110
  13. package/lib/browser/editor-preview-widget-factory.d.ts +13 -13
  14. package/lib/browser/editor-preview-widget-factory.js +52 -52
  15. package/lib/browser/editor-preview-widget.d.ts +25 -25
  16. package/lib/browser/editor-preview-widget.js +102 -102
  17. package/lib/package.spec.js +25 -25
  18. package/package.json +6 -6
  19. package/src/browser/editor-preview-contribution.ts +67 -67
  20. package/src/browser/editor-preview-frontend-module.ts +46 -46
  21. package/src/browser/editor-preview-manager.ts +125 -125
  22. package/src/browser/editor-preview-preferences.ts +53 -53
  23. package/src/browser/editor-preview-tree-decorator.ts +107 -107
  24. package/src/browser/editor-preview-widget-factory.ts +45 -45
  25. package/src/browser/editor-preview-widget.ts +113 -113
  26. package/src/browser/style/editor-preview-widget.css +23 -23
  27. package/src/browser/style/index.css +17 -17
  28. package/src/package.spec.ts +28 -28
@@ -1,53 +1,53 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Google 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
- import { interfaces } from '@theia/core/shared/inversify';
18
- import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';
19
- import { nls } from '@theia/core/lib/common/nls';
20
-
21
- export const EditorPreviewConfigSchema: PreferenceSchema = {
22
- 'type': 'object',
23
- properties: {
24
- 'editor.enablePreview': {
25
- type: 'boolean',
26
- // eslint-disable-next-line max-len
27
- description: nls.localizeByDefault('Controls whether opened editors show as preview editors. Preview editors do not stay open, are reused until explicitly set to be kept open (e.g. via double click or editing), and show file names in italics.'),
28
- default: true
29
- },
30
- }
31
- };
32
-
33
- export interface EditorPreviewConfiguration {
34
- 'editor.enablePreview': boolean;
35
- }
36
-
37
- export const EditorPreviewPreferenceContribution = Symbol('EditorPreviewPreferenceContribution');
38
- export const EditorPreviewPreferences = Symbol('EditorPreviewPreferences');
39
- export type EditorPreviewPreferences = PreferenceProxy<EditorPreviewConfiguration>;
40
-
41
- export function createEditorPreviewPreferences(preferences: PreferenceService, schema: PreferenceSchema = EditorPreviewConfigSchema): EditorPreviewPreferences {
42
- return createPreferenceProxy(preferences, schema);
43
- }
44
-
45
- export function bindEditorPreviewPreferences(bind: interfaces.Bind): void {
46
- bind(EditorPreviewPreferences).toDynamicValue(ctx => {
47
- const preferences = ctx.container.get<PreferenceService>(PreferenceService);
48
- const contribution = ctx.container.get<PreferenceContribution>(EditorPreviewPreferenceContribution);
49
- return createEditorPreviewPreferences(preferences, contribution.schema);
50
- }).inSingletonScope();
51
- bind(EditorPreviewPreferenceContribution).toConstantValue({ schema: EditorPreviewConfigSchema });
52
- bind(PreferenceContribution).toService(EditorPreviewPreferenceContribution);
53
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Google 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
+ import { interfaces } from '@theia/core/shared/inversify';
18
+ import { createPreferenceProxy, PreferenceProxy, PreferenceService, PreferenceContribution, PreferenceSchema } from '@theia/core/lib/browser';
19
+ import { nls } from '@theia/core/lib/common/nls';
20
+
21
+ export const EditorPreviewConfigSchema: PreferenceSchema = {
22
+ 'type': 'object',
23
+ properties: {
24
+ 'editor.enablePreview': {
25
+ type: 'boolean',
26
+ // eslint-disable-next-line max-len
27
+ description: nls.localizeByDefault('Controls whether opened editors show as preview editors. Preview editors do not stay open, are reused until explicitly set to be kept open (e.g. via double click or editing), and show file names in italics.'),
28
+ default: true
29
+ },
30
+ }
31
+ };
32
+
33
+ export interface EditorPreviewConfiguration {
34
+ 'editor.enablePreview': boolean;
35
+ }
36
+
37
+ export const EditorPreviewPreferenceContribution = Symbol('EditorPreviewPreferenceContribution');
38
+ export const EditorPreviewPreferences = Symbol('EditorPreviewPreferences');
39
+ export type EditorPreviewPreferences = PreferenceProxy<EditorPreviewConfiguration>;
40
+
41
+ export function createEditorPreviewPreferences(preferences: PreferenceService, schema: PreferenceSchema = EditorPreviewConfigSchema): EditorPreviewPreferences {
42
+ return createPreferenceProxy(preferences, schema);
43
+ }
44
+
45
+ export function bindEditorPreviewPreferences(bind: interfaces.Bind): void {
46
+ bind(EditorPreviewPreferences).toDynamicValue(ctx => {
47
+ const preferences = ctx.container.get<PreferenceService>(PreferenceService);
48
+ const contribution = ctx.container.get<PreferenceContribution>(EditorPreviewPreferenceContribution);
49
+ return createEditorPreviewPreferences(preferences, contribution.schema);
50
+ }).inSingletonScope();
51
+ bind(EditorPreviewPreferenceContribution).toConstantValue({ schema: EditorPreviewConfigSchema });
52
+ bind(PreferenceContribution).toService(EditorPreviewPreferenceContribution);
53
+ }
@@ -1,107 +1,107 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 Ericsson 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
- import { injectable, inject } from '@theia/core/shared/inversify';
18
- import { TreeDecorator, TreeDecoration } from '@theia/core/lib/browser/tree/tree-decorator';
19
- import { Emitter } from '@theia/core/lib/common/event';
20
- import { Tree } from '@theia/core/lib/browser/tree/tree';
21
- import {
22
- ApplicationShell,
23
- DepthFirstTreeIterator,
24
- FrontendApplication,
25
- FrontendApplicationContribution,
26
- NavigatableWidget,
27
- Saveable,
28
- Widget,
29
- } from '@theia/core/lib/browser';
30
- import { Disposable } from '@theia/core/lib/common';
31
- import { OpenEditorNode } from '@theia/navigator/lib/browser/open-editors-widget/navigator-open-editors-tree-model';
32
- import { EditorPreviewWidget } from './editor-preview-widget';
33
- import { EditorPreviewManager } from './editor-preview-manager';
34
-
35
- @injectable()
36
- export class EditorPreviewTreeDecorator implements TreeDecorator, FrontendApplicationContribution {
37
- @inject(EditorPreviewManager) protected readonly editorPreviewManager: EditorPreviewManager;
38
- @inject(ApplicationShell) protected readonly shell: ApplicationShell;
39
-
40
- readonly id = 'theia-open-editors-file-decorator';
41
- protected decorationsMap = new Map<string, TreeDecoration.Data>();
42
-
43
- protected readonly decorationsChangedEmitter = new Emitter();
44
- readonly onDidChangeDecorations = this.decorationsChangedEmitter.event;
45
- protected readonly toDisposeOnDirtyChanged = new Map<string, Disposable>();
46
- protected readonly toDisposeOnPreviewPinned = new Map<string, Disposable>();
47
-
48
- onDidInitializeLayout(app: FrontendApplication): void {
49
- this.shell.onDidAddWidget(widget => this.registerEditorListeners(widget));
50
- this.shell.onDidRemoveWidget(widget => this.unregisterEditorListeners(widget));
51
- this.editorWidgets.forEach(widget => this.registerEditorListeners(widget));
52
- }
53
-
54
- protected registerEditorListeners(widget: Widget): void {
55
- const saveable = Saveable.get(widget);
56
- if (saveable) {
57
- this.toDisposeOnDirtyChanged.set(widget.id, saveable.onDirtyChanged(() => {
58
- this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
59
- }));
60
- }
61
- if (widget instanceof EditorPreviewWidget) {
62
- this.toDisposeOnPreviewPinned.set(widget.id, widget.onDidChangePreviewState(() => {
63
- this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
64
- this.toDisposeOnPreviewPinned.get(widget.id)?.dispose();
65
- this.toDisposeOnDirtyChanged.delete(widget.id);
66
- }));
67
- }
68
- }
69
-
70
- protected unregisterEditorListeners(widget: Widget): void {
71
- this.toDisposeOnDirtyChanged.get(widget.id)?.dispose();
72
- this.toDisposeOnDirtyChanged.delete(widget.id);
73
- this.toDisposeOnPreviewPinned.get(widget.id)?.dispose();
74
- this.toDisposeOnPreviewPinned.delete(widget.id);
75
- }
76
-
77
- protected get editorWidgets(): NavigatableWidget[] {
78
- return this.shell.widgets.filter((widget): widget is NavigatableWidget => NavigatableWidget.is(widget));
79
- }
80
-
81
- protected fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void {
82
- this.decorationsChangedEmitter.fire(event);
83
- }
84
-
85
- decorations(tree: Tree): Map<string, TreeDecoration.Data> {
86
- return this.collectDecorators(tree);
87
- }
88
-
89
- // Add workspace root as caption suffix and italicize if PreviewWidget
90
- protected collectDecorators(tree: Tree): Map<string, TreeDecoration.Data> {
91
- const result = new Map<string, TreeDecoration.Data>();
92
- if (tree.root === undefined) {
93
- return result;
94
- }
95
- for (const node of new DepthFirstTreeIterator(tree.root)) {
96
- if (OpenEditorNode.is(node)) {
97
- const { widget } = node;
98
- const isPreviewWidget = widget instanceof EditorPreviewWidget && widget.isPreview;
99
- const decorations: TreeDecoration.Data = {
100
- fontData: { style: isPreviewWidget ? 'italic' : undefined }
101
- };
102
- result.set(node.id, decorations);
103
- }
104
- }
105
- return result;
106
- }
107
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 Ericsson 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
+ import { injectable, inject } from '@theia/core/shared/inversify';
18
+ import { TreeDecorator, TreeDecoration } from '@theia/core/lib/browser/tree/tree-decorator';
19
+ import { Emitter } from '@theia/core/lib/common/event';
20
+ import { Tree } from '@theia/core/lib/browser/tree/tree';
21
+ import {
22
+ ApplicationShell,
23
+ DepthFirstTreeIterator,
24
+ FrontendApplication,
25
+ FrontendApplicationContribution,
26
+ NavigatableWidget,
27
+ Saveable,
28
+ Widget,
29
+ } from '@theia/core/lib/browser';
30
+ import { Disposable } from '@theia/core/lib/common';
31
+ import { OpenEditorNode } from '@theia/navigator/lib/browser/open-editors-widget/navigator-open-editors-tree-model';
32
+ import { EditorPreviewWidget } from './editor-preview-widget';
33
+ import { EditorPreviewManager } from './editor-preview-manager';
34
+
35
+ @injectable()
36
+ export class EditorPreviewTreeDecorator implements TreeDecorator, FrontendApplicationContribution {
37
+ @inject(EditorPreviewManager) protected readonly editorPreviewManager: EditorPreviewManager;
38
+ @inject(ApplicationShell) protected readonly shell: ApplicationShell;
39
+
40
+ readonly id = 'theia-open-editors-file-decorator';
41
+ protected decorationsMap = new Map<string, TreeDecoration.Data>();
42
+
43
+ protected readonly decorationsChangedEmitter = new Emitter();
44
+ readonly onDidChangeDecorations = this.decorationsChangedEmitter.event;
45
+ protected readonly toDisposeOnDirtyChanged = new Map<string, Disposable>();
46
+ protected readonly toDisposeOnPreviewPinned = new Map<string, Disposable>();
47
+
48
+ onDidInitializeLayout(app: FrontendApplication): void {
49
+ this.shell.onDidAddWidget(widget => this.registerEditorListeners(widget));
50
+ this.shell.onDidRemoveWidget(widget => this.unregisterEditorListeners(widget));
51
+ this.editorWidgets.forEach(widget => this.registerEditorListeners(widget));
52
+ }
53
+
54
+ protected registerEditorListeners(widget: Widget): void {
55
+ const saveable = Saveable.get(widget);
56
+ if (saveable) {
57
+ this.toDisposeOnDirtyChanged.set(widget.id, saveable.onDirtyChanged(() => {
58
+ this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
59
+ }));
60
+ }
61
+ if (widget instanceof EditorPreviewWidget) {
62
+ this.toDisposeOnPreviewPinned.set(widget.id, widget.onDidChangePreviewState(() => {
63
+ this.fireDidChangeDecorations((tree: Tree) => this.collectDecorators(tree));
64
+ this.toDisposeOnPreviewPinned.get(widget.id)?.dispose();
65
+ this.toDisposeOnDirtyChanged.delete(widget.id);
66
+ }));
67
+ }
68
+ }
69
+
70
+ protected unregisterEditorListeners(widget: Widget): void {
71
+ this.toDisposeOnDirtyChanged.get(widget.id)?.dispose();
72
+ this.toDisposeOnDirtyChanged.delete(widget.id);
73
+ this.toDisposeOnPreviewPinned.get(widget.id)?.dispose();
74
+ this.toDisposeOnPreviewPinned.delete(widget.id);
75
+ }
76
+
77
+ protected get editorWidgets(): NavigatableWidget[] {
78
+ return this.shell.widgets.filter((widget): widget is NavigatableWidget => NavigatableWidget.is(widget));
79
+ }
80
+
81
+ protected fireDidChangeDecorations(event: (tree: Tree) => Map<string, TreeDecoration.Data>): void {
82
+ this.decorationsChangedEmitter.fire(event);
83
+ }
84
+
85
+ decorations(tree: Tree): Map<string, TreeDecoration.Data> {
86
+ return this.collectDecorators(tree);
87
+ }
88
+
89
+ // Add workspace root as caption suffix and italicize if PreviewWidget
90
+ protected collectDecorators(tree: Tree): Map<string, TreeDecoration.Data> {
91
+ const result = new Map<string, TreeDecoration.Data>();
92
+ if (tree.root === undefined) {
93
+ return result;
94
+ }
95
+ for (const node of new DepthFirstTreeIterator(tree.root)) {
96
+ if (OpenEditorNode.is(node)) {
97
+ const { widget } = node;
98
+ const isPreviewWidget = widget instanceof EditorPreviewWidget && widget.isPreview;
99
+ const decorations: TreeDecoration.Data = {
100
+ fontData: { style: isPreviewWidget ? 'italic' : undefined }
101
+ };
102
+ result.set(node.id, decorations);
103
+ }
104
+ }
105
+ return result;
106
+ }
107
+ }
@@ -1,45 +1,45 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018-2021 Google 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
- import URI from '@theia/core/lib/common/uri';
18
- import { EditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
19
- import { injectable } from '@theia/core/shared/inversify';
20
- import { EditorPreviewWidget } from './editor-preview-widget';
21
- import { NavigatableWidgetOptions } from '@theia/core/lib/browser';
22
-
23
- export interface EditorPreviewOptions extends NavigatableWidgetOptions {
24
- preview?: boolean;
25
- }
26
-
27
- @injectable()
28
- export class EditorPreviewWidgetFactory extends EditorWidgetFactory {
29
- static override ID: string = 'editor-preview-widget';
30
- override readonly id = EditorPreviewWidgetFactory.ID;
31
-
32
- override async createWidget(options: EditorPreviewOptions): Promise<EditorPreviewWidget> {
33
- const uri = new URI(options.uri);
34
- const editor = await this.createEditor(uri, options) as EditorPreviewWidget;
35
- if (options.preview) {
36
- editor.initializePreview();
37
- }
38
- return editor;
39
- }
40
-
41
- protected override async constructEditor(uri: URI): Promise<EditorPreviewWidget> {
42
- const textEditor = await this.editorProvider(uri);
43
- return new EditorPreviewWidget(textEditor, this.selectionService);
44
- }
45
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018-2021 Google 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
+ import URI from '@theia/core/lib/common/uri';
18
+ import { EditorWidgetFactory } from '@theia/editor/lib/browser/editor-widget-factory';
19
+ import { injectable } from '@theia/core/shared/inversify';
20
+ import { EditorPreviewWidget } from './editor-preview-widget';
21
+ import { NavigatableWidgetOptions } from '@theia/core/lib/browser';
22
+
23
+ export interface EditorPreviewOptions extends NavigatableWidgetOptions {
24
+ preview?: boolean;
25
+ }
26
+
27
+ @injectable()
28
+ export class EditorPreviewWidgetFactory extends EditorWidgetFactory {
29
+ static override ID: string = 'editor-preview-widget';
30
+ override readonly id = EditorPreviewWidgetFactory.ID;
31
+
32
+ override async createWidget(options: EditorPreviewOptions): Promise<EditorPreviewWidget> {
33
+ const uri = new URI(options.uri);
34
+ const editor = await this.createEditor(uri, options) as EditorPreviewWidget;
35
+ if (options.preview) {
36
+ editor.initializePreview();
37
+ }
38
+ return editor;
39
+ }
40
+
41
+ protected override async constructEditor(uri: URI): Promise<EditorPreviewWidget> {
42
+ const textEditor = await this.editorProvider(uri);
43
+ return new EditorPreviewWidget(textEditor, this.selectionService);
44
+ }
45
+ }
@@ -1,113 +1,113 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 Ericsson 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
- import { Message } from '@theia/core/shared/@phosphor/messaging';
18
- import { DockPanel, TabBar, Widget, PINNED_CLASS } from '@theia/core/lib/browser';
19
- import { EditorWidget, TextEditor } from '@theia/editor/lib/browser';
20
- import { Disposable, DisposableCollection, Emitter, SelectionService, UNTITLED_SCHEME } from '@theia/core/lib/common';
21
- import { find } from '@theia/core/shared/@phosphor/algorithm';
22
-
23
- const PREVIEW_TITLE_CLASS = 'theia-editor-preview-title-unpinned';
24
- export class EditorPreviewWidget extends EditorWidget {
25
- protected _isPreview = false;
26
- protected lastTabbar: TabBar<Widget> | undefined;
27
-
28
- protected readonly onDidChangePreviewStateEmitter = new Emitter<void>();
29
- readonly onDidChangePreviewState = this.onDidChangePreviewStateEmitter.event;
30
-
31
- protected readonly toDisposeOnLocationChange = new DisposableCollection();
32
-
33
- get isPreview(): boolean {
34
- return this._isPreview;
35
- }
36
-
37
- constructor(
38
- editor: TextEditor,
39
- selectionService: SelectionService
40
- ) {
41
- super(editor, selectionService);
42
- this.toDispose.push(this.onDidChangePreviewStateEmitter);
43
- this.toDispose.push(this.toDisposeOnLocationChange);
44
- }
45
-
46
- initializePreview(): void {
47
- const oneTimeListeners = new DisposableCollection();
48
- this._isPreview = true;
49
- this.title.className += ` ${PREVIEW_TITLE_CLASS}`;
50
- const oneTimeDirtyChangeListener = this.saveable.onDirtyChanged(() => {
51
- this.convertToNonPreview();
52
- oneTimeListeners.dispose();
53
- });
54
- oneTimeListeners.push(oneTimeDirtyChangeListener);
55
- const oneTimeTitleChangeHandler = () => {
56
- if (this.title.className.includes(PINNED_CLASS)) {
57
- this.convertToNonPreview();
58
- oneTimeListeners.dispose();
59
- }
60
- };
61
- this.title.changed.connect(oneTimeTitleChangeHandler);
62
- oneTimeListeners.push(Disposable.create(() => this.title.changed.disconnect(oneTimeTitleChangeHandler)));
63
- this.toDispose.push(oneTimeListeners);
64
- }
65
-
66
- convertToNonPreview(): void {
67
- if (this._isPreview) {
68
- this._isPreview = false;
69
- this.toDisposeOnLocationChange.dispose();
70
- this.lastTabbar = undefined;
71
- this.title.className = this.title.className.replace(PREVIEW_TITLE_CLASS, '');
72
- this.onDidChangePreviewStateEmitter.fire();
73
- this.onDidChangePreviewStateEmitter.dispose();
74
- }
75
- }
76
-
77
- protected override onAfterAttach(msg: Message): void {
78
- super.onAfterAttach(msg);
79
- if (this._isPreview) {
80
- this.checkForTabbarChange();
81
- }
82
- }
83
-
84
- protected checkForTabbarChange(): void {
85
- const { parent } = this;
86
- if (parent instanceof DockPanel) {
87
- this.toDisposeOnLocationChange.dispose();
88
- const newTabbar = find(parent.tabBars(), tabbar => !!tabbar.titles.find(title => title === this.title));
89
- if (this.lastTabbar && this.lastTabbar !== newTabbar) {
90
- this.convertToNonPreview();
91
- } else {
92
- this.lastTabbar = newTabbar;
93
- const listener = () => this.checkForTabbarChange();
94
- parent.layoutModified.connect(listener);
95
- this.toDisposeOnLocationChange.push(Disposable.create(() => parent.layoutModified.disconnect(listener)));
96
- }
97
- }
98
- }
99
-
100
- override storeState(): { isPreview: boolean, editorState: object } | undefined {
101
- if (this.getResourceUri()?.scheme !== UNTITLED_SCHEME) {
102
- const { _isPreview: isPreview } = this;
103
- return { isPreview, editorState: this.editor.storeViewState() };
104
- }
105
- }
106
-
107
- override restoreState(oldState: { isPreview: boolean, editorState: object }): void {
108
- if (!oldState.isPreview) {
109
- this.convertToNonPreview();
110
- }
111
- this.editor.restoreViewState(oldState.editorState);
112
- }
113
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 Ericsson 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
+ import { Message } from '@theia/core/shared/@phosphor/messaging';
18
+ import { DockPanel, TabBar, Widget, PINNED_CLASS } from '@theia/core/lib/browser';
19
+ import { EditorWidget, TextEditor } from '@theia/editor/lib/browser';
20
+ import { Disposable, DisposableCollection, Emitter, SelectionService, UNTITLED_SCHEME } from '@theia/core/lib/common';
21
+ import { find } from '@theia/core/shared/@phosphor/algorithm';
22
+
23
+ const PREVIEW_TITLE_CLASS = 'theia-editor-preview-title-unpinned';
24
+ export class EditorPreviewWidget extends EditorWidget {
25
+ protected _isPreview = false;
26
+ protected lastTabbar: TabBar<Widget> | undefined;
27
+
28
+ protected readonly onDidChangePreviewStateEmitter = new Emitter<void>();
29
+ readonly onDidChangePreviewState = this.onDidChangePreviewStateEmitter.event;
30
+
31
+ protected readonly toDisposeOnLocationChange = new DisposableCollection();
32
+
33
+ get isPreview(): boolean {
34
+ return this._isPreview;
35
+ }
36
+
37
+ constructor(
38
+ editor: TextEditor,
39
+ selectionService: SelectionService
40
+ ) {
41
+ super(editor, selectionService);
42
+ this.toDispose.push(this.onDidChangePreviewStateEmitter);
43
+ this.toDispose.push(this.toDisposeOnLocationChange);
44
+ }
45
+
46
+ initializePreview(): void {
47
+ const oneTimeListeners = new DisposableCollection();
48
+ this._isPreview = true;
49
+ this.title.className += ` ${PREVIEW_TITLE_CLASS}`;
50
+ const oneTimeDirtyChangeListener = this.saveable.onDirtyChanged(() => {
51
+ this.convertToNonPreview();
52
+ oneTimeListeners.dispose();
53
+ });
54
+ oneTimeListeners.push(oneTimeDirtyChangeListener);
55
+ const oneTimeTitleChangeHandler = () => {
56
+ if (this.title.className.includes(PINNED_CLASS)) {
57
+ this.convertToNonPreview();
58
+ oneTimeListeners.dispose();
59
+ }
60
+ };
61
+ this.title.changed.connect(oneTimeTitleChangeHandler);
62
+ oneTimeListeners.push(Disposable.create(() => this.title.changed.disconnect(oneTimeTitleChangeHandler)));
63
+ this.toDispose.push(oneTimeListeners);
64
+ }
65
+
66
+ convertToNonPreview(): void {
67
+ if (this._isPreview) {
68
+ this._isPreview = false;
69
+ this.toDisposeOnLocationChange.dispose();
70
+ this.lastTabbar = undefined;
71
+ this.title.className = this.title.className.replace(PREVIEW_TITLE_CLASS, '');
72
+ this.onDidChangePreviewStateEmitter.fire();
73
+ this.onDidChangePreviewStateEmitter.dispose();
74
+ }
75
+ }
76
+
77
+ protected override onAfterAttach(msg: Message): void {
78
+ super.onAfterAttach(msg);
79
+ if (this._isPreview) {
80
+ this.checkForTabbarChange();
81
+ }
82
+ }
83
+
84
+ protected checkForTabbarChange(): void {
85
+ const { parent } = this;
86
+ if (parent instanceof DockPanel) {
87
+ this.toDisposeOnLocationChange.dispose();
88
+ const newTabbar = find(parent.tabBars(), tabbar => !!tabbar.titles.find(title => title === this.title));
89
+ if (this.lastTabbar && this.lastTabbar !== newTabbar) {
90
+ this.convertToNonPreview();
91
+ } else {
92
+ this.lastTabbar = newTabbar;
93
+ const listener = () => this.checkForTabbarChange();
94
+ parent.layoutModified.connect(listener);
95
+ this.toDisposeOnLocationChange.push(Disposable.create(() => parent.layoutModified.disconnect(listener)));
96
+ }
97
+ }
98
+ }
99
+
100
+ override storeState(): { isPreview: boolean, editorState: object } | undefined {
101
+ if (this.getResourceUri()?.scheme !== UNTITLED_SCHEME) {
102
+ const { _isPreview: isPreview } = this;
103
+ return { isPreview, editorState: this.editor.storeViewState() };
104
+ }
105
+ }
106
+
107
+ override restoreState(oldState: { isPreview: boolean, editorState: object }): void {
108
+ if (!oldState.isPreview) {
109
+ this.convertToNonPreview();
110
+ }
111
+ this.editor.restoreViewState(oldState.editorState);
112
+ }
113
+ }