@theia/outline-view 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.
Files changed (30) hide show
  1. package/LICENSE +641 -641
  2. package/README.md +30 -30
  3. package/lib/browser/index.d.ts +2 -2
  4. package/lib/browser/index.js +29 -29
  5. package/lib/browser/outline-breadcrumbs-contribution.d.ts +57 -57
  6. package/lib/browser/outline-breadcrumbs-contribution.js +222 -222
  7. package/lib/browser/outline-decorator-service.d.ts +13 -13
  8. package/lib/browser/outline-decorator-service.js +53 -53
  9. package/lib/browser/outline-view-contribution.d.ts +31 -31
  10. package/lib/browser/outline-view-contribution.js +108 -108
  11. package/lib/browser/outline-view-frontend-module.d.ts +4 -4
  12. package/lib/browser/outline-view-frontend-module.js +68 -68
  13. package/lib/browser/outline-view-service.d.ts +26 -26
  14. package/lib/browser/outline-view-service.js +89 -89
  15. package/lib/browser/outline-view-tree-model.d.ts +17 -17
  16. package/lib/browser/outline-view-tree-model.js +59 -59
  17. package/lib/browser/outline-view-widget.d.ts +73 -73
  18. package/lib/browser/outline-view-widget.js +180 -180
  19. package/lib/package.spec.js +25 -25
  20. package/package.json +4 -4
  21. package/src/browser/index.ts +18 -18
  22. package/src/browser/outline-breadcrumbs-contribution.tsx +229 -229
  23. package/src/browser/outline-decorator-service.ts +36 -36
  24. package/src/browser/outline-view-contribution.ts +104 -104
  25. package/src/browser/outline-view-frontend-module.ts +84 -84
  26. package/src/browser/outline-view-service.ts +82 -82
  27. package/src/browser/outline-view-tree-model.ts +52 -52
  28. package/src/browser/outline-view-widget.tsx +203 -203
  29. package/src/browser/styles/index.css +24 -24
  30. package/src/package.spec.ts +28 -28
@@ -1,104 +1,104 @@
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
- import { injectable } from '@theia/core/shared/inversify';
18
- import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
19
- import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser/frontend-application';
20
- import { Command, CommandRegistry } from '@theia/core/lib/common/command';
21
- import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
22
- import { codicon, Widget } from '@theia/core/lib/browser/widgets';
23
- import { OutlineViewWidget } from './outline-view-widget';
24
- import { CompositeTreeNode } from '@theia/core/lib/browser/tree';
25
- import { OS } from '@theia/core/lib/common/os';
26
- import { nls } from '@theia/core/lib/common/nls';
27
-
28
- export const OUTLINE_WIDGET_FACTORY_ID = 'outline-view';
29
-
30
- /**
31
- * Collection of `outline-view` commands.
32
- */
33
- export namespace OutlineViewCommands {
34
- /**
35
- * Command which collapses all nodes
36
- * from the `outline-view` tree.
37
- */
38
- export const COLLAPSE_ALL: Command = {
39
- id: 'outlineView.collapse.all',
40
- iconClass: codicon('collapse-all')
41
- };
42
- }
43
-
44
- @injectable()
45
- export class OutlineViewContribution extends AbstractViewContribution<OutlineViewWidget> implements FrontendApplicationContribution, TabBarToolbarContribution {
46
-
47
- constructor() {
48
- super({
49
- widgetId: OUTLINE_WIDGET_FACTORY_ID,
50
- widgetName: OutlineViewWidget.LABEL,
51
- defaultWidgetOptions: {
52
- area: 'right',
53
- rank: 500
54
- },
55
- toggleCommandId: 'outlineView:toggle',
56
- toggleKeybinding: OS.type() !== OS.Type.Linux
57
- ? 'ctrlcmd+shift+i'
58
- : undefined
59
- });
60
- }
61
-
62
- async initializeLayout(app: FrontendApplication): Promise<void> {
63
- await this.openView();
64
- }
65
-
66
- override registerCommands(commands: CommandRegistry): void {
67
- super.registerCommands(commands);
68
- commands.registerCommand(OutlineViewCommands.COLLAPSE_ALL, {
69
- isEnabled: widget => this.withWidget(widget, () => true),
70
- isVisible: widget => this.withWidget(widget, () => true),
71
- execute: () => this.collapseAllItems()
72
- });
73
- }
74
-
75
- registerToolbarItems(toolbar: TabBarToolbarRegistry): void {
76
- toolbar.registerItem({
77
- id: OutlineViewCommands.COLLAPSE_ALL.id,
78
- command: OutlineViewCommands.COLLAPSE_ALL.id,
79
- tooltip: nls.localizeByDefault('Collapse All'),
80
- priority: 0
81
- });
82
- }
83
-
84
- /**
85
- * Collapse all nodes in the outline view tree.
86
- */
87
- protected async collapseAllItems(): Promise<void> {
88
- const { model } = await this.widget;
89
- const root = model.root;
90
- if (CompositeTreeNode.is(root)) {
91
- model.collapseAll(root);
92
- }
93
- }
94
-
95
- /**
96
- * Determine if the current widget is the `outline-view`.
97
- */
98
- protected withWidget<T>(widget: Widget | undefined = this.tryGetWidget(), cb: (widget: OutlineViewWidget) => T): T | false {
99
- if (widget instanceof OutlineViewWidget && widget.id === OUTLINE_WIDGET_FACTORY_ID) {
100
- return cb(widget);
101
- }
102
- return false;
103
- }
104
- }
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
+ import { injectable } from '@theia/core/shared/inversify';
18
+ import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
19
+ import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser/frontend-application';
20
+ import { Command, CommandRegistry } from '@theia/core/lib/common/command';
21
+ import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
22
+ import { codicon, Widget } from '@theia/core/lib/browser/widgets';
23
+ import { OutlineViewWidget } from './outline-view-widget';
24
+ import { CompositeTreeNode } from '@theia/core/lib/browser/tree';
25
+ import { OS } from '@theia/core/lib/common/os';
26
+ import { nls } from '@theia/core/lib/common/nls';
27
+
28
+ export const OUTLINE_WIDGET_FACTORY_ID = 'outline-view';
29
+
30
+ /**
31
+ * Collection of `outline-view` commands.
32
+ */
33
+ export namespace OutlineViewCommands {
34
+ /**
35
+ * Command which collapses all nodes
36
+ * from the `outline-view` tree.
37
+ */
38
+ export const COLLAPSE_ALL: Command = {
39
+ id: 'outlineView.collapse.all',
40
+ iconClass: codicon('collapse-all')
41
+ };
42
+ }
43
+
44
+ @injectable()
45
+ export class OutlineViewContribution extends AbstractViewContribution<OutlineViewWidget> implements FrontendApplicationContribution, TabBarToolbarContribution {
46
+
47
+ constructor() {
48
+ super({
49
+ widgetId: OUTLINE_WIDGET_FACTORY_ID,
50
+ widgetName: OutlineViewWidget.LABEL,
51
+ defaultWidgetOptions: {
52
+ area: 'right',
53
+ rank: 500
54
+ },
55
+ toggleCommandId: 'outlineView:toggle',
56
+ toggleKeybinding: OS.type() !== OS.Type.Linux
57
+ ? 'ctrlcmd+shift+i'
58
+ : undefined
59
+ });
60
+ }
61
+
62
+ async initializeLayout(app: FrontendApplication): Promise<void> {
63
+ await this.openView();
64
+ }
65
+
66
+ override registerCommands(commands: CommandRegistry): void {
67
+ super.registerCommands(commands);
68
+ commands.registerCommand(OutlineViewCommands.COLLAPSE_ALL, {
69
+ isEnabled: widget => this.withWidget(widget, () => true),
70
+ isVisible: widget => this.withWidget(widget, () => true),
71
+ execute: () => this.collapseAllItems()
72
+ });
73
+ }
74
+
75
+ registerToolbarItems(toolbar: TabBarToolbarRegistry): void {
76
+ toolbar.registerItem({
77
+ id: OutlineViewCommands.COLLAPSE_ALL.id,
78
+ command: OutlineViewCommands.COLLAPSE_ALL.id,
79
+ tooltip: nls.localizeByDefault('Collapse All'),
80
+ priority: 0
81
+ });
82
+ }
83
+
84
+ /**
85
+ * Collapse all nodes in the outline view tree.
86
+ */
87
+ protected async collapseAllItems(): Promise<void> {
88
+ const { model } = await this.widget;
89
+ const root = model.root;
90
+ if (CompositeTreeNode.is(root)) {
91
+ model.collapseAll(root);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Determine if the current widget is the `outline-view`.
97
+ */
98
+ protected withWidget<T>(widget: Widget | undefined = this.tryGetWidget(), cb: (widget: OutlineViewWidget) => T): T | false {
99
+ if (widget instanceof OutlineViewWidget && widget.id === OUTLINE_WIDGET_FACTORY_ID) {
100
+ return cb(widget);
101
+ }
102
+ return false;
103
+ }
104
+ }
@@ -1,84 +1,84 @@
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
- import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
18
- import { OutlineViewService } from './outline-view-service';
19
- import { OutlineViewContribution } from './outline-view-contribution';
20
- import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
21
- import {
22
- FrontendApplicationContribution,
23
- createTreeContainer,
24
- bindViewContribution,
25
- TreeProps,
26
- defaultTreeProps,
27
- BreadcrumbsContribution
28
- } from '@theia/core/lib/browser';
29
- import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
30
- import { OutlineViewWidgetFactory, OutlineViewWidget } from './outline-view-widget';
31
- import '../../src/browser/styles/index.css';
32
- import { bindContributionProvider } from '@theia/core/lib/common/contribution-provider';
33
- import { OutlineDecoratorService, OutlineTreeDecorator } from './outline-decorator-service';
34
- import { OutlineViewTreeModel } from './outline-view-tree-model';
35
- import { BreadcrumbPopupOutlineView, BreadcrumbPopupOutlineViewFactory, OutlineBreadcrumbsContribution } from './outline-breadcrumbs-contribution';
36
-
37
- export default new ContainerModule(bind => {
38
- bind(OutlineViewWidgetFactory).toFactory(ctx =>
39
- () => createOutlineViewWidget(ctx.container)
40
- );
41
-
42
- bind(BreadcrumbPopupOutlineViewFactory).toFactory(({ container }) => () => {
43
- const child = createOutlineViewWidgetContainer(container);
44
- child.rebind(OutlineViewWidget).to(BreadcrumbPopupOutlineView);
45
- child.rebind(TreeProps).toConstantValue({ ...defaultTreeProps, expandOnlyOnExpansionToggleClick: true, search: false, virtualized: false });
46
- return child.get(OutlineViewWidget);
47
- });
48
-
49
- bind(OutlineViewService).toSelf().inSingletonScope();
50
- bind(WidgetFactory).toService(OutlineViewService);
51
-
52
- bindViewContribution(bind, OutlineViewContribution);
53
- bind(FrontendApplicationContribution).toService(OutlineViewContribution);
54
- bind(TabBarToolbarContribution).toService(OutlineViewContribution);
55
-
56
- bind(OutlineBreadcrumbsContribution).toSelf().inSingletonScope();
57
- bind(BreadcrumbsContribution).toService(OutlineBreadcrumbsContribution);
58
- });
59
-
60
- function createOutlineViewWidgetContainer(parent: interfaces.Container): interfaces.Container {
61
- const child = createTreeContainer(parent, {
62
- props: { expandOnlyOnExpansionToggleClick: true, search: true },
63
- widget: OutlineViewWidget,
64
- model: OutlineViewTreeModel,
65
- decoratorService: OutlineDecoratorService,
66
- });
67
- bindContributionProvider(child, OutlineTreeDecorator);
68
- return child;
69
- }
70
-
71
- /**
72
- * Create an `OutlineViewWidget`.
73
- * - The creation of the `OutlineViewWidget` includes:
74
- * - The creation of the tree widget itself with it's own customized props.
75
- * - The binding of necessary components into the container.
76
- * @param parent the Inversify container.
77
- *
78
- * @returns the `OutlineViewWidget`.
79
- */
80
- function createOutlineViewWidget(parent: interfaces.Container): OutlineViewWidget {
81
- const child = createOutlineViewWidgetContainer(parent);
82
-
83
- return child.get(OutlineViewWidget);
84
- }
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
+ import { ContainerModule, interfaces } from '@theia/core/shared/inversify';
18
+ import { OutlineViewService } from './outline-view-service';
19
+ import { OutlineViewContribution } from './outline-view-contribution';
20
+ import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
21
+ import {
22
+ FrontendApplicationContribution,
23
+ createTreeContainer,
24
+ bindViewContribution,
25
+ TreeProps,
26
+ defaultTreeProps,
27
+ BreadcrumbsContribution
28
+ } from '@theia/core/lib/browser';
29
+ import { TabBarToolbarContribution } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
30
+ import { OutlineViewWidgetFactory, OutlineViewWidget } from './outline-view-widget';
31
+ import '../../src/browser/styles/index.css';
32
+ import { bindContributionProvider } from '@theia/core/lib/common/contribution-provider';
33
+ import { OutlineDecoratorService, OutlineTreeDecorator } from './outline-decorator-service';
34
+ import { OutlineViewTreeModel } from './outline-view-tree-model';
35
+ import { BreadcrumbPopupOutlineView, BreadcrumbPopupOutlineViewFactory, OutlineBreadcrumbsContribution } from './outline-breadcrumbs-contribution';
36
+
37
+ export default new ContainerModule(bind => {
38
+ bind(OutlineViewWidgetFactory).toFactory(ctx =>
39
+ () => createOutlineViewWidget(ctx.container)
40
+ );
41
+
42
+ bind(BreadcrumbPopupOutlineViewFactory).toFactory(({ container }) => () => {
43
+ const child = createOutlineViewWidgetContainer(container);
44
+ child.rebind(OutlineViewWidget).to(BreadcrumbPopupOutlineView);
45
+ child.rebind(TreeProps).toConstantValue({ ...defaultTreeProps, expandOnlyOnExpansionToggleClick: true, search: false, virtualized: false });
46
+ return child.get(OutlineViewWidget);
47
+ });
48
+
49
+ bind(OutlineViewService).toSelf().inSingletonScope();
50
+ bind(WidgetFactory).toService(OutlineViewService);
51
+
52
+ bindViewContribution(bind, OutlineViewContribution);
53
+ bind(FrontendApplicationContribution).toService(OutlineViewContribution);
54
+ bind(TabBarToolbarContribution).toService(OutlineViewContribution);
55
+
56
+ bind(OutlineBreadcrumbsContribution).toSelf().inSingletonScope();
57
+ bind(BreadcrumbsContribution).toService(OutlineBreadcrumbsContribution);
58
+ });
59
+
60
+ function createOutlineViewWidgetContainer(parent: interfaces.Container): interfaces.Container {
61
+ const child = createTreeContainer(parent, {
62
+ props: { expandOnlyOnExpansionToggleClick: true, search: true },
63
+ widget: OutlineViewWidget,
64
+ model: OutlineViewTreeModel,
65
+ decoratorService: OutlineDecoratorService,
66
+ });
67
+ bindContributionProvider(child, OutlineTreeDecorator);
68
+ return child;
69
+ }
70
+
71
+ /**
72
+ * Create an `OutlineViewWidget`.
73
+ * - The creation of the `OutlineViewWidget` includes:
74
+ * - The creation of the tree widget itself with it's own customized props.
75
+ * - The binding of necessary components into the container.
76
+ * @param parent the Inversify container.
77
+ *
78
+ * @returns the `OutlineViewWidget`.
79
+ */
80
+ function createOutlineViewWidget(parent: interfaces.Container): OutlineViewWidget {
81
+ const child = createOutlineViewWidgetContainer(parent);
82
+
83
+ return child.get(OutlineViewWidget);
84
+ }
@@ -1,82 +1,82 @@
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
- import { injectable, inject } from '@theia/core/shared/inversify';
18
- import { Event, Emitter, DisposableCollection } from '@theia/core';
19
- import { WidgetFactory } from '@theia/core/lib/browser';
20
- import { OutlineViewWidget, OutlineViewWidgetFactory, OutlineSymbolInformationNode } from './outline-view-widget';
21
- import { Widget } from '@theia/core/shared/@phosphor/widgets';
22
-
23
- @injectable()
24
- export class OutlineViewService implements WidgetFactory {
25
-
26
- id = 'outline-view';
27
-
28
- protected widget?: OutlineViewWidget;
29
- protected readonly onDidChangeOutlineEmitter = new Emitter<OutlineSymbolInformationNode[]>();
30
- protected readonly onDidChangeOpenStateEmitter = new Emitter<boolean>();
31
- protected readonly onDidSelectEmitter = new Emitter<OutlineSymbolInformationNode>();
32
- protected readonly onDidOpenEmitter = new Emitter<OutlineSymbolInformationNode>();
33
-
34
- constructor(@inject(OutlineViewWidgetFactory) protected factory: OutlineViewWidgetFactory) { }
35
-
36
- get onDidSelect(): Event<OutlineSymbolInformationNode> {
37
- return this.onDidSelectEmitter.event;
38
- }
39
-
40
- get onDidOpen(): Event<OutlineSymbolInformationNode> {
41
- return this.onDidOpenEmitter.event;
42
- }
43
-
44
- get onDidChangeOutline(): Event<OutlineSymbolInformationNode[]> {
45
- return this.onDidChangeOutlineEmitter.event;
46
- }
47
-
48
- get onDidChangeOpenState(): Event<boolean> {
49
- return this.onDidChangeOpenStateEmitter.event;
50
- }
51
-
52
- get open(): boolean {
53
- return this.widget !== undefined && this.widget.isVisible;
54
- }
55
-
56
- /**
57
- * Publish the collection of outline view symbols.
58
- * - Publishing includes setting the `OutlineViewWidget` tree with symbol information.
59
- * @param roots the list of outline symbol information nodes.
60
- */
61
- publish(roots: OutlineSymbolInformationNode[]): void {
62
- if (this.widget) {
63
- this.widget.setOutlineTree(roots);
64
- }
65
- // onDidChangeOutline needs to be fired even when the outline view widget is closed
66
- // in order to update breadcrumbs.
67
- this.onDidChangeOutlineEmitter.fire(roots);
68
- }
69
-
70
- createWidget(): Promise<Widget> {
71
- this.widget = this.factory();
72
- const disposables = new DisposableCollection();
73
- disposables.push(this.widget.onDidChangeOpenStateEmitter.event(open => this.onDidChangeOpenStateEmitter.fire(open)));
74
- disposables.push(this.widget.model.onOpenNode(node => this.onDidOpenEmitter.fire(node as OutlineSymbolInformationNode)));
75
- disposables.push(this.widget.model.onSelectionChanged(selection => this.onDidSelectEmitter.fire(selection[0] as OutlineSymbolInformationNode)));
76
- this.widget.disposed.connect(() => {
77
- this.widget = undefined;
78
- disposables.dispose();
79
- });
80
- return Promise.resolve(this.widget);
81
- }
82
- }
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
+ import { injectable, inject } from '@theia/core/shared/inversify';
18
+ import { Event, Emitter, DisposableCollection } from '@theia/core';
19
+ import { WidgetFactory } from '@theia/core/lib/browser';
20
+ import { OutlineViewWidget, OutlineViewWidgetFactory, OutlineSymbolInformationNode } from './outline-view-widget';
21
+ import { Widget } from '@theia/core/shared/@phosphor/widgets';
22
+
23
+ @injectable()
24
+ export class OutlineViewService implements WidgetFactory {
25
+
26
+ id = 'outline-view';
27
+
28
+ protected widget?: OutlineViewWidget;
29
+ protected readonly onDidChangeOutlineEmitter = new Emitter<OutlineSymbolInformationNode[]>();
30
+ protected readonly onDidChangeOpenStateEmitter = new Emitter<boolean>();
31
+ protected readonly onDidSelectEmitter = new Emitter<OutlineSymbolInformationNode>();
32
+ protected readonly onDidOpenEmitter = new Emitter<OutlineSymbolInformationNode>();
33
+
34
+ constructor(@inject(OutlineViewWidgetFactory) protected factory: OutlineViewWidgetFactory) { }
35
+
36
+ get onDidSelect(): Event<OutlineSymbolInformationNode> {
37
+ return this.onDidSelectEmitter.event;
38
+ }
39
+
40
+ get onDidOpen(): Event<OutlineSymbolInformationNode> {
41
+ return this.onDidOpenEmitter.event;
42
+ }
43
+
44
+ get onDidChangeOutline(): Event<OutlineSymbolInformationNode[]> {
45
+ return this.onDidChangeOutlineEmitter.event;
46
+ }
47
+
48
+ get onDidChangeOpenState(): Event<boolean> {
49
+ return this.onDidChangeOpenStateEmitter.event;
50
+ }
51
+
52
+ get open(): boolean {
53
+ return this.widget !== undefined && this.widget.isVisible;
54
+ }
55
+
56
+ /**
57
+ * Publish the collection of outline view symbols.
58
+ * - Publishing includes setting the `OutlineViewWidget` tree with symbol information.
59
+ * @param roots the list of outline symbol information nodes.
60
+ */
61
+ publish(roots: OutlineSymbolInformationNode[]): void {
62
+ if (this.widget) {
63
+ this.widget.setOutlineTree(roots);
64
+ }
65
+ // onDidChangeOutline needs to be fired even when the outline view widget is closed
66
+ // in order to update breadcrumbs.
67
+ this.onDidChangeOutlineEmitter.fire(roots);
68
+ }
69
+
70
+ createWidget(): Promise<Widget> {
71
+ this.widget = this.factory();
72
+ const disposables = new DisposableCollection();
73
+ disposables.push(this.widget.onDidChangeOpenStateEmitter.event(open => this.onDidChangeOpenStateEmitter.fire(open)));
74
+ disposables.push(this.widget.model.onOpenNode(node => this.onDidOpenEmitter.fire(node as OutlineSymbolInformationNode)));
75
+ disposables.push(this.widget.model.onSelectionChanged(selection => this.onDidSelectEmitter.fire(selection[0] as OutlineSymbolInformationNode)));
76
+ this.widget.disposed.connect(() => {
77
+ this.widget = undefined;
78
+ disposables.dispose();
79
+ });
80
+ return Promise.resolve(this.widget);
81
+ }
82
+ }
@@ -1,52 +1,52 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2019 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 } from '@theia/core/shared/inversify';
18
- import { CompositeTreeNode, TreeModelImpl, ExpandableTreeNode, TreeNode } from '@theia/core/lib/browser';
19
-
20
- @injectable()
21
- export class OutlineViewTreeModel extends TreeModelImpl {
22
-
23
- /**
24
- * Handle the expansion of the tree node.
25
- * - The method is a no-op in order to preserve focus on the editor
26
- * after attempting to perform a `collapse-all`.
27
- * @param node the expandable tree node.
28
- */
29
- protected override handleExpansion(node: Readonly<ExpandableTreeNode>): void {
30
- // no-op
31
- }
32
-
33
- override async collapseAll(raw?: Readonly<CompositeTreeNode>): Promise<boolean> {
34
- const node = raw || this.getFocusedNode();
35
- if (CompositeTreeNode.is(node)) {
36
- return this.expansionService.collapseAll(node);
37
- }
38
- return false;
39
- }
40
-
41
- /**
42
- * The default behavior of `openNode` calls `doOpenNode` which by default
43
- * toggles the expansion of the node. Overriding to prevent expansion, but
44
- * allow for the `onOpenNode` event to still fire on a double-click event.
45
- */
46
- override openNode(raw?: TreeNode | undefined): void {
47
- const node = raw || this.getFocusedNode();
48
- if (node) {
49
- this.onOpenNodeEmitter.fire(node);
50
- }
51
- }
52
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2019 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 } from '@theia/core/shared/inversify';
18
+ import { CompositeTreeNode, TreeModelImpl, ExpandableTreeNode, TreeNode } from '@theia/core/lib/browser';
19
+
20
+ @injectable()
21
+ export class OutlineViewTreeModel extends TreeModelImpl {
22
+
23
+ /**
24
+ * Handle the expansion of the tree node.
25
+ * - The method is a no-op in order to preserve focus on the editor
26
+ * after attempting to perform a `collapse-all`.
27
+ * @param node the expandable tree node.
28
+ */
29
+ protected override handleExpansion(node: Readonly<ExpandableTreeNode>): void {
30
+ // no-op
31
+ }
32
+
33
+ override async collapseAll(raw?: Readonly<CompositeTreeNode>): Promise<boolean> {
34
+ const node = raw || this.getFocusedNode();
35
+ if (CompositeTreeNode.is(node)) {
36
+ return this.expansionService.collapseAll(node);
37
+ }
38
+ return false;
39
+ }
40
+
41
+ /**
42
+ * The default behavior of `openNode` calls `doOpenNode` which by default
43
+ * toggles the expansion of the node. Overriding to prevent expansion, but
44
+ * allow for the `onOpenNode` event to still fire on a double-click event.
45
+ */
46
+ override openNode(raw?: TreeNode | undefined): void {
47
+ const node = raw || this.getFocusedNode();
48
+ if (node) {
49
+ this.onOpenNodeEmitter.fire(node);
50
+ }
51
+ }
52
+ }