@theia/editor-preview 1.34.2 → 1.34.3
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.
- package/LICENSE +641 -641
- package/README.md +52 -52
- package/lib/browser/editor-preview-contribution.d.ts +12 -12
- package/lib/browser/editor-preview-contribution.js +79 -79
- package/lib/browser/editor-preview-frontend-module.d.ts +4 -4
- package/lib/browser/editor-preview-frontend-module.js +42 -42
- package/lib/browser/editor-preview-manager.d.ts +24 -24
- package/lib/browser/editor-preview-manager.js +142 -142
- package/lib/browser/editor-preview-preferences.d.ts +11 -11
- package/lib/browser/editor-preview-preferences.js +47 -47
- package/lib/browser/editor-preview-tree-decorator.d.ts +23 -23
- package/lib/browser/editor-preview-tree-decorator.js +110 -110
- package/lib/browser/editor-preview-widget-factory.d.ts +13 -13
- package/lib/browser/editor-preview-widget-factory.js +52 -52
- package/lib/browser/editor-preview-widget.d.ts +25 -25
- package/lib/browser/editor-preview-widget.js +102 -102
- package/lib/package.spec.js +25 -25
- package/package.json +6 -6
- package/src/browser/editor-preview-contribution.ts +67 -67
- package/src/browser/editor-preview-frontend-module.ts +46 -46
- package/src/browser/editor-preview-manager.ts +125 -125
- package/src/browser/editor-preview-preferences.ts +53 -53
- package/src/browser/editor-preview-tree-decorator.ts +107 -107
- package/src/browser/editor-preview-widget-factory.ts +45 -45
- package/src/browser/editor-preview-widget.ts +113 -113
- package/src/browser/style/editor-preview-widget.css +23 -23
- package/src/browser/style/index.css +17 -17
- package/src/package.spec.ts +28 -28
package/lib/package.spec.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
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
|
-
/* note: this bogus test file is required so that
|
|
17
|
-
we are able to run mocha unit tests on this
|
|
18
|
-
package, without having any actual unit tests in it.
|
|
19
|
-
This way a coverage report will be generated,
|
|
20
|
-
showing 0% coverage, instead of no report.
|
|
21
|
-
This file can be removed once we have real unit
|
|
22
|
-
tests in place. */
|
|
23
|
-
describe('editor package', () => {
|
|
24
|
-
it('support code coverage statistics', () => true);
|
|
25
|
-
});
|
|
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
|
+
/* note: this bogus test file is required so that
|
|
17
|
+
we are able to run mocha unit tests on this
|
|
18
|
+
package, without having any actual unit tests in it.
|
|
19
|
+
This way a coverage report will be generated,
|
|
20
|
+
showing 0% coverage, instead of no report.
|
|
21
|
+
This file can be removed once we have real unit
|
|
22
|
+
tests in place. */
|
|
23
|
+
describe('editor package', () => {
|
|
24
|
+
it('support code coverage statistics', () => true);
|
|
25
|
+
});
|
|
26
26
|
//# sourceMappingURL=package.spec.js.map
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/editor-preview",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.3",
|
|
4
4
|
"description": "Theia - Editor Preview Extension",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/core": "1.34.
|
|
7
|
-
"@theia/editor": "1.34.
|
|
8
|
-
"@theia/navigator": "1.34.
|
|
6
|
+
"@theia/core": "1.34.3",
|
|
7
|
+
"@theia/editor": "1.34.3",
|
|
8
|
+
"@theia/navigator": "1.34.3"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"watch": "theiaext watch"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@theia/ext-scripts": "1.34.
|
|
43
|
+
"@theia/ext-scripts": "1.34.3"
|
|
44
44
|
},
|
|
45
45
|
"nyc": {
|
|
46
46
|
"extends": "../../configs/nyc.json"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "a6cf9fe96b1624d6e27a11dce2ebdeae820478e5"
|
|
49
49
|
}
|
|
@@ -1,67 +1,67 @@
|
|
|
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 { ApplicationShell, CommonCommands, KeybindingContribution, KeybindingRegistry, SHELL_TABBAR_CONTEXT_PIN, Widget } from '@theia/core/lib/browser';
|
|
18
|
-
import { nls } from '@theia/core/lib/common/nls';
|
|
19
|
-
import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core/lib/common';
|
|
20
|
-
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
21
|
-
import { EditorPreviewWidget } from './editor-preview-widget';
|
|
22
|
-
import { CurrentWidgetCommandAdapter } from '@theia/core/lib/browser/shell/current-widget-command-adapter';
|
|
23
|
-
|
|
24
|
-
export namespace EditorPreviewCommands {
|
|
25
|
-
export const PIN_PREVIEW_COMMAND = Command.toDefaultLocalizedCommand({
|
|
26
|
-
id: 'workbench.action.keepEditor',
|
|
27
|
-
category: CommonCommands.VIEW_CATEGORY,
|
|
28
|
-
label: 'Keep Editor',
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@injectable()
|
|
33
|
-
export class EditorPreviewContribution implements CommandContribution, MenuContribution, KeybindingContribution {
|
|
34
|
-
@inject(ApplicationShell) protected readonly shell: ApplicationShell;
|
|
35
|
-
|
|
36
|
-
registerCommands(registry: CommandRegistry): void {
|
|
37
|
-
registry.registerCommand(EditorPreviewCommands.PIN_PREVIEW_COMMAND, new CurrentWidgetCommandAdapter(this.shell, {
|
|
38
|
-
execute: async title => {
|
|
39
|
-
if (title?.owner instanceof EditorPreviewWidget) {
|
|
40
|
-
title.owner.convertToNonPreview();
|
|
41
|
-
await this.shell.activateWidget(title.owner.id);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
isEnabled: title => title?.owner instanceof EditorPreviewWidget && title.owner.isPreview,
|
|
45
|
-
isVisible: title => title?.owner instanceof EditorPreviewWidget,
|
|
46
|
-
}));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
registerKeybindings(registry: KeybindingRegistry): void {
|
|
50
|
-
registry.registerKeybinding({
|
|
51
|
-
command: EditorPreviewCommands.PIN_PREVIEW_COMMAND.id,
|
|
52
|
-
keybinding: 'ctrlcmd+k enter'
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
registerMenus(registry: MenuModelRegistry): void {
|
|
57
|
-
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_PIN, {
|
|
58
|
-
commandId: EditorPreviewCommands.PIN_PREVIEW_COMMAND.id,
|
|
59
|
-
label: nls.localizeByDefault('Keep Open'),
|
|
60
|
-
order: '6',
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
protected getTargetWidget(event?: Event): Widget | undefined {
|
|
65
|
-
return event ? this.shell.findTargetedWidget(event) : this.shell.activeWidget;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
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 { ApplicationShell, CommonCommands, KeybindingContribution, KeybindingRegistry, SHELL_TABBAR_CONTEXT_PIN, Widget } from '@theia/core/lib/browser';
|
|
18
|
+
import { nls } from '@theia/core/lib/common/nls';
|
|
19
|
+
import { Command, CommandContribution, CommandRegistry, MenuContribution, MenuModelRegistry } from '@theia/core/lib/common';
|
|
20
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
21
|
+
import { EditorPreviewWidget } from './editor-preview-widget';
|
|
22
|
+
import { CurrentWidgetCommandAdapter } from '@theia/core/lib/browser/shell/current-widget-command-adapter';
|
|
23
|
+
|
|
24
|
+
export namespace EditorPreviewCommands {
|
|
25
|
+
export const PIN_PREVIEW_COMMAND = Command.toDefaultLocalizedCommand({
|
|
26
|
+
id: 'workbench.action.keepEditor',
|
|
27
|
+
category: CommonCommands.VIEW_CATEGORY,
|
|
28
|
+
label: 'Keep Editor',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@injectable()
|
|
33
|
+
export class EditorPreviewContribution implements CommandContribution, MenuContribution, KeybindingContribution {
|
|
34
|
+
@inject(ApplicationShell) protected readonly shell: ApplicationShell;
|
|
35
|
+
|
|
36
|
+
registerCommands(registry: CommandRegistry): void {
|
|
37
|
+
registry.registerCommand(EditorPreviewCommands.PIN_PREVIEW_COMMAND, new CurrentWidgetCommandAdapter(this.shell, {
|
|
38
|
+
execute: async title => {
|
|
39
|
+
if (title?.owner instanceof EditorPreviewWidget) {
|
|
40
|
+
title.owner.convertToNonPreview();
|
|
41
|
+
await this.shell.activateWidget(title.owner.id);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
isEnabled: title => title?.owner instanceof EditorPreviewWidget && title.owner.isPreview,
|
|
45
|
+
isVisible: title => title?.owner instanceof EditorPreviewWidget,
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
registerKeybindings(registry: KeybindingRegistry): void {
|
|
50
|
+
registry.registerKeybinding({
|
|
51
|
+
command: EditorPreviewCommands.PIN_PREVIEW_COMMAND.id,
|
|
52
|
+
keybinding: 'ctrlcmd+k enter'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
registerMenus(registry: MenuModelRegistry): void {
|
|
57
|
+
registry.registerMenuAction(SHELL_TABBAR_CONTEXT_PIN, {
|
|
58
|
+
commandId: EditorPreviewCommands.PIN_PREVIEW_COMMAND.id,
|
|
59
|
+
label: nls.localizeByDefault('Keep Open'),
|
|
60
|
+
order: '6',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected getTargetWidget(event?: Event): Widget | undefined {
|
|
65
|
+
return event ? this.shell.findTargetedWidget(event) : this.shell.activeWidget;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
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 '../../src/browser/style/index.css';
|
|
18
|
-
import { FrontendApplicationContribution, KeybindingContribution, WidgetFactory } from '@theia/core/lib/browser';
|
|
19
|
-
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
20
|
-
import { bindEditorPreviewPreferences } from './editor-preview-preferences';
|
|
21
|
-
import { EditorPreviewManager } from './editor-preview-manager';
|
|
22
|
-
import { EditorManager } from '@theia/editor/lib/browser';
|
|
23
|
-
import { EditorPreviewWidgetFactory } from './editor-preview-widget-factory';
|
|
24
|
-
import { EditorPreviewContribution } from './editor-preview-contribution';
|
|
25
|
-
import { CommandContribution, MenuContribution } from '@theia/core/lib/common';
|
|
26
|
-
import { OpenEditorsTreeDecorator } from '@theia/navigator/lib/browser/open-editors-widget/navigator-open-editors-decorator-service';
|
|
27
|
-
import { EditorPreviewTreeDecorator } from './editor-preview-tree-decorator';
|
|
28
|
-
|
|
29
|
-
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
30
|
-
|
|
31
|
-
bind(EditorPreviewWidgetFactory).toSelf().inSingletonScope();
|
|
32
|
-
bind(WidgetFactory).toService(EditorPreviewWidgetFactory);
|
|
33
|
-
|
|
34
|
-
bind(EditorPreviewManager).toSelf().inSingletonScope();
|
|
35
|
-
rebind(EditorManager).toService(EditorPreviewManager);
|
|
36
|
-
|
|
37
|
-
bind(EditorPreviewContribution).toSelf().inSingletonScope();
|
|
38
|
-
bind(CommandContribution).toService(EditorPreviewContribution);
|
|
39
|
-
bind(KeybindingContribution).toService(EditorPreviewContribution);
|
|
40
|
-
bind(MenuContribution).toService(EditorPreviewContribution);
|
|
41
|
-
|
|
42
|
-
bind(EditorPreviewTreeDecorator).toSelf().inSingletonScope();
|
|
43
|
-
bind(OpenEditorsTreeDecorator).toService(EditorPreviewTreeDecorator);
|
|
44
|
-
bind(FrontendApplicationContribution).toService(EditorPreviewTreeDecorator);
|
|
45
|
-
bindEditorPreviewPreferences(bind);
|
|
46
|
-
});
|
|
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 '../../src/browser/style/index.css';
|
|
18
|
+
import { FrontendApplicationContribution, KeybindingContribution, WidgetFactory } from '@theia/core/lib/browser';
|
|
19
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
20
|
+
import { bindEditorPreviewPreferences } from './editor-preview-preferences';
|
|
21
|
+
import { EditorPreviewManager } from './editor-preview-manager';
|
|
22
|
+
import { EditorManager } from '@theia/editor/lib/browser';
|
|
23
|
+
import { EditorPreviewWidgetFactory } from './editor-preview-widget-factory';
|
|
24
|
+
import { EditorPreviewContribution } from './editor-preview-contribution';
|
|
25
|
+
import { CommandContribution, MenuContribution } from '@theia/core/lib/common';
|
|
26
|
+
import { OpenEditorsTreeDecorator } from '@theia/navigator/lib/browser/open-editors-widget/navigator-open-editors-decorator-service';
|
|
27
|
+
import { EditorPreviewTreeDecorator } from './editor-preview-tree-decorator';
|
|
28
|
+
|
|
29
|
+
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
30
|
+
|
|
31
|
+
bind(EditorPreviewWidgetFactory).toSelf().inSingletonScope();
|
|
32
|
+
bind(WidgetFactory).toService(EditorPreviewWidgetFactory);
|
|
33
|
+
|
|
34
|
+
bind(EditorPreviewManager).toSelf().inSingletonScope();
|
|
35
|
+
rebind(EditorManager).toService(EditorPreviewManager);
|
|
36
|
+
|
|
37
|
+
bind(EditorPreviewContribution).toSelf().inSingletonScope();
|
|
38
|
+
bind(CommandContribution).toService(EditorPreviewContribution);
|
|
39
|
+
bind(KeybindingContribution).toService(EditorPreviewContribution);
|
|
40
|
+
bind(MenuContribution).toService(EditorPreviewContribution);
|
|
41
|
+
|
|
42
|
+
bind(EditorPreviewTreeDecorator).toSelf().inSingletonScope();
|
|
43
|
+
bind(OpenEditorsTreeDecorator).toService(EditorPreviewTreeDecorator);
|
|
44
|
+
bind(FrontendApplicationContribution).toService(EditorPreviewTreeDecorator);
|
|
45
|
+
bindEditorPreviewPreferences(bind);
|
|
46
|
+
});
|
|
@@ -1,125 +1,125 @@
|
|
|
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 { EditorManager, EditorOpenerOptions, EditorWidget } from '@theia/editor/lib/browser';
|
|
18
|
-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
19
|
-
import { EditorPreviewPreferences } from './editor-preview-preferences';
|
|
20
|
-
import { MaybePromise } from '@theia/core/lib/common';
|
|
21
|
-
import URI from '@theia/core/lib/common/uri';
|
|
22
|
-
import { EditorPreviewWidgetFactory, EditorPreviewOptions } from './editor-preview-widget-factory';
|
|
23
|
-
import { EditorPreviewWidget } from './editor-preview-widget';
|
|
24
|
-
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
|
|
25
|
-
|
|
26
|
-
@injectable()
|
|
27
|
-
export class EditorPreviewManager extends EditorManager {
|
|
28
|
-
override readonly id = EditorPreviewWidgetFactory.ID;
|
|
29
|
-
|
|
30
|
-
@inject(EditorPreviewPreferences) protected readonly preferences: EditorPreviewPreferences;
|
|
31
|
-
@inject(FrontendApplicationStateService) protected readonly stateService: FrontendApplicationStateService;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Until the layout has been restored, widget state is not reliable, so we ignore creation events.
|
|
35
|
-
*/
|
|
36
|
-
protected layoutIsSet = false;
|
|
37
|
-
|
|
38
|
-
@postConstruct()
|
|
39
|
-
protected override init(): void {
|
|
40
|
-
super.init();
|
|
41
|
-
// All editors are created, but not all are opened. This sets up the logic to swap previews when the editor is attached.
|
|
42
|
-
this.onCreated((widget: EditorPreviewWidget) => {
|
|
43
|
-
if (this.layoutIsSet && widget.isPreview) {
|
|
44
|
-
const oneTimeDisposable = widget.onDidChangeVisibility(() => {
|
|
45
|
-
this.handleNewPreview(widget);
|
|
46
|
-
oneTimeDisposable.dispose();
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
this.preferences.onPreferenceChanged(change => {
|
|
52
|
-
if (change.preferenceName === 'editor.enablePreview' && !change.newValue) {
|
|
53
|
-
this.all.forEach((editor: EditorPreviewWidget) => {
|
|
54
|
-
if (editor.isPreview) {
|
|
55
|
-
editor.convertToNonPreview();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
this.stateService.reachedState('initialized_layout').then(() => {
|
|
62
|
-
const editors = this.all as EditorPreviewWidget[];
|
|
63
|
-
const currentPreview = editors.find(editor => editor.isPreview);
|
|
64
|
-
if (currentPreview) {
|
|
65
|
-
this.handleNewPreview(currentPreview);
|
|
66
|
-
}
|
|
67
|
-
this.layoutIsSet = true;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
document.addEventListener('dblclick', this.convertEditorOnDoubleClick.bind(this));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
protected override async doOpen(widget: EditorPreviewWidget, options?: EditorOpenerOptions): Promise<void> {
|
|
74
|
-
const { preview, widgetOptions = { area: 'main' }, mode = 'activate' } = options ?? {};
|
|
75
|
-
if (!widget.isAttached) {
|
|
76
|
-
this.shell.addWidget(widget, widgetOptions);
|
|
77
|
-
} else if (!preview && widget.isPreview) {
|
|
78
|
-
widget.convertToNonPreview();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (mode === 'activate') {
|
|
82
|
-
await this.shell.activateWidget(widget.id);
|
|
83
|
-
} else if (mode === 'reveal') {
|
|
84
|
-
await this.shell.revealWidget(widget.id);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
protected handleNewPreview(newPreviewWidget: EditorPreviewWidget): void {
|
|
89
|
-
if (newPreviewWidget.isPreview) {
|
|
90
|
-
const tabbar = this.shell.getTabBarFor(newPreviewWidget);
|
|
91
|
-
if (tabbar) {
|
|
92
|
-
for (const title of tabbar.titles) {
|
|
93
|
-
if (title.owner !== newPreviewWidget && title.owner instanceof EditorPreviewWidget && title.owner.isPreview) {
|
|
94
|
-
title.owner.dispose();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
protected override tryGetPendingWidget(uri: URI, options?: EditorOpenerOptions): MaybePromise<EditorWidget> | undefined {
|
|
102
|
-
return super.tryGetPendingWidget(uri, { ...options, preview: true }) ?? super.tryGetPendingWidget(uri, { ...options, preview: false });
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
protected override async getWidget(uri: URI, options?: EditorOpenerOptions): Promise<EditorWidget | undefined> {
|
|
106
|
-
return (await super.getWidget(uri, { ...options, preview: true })) ?? super.getWidget(uri, { ...options, preview: false });
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
protected override async getOrCreateWidget(uri: URI, options?: EditorOpenerOptions): Promise<EditorWidget> {
|
|
110
|
-
return this.tryGetPendingWidget(uri, options) ?? super.getOrCreateWidget(uri, options);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
protected override createWidgetOptions(uri: URI, options?: EditorOpenerOptions): EditorPreviewOptions {
|
|
114
|
-
const navigatableOptions = super.createWidgetOptions(uri, options) as EditorPreviewOptions;
|
|
115
|
-
navigatableOptions.preview = !!(options?.preview && this.preferences['editor.enablePreview']);
|
|
116
|
-
return navigatableOptions;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
protected convertEditorOnDoubleClick(event: Event): void {
|
|
120
|
-
const widget = this.shell.findTargetedWidget(event);
|
|
121
|
-
if (widget instanceof EditorPreviewWidget && widget.isPreview) {
|
|
122
|
-
widget.convertToNonPreview();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
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 { EditorManager, EditorOpenerOptions, EditorWidget } from '@theia/editor/lib/browser';
|
|
18
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
19
|
+
import { EditorPreviewPreferences } from './editor-preview-preferences';
|
|
20
|
+
import { MaybePromise } from '@theia/core/lib/common';
|
|
21
|
+
import URI from '@theia/core/lib/common/uri';
|
|
22
|
+
import { EditorPreviewWidgetFactory, EditorPreviewOptions } from './editor-preview-widget-factory';
|
|
23
|
+
import { EditorPreviewWidget } from './editor-preview-widget';
|
|
24
|
+
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
|
|
25
|
+
|
|
26
|
+
@injectable()
|
|
27
|
+
export class EditorPreviewManager extends EditorManager {
|
|
28
|
+
override readonly id = EditorPreviewWidgetFactory.ID;
|
|
29
|
+
|
|
30
|
+
@inject(EditorPreviewPreferences) protected readonly preferences: EditorPreviewPreferences;
|
|
31
|
+
@inject(FrontendApplicationStateService) protected readonly stateService: FrontendApplicationStateService;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Until the layout has been restored, widget state is not reliable, so we ignore creation events.
|
|
35
|
+
*/
|
|
36
|
+
protected layoutIsSet = false;
|
|
37
|
+
|
|
38
|
+
@postConstruct()
|
|
39
|
+
protected override init(): void {
|
|
40
|
+
super.init();
|
|
41
|
+
// All editors are created, but not all are opened. This sets up the logic to swap previews when the editor is attached.
|
|
42
|
+
this.onCreated((widget: EditorPreviewWidget) => {
|
|
43
|
+
if (this.layoutIsSet && widget.isPreview) {
|
|
44
|
+
const oneTimeDisposable = widget.onDidChangeVisibility(() => {
|
|
45
|
+
this.handleNewPreview(widget);
|
|
46
|
+
oneTimeDisposable.dispose();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
this.preferences.onPreferenceChanged(change => {
|
|
52
|
+
if (change.preferenceName === 'editor.enablePreview' && !change.newValue) {
|
|
53
|
+
this.all.forEach((editor: EditorPreviewWidget) => {
|
|
54
|
+
if (editor.isPreview) {
|
|
55
|
+
editor.convertToNonPreview();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
this.stateService.reachedState('initialized_layout').then(() => {
|
|
62
|
+
const editors = this.all as EditorPreviewWidget[];
|
|
63
|
+
const currentPreview = editors.find(editor => editor.isPreview);
|
|
64
|
+
if (currentPreview) {
|
|
65
|
+
this.handleNewPreview(currentPreview);
|
|
66
|
+
}
|
|
67
|
+
this.layoutIsSet = true;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
document.addEventListener('dblclick', this.convertEditorOnDoubleClick.bind(this));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected override async doOpen(widget: EditorPreviewWidget, options?: EditorOpenerOptions): Promise<void> {
|
|
74
|
+
const { preview, widgetOptions = { area: 'main' }, mode = 'activate' } = options ?? {};
|
|
75
|
+
if (!widget.isAttached) {
|
|
76
|
+
this.shell.addWidget(widget, widgetOptions);
|
|
77
|
+
} else if (!preview && widget.isPreview) {
|
|
78
|
+
widget.convertToNonPreview();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (mode === 'activate') {
|
|
82
|
+
await this.shell.activateWidget(widget.id);
|
|
83
|
+
} else if (mode === 'reveal') {
|
|
84
|
+
await this.shell.revealWidget(widget.id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
protected handleNewPreview(newPreviewWidget: EditorPreviewWidget): void {
|
|
89
|
+
if (newPreviewWidget.isPreview) {
|
|
90
|
+
const tabbar = this.shell.getTabBarFor(newPreviewWidget);
|
|
91
|
+
if (tabbar) {
|
|
92
|
+
for (const title of tabbar.titles) {
|
|
93
|
+
if (title.owner !== newPreviewWidget && title.owner instanceof EditorPreviewWidget && title.owner.isPreview) {
|
|
94
|
+
title.owner.dispose();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected override tryGetPendingWidget(uri: URI, options?: EditorOpenerOptions): MaybePromise<EditorWidget> | undefined {
|
|
102
|
+
return super.tryGetPendingWidget(uri, { ...options, preview: true }) ?? super.tryGetPendingWidget(uri, { ...options, preview: false });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
protected override async getWidget(uri: URI, options?: EditorOpenerOptions): Promise<EditorWidget | undefined> {
|
|
106
|
+
return (await super.getWidget(uri, { ...options, preview: true })) ?? super.getWidget(uri, { ...options, preview: false });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
protected override async getOrCreateWidget(uri: URI, options?: EditorOpenerOptions): Promise<EditorWidget> {
|
|
110
|
+
return this.tryGetPendingWidget(uri, options) ?? super.getOrCreateWidget(uri, options);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
protected override createWidgetOptions(uri: URI, options?: EditorOpenerOptions): EditorPreviewOptions {
|
|
114
|
+
const navigatableOptions = super.createWidgetOptions(uri, options) as EditorPreviewOptions;
|
|
115
|
+
navigatableOptions.preview = !!(options?.preview && this.preferences['editor.enablePreview']);
|
|
116
|
+
return navigatableOptions;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected convertEditorOnDoubleClick(event: Event): void {
|
|
120
|
+
const widget = this.shell.findTargetedWidget(event);
|
|
121
|
+
if (widget instanceof EditorPreviewWidget && widget.isPreview) {
|
|
122
|
+
widget.convertToNonPreview();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|