@theia/notebook 1.53.0-next.5 → 1.53.0-next.55
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/README.md +30 -30
- package/lib/browser/contributions/notebook-actions-contribution.d.ts +1 -0
- package/lib/browser/contributions/notebook-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-actions-contribution.js +31 -5
- package/lib/browser/contributions/notebook-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts +2 -0
- package/lib/browser/contributions/notebook-cell-actions-contribution.d.ts.map +1 -1
- package/lib/browser/contributions/notebook-cell-actions-contribution.js +41 -7
- package/lib/browser/contributions/notebook-cell-actions-contribution.js.map +1 -1
- package/lib/browser/contributions/notebook-status-bar-contribution.d.ts +14 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.d.ts.map +1 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.js +75 -0
- package/lib/browser/contributions/notebook-status-bar-contribution.js.map +1 -0
- package/lib/browser/notebook-editor-widget.d.ts.map +1 -1
- package/lib/browser/notebook-editor-widget.js +3 -5
- package/lib/browser/notebook-editor-widget.js.map +1 -1
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
- package/lib/browser/notebook-frontend-module.js +3 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -1
- package/lib/browser/notebook-open-handler.d.ts +3 -2
- package/lib/browser/notebook-open-handler.d.ts.map +1 -1
- package/lib/browser/notebook-open-handler.js +12 -5
- package/lib/browser/notebook-open-handler.js.map +1 -1
- package/lib/browser/view/notebook-cell-editor.d.ts +1 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-editor.js +30 -16
- package/lib/browser/view/notebook-cell-editor.js.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.d.ts +6 -4
- package/lib/browser/view/notebook-cell-list-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-list-view.js +20 -13
- package/lib/browser/view/notebook-cell-list-view.js.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.d.ts +3 -0
- package/lib/browser/view-model/notebook-cell-model.d.ts.map +1 -1
- package/lib/browser/view-model/notebook-cell-model.js +5 -0
- package/lib/browser/view-model/notebook-cell-model.js.map +1 -1
- package/package.json +8 -8
- package/src/browser/contributions/cell-operations.ts +44 -44
- package/src/browser/contributions/notebook-actions-contribution.ts +379 -350
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -487
- package/src/browser/contributions/notebook-color-contribution.ts +268 -268
- package/src/browser/contributions/notebook-context-keys.ts +113 -113
- package/src/browser/contributions/notebook-label-provider-contribution.ts +85 -85
- package/src/browser/contributions/notebook-outline-contribution.ts +114 -114
- package/src/browser/contributions/notebook-output-action-contribution.ts +82 -82
- package/src/browser/contributions/notebook-preferences.ts +92 -92
- package/src/browser/contributions/notebook-status-bar-contribution.ts +77 -0
- package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
- package/src/browser/index.ts +27 -27
- package/src/browser/notebook-cell-resource-resolver.ts +130 -130
- package/src/browser/notebook-editor-widget-factory.ts +82 -82
- package/src/browser/notebook-editor-widget.tsx +330 -331
- package/src/browser/notebook-frontend-module.ts +119 -115
- package/src/browser/notebook-open-handler.ts +120 -114
- package/src/browser/notebook-output-utils.ts +119 -119
- package/src/browser/notebook-renderer-registry.ts +85 -85
- package/src/browser/notebook-type-registry.ts +54 -54
- package/src/browser/notebook-types.ts +186 -186
- package/src/browser/renderers/cell-output-webview.ts +33 -33
- package/src/browser/service/notebook-clipboard-service.ts +43 -43
- package/src/browser/service/notebook-context-manager.ts +162 -162
- package/src/browser/service/notebook-editor-widget-service.ts +101 -101
- package/src/browser/service/notebook-execution-service.ts +139 -139
- package/src/browser/service/notebook-execution-state-service.ts +311 -311
- package/src/browser/service/notebook-kernel-history-service.ts +124 -124
- package/src/browser/service/notebook-kernel-quick-pick-service.ts +479 -479
- package/src/browser/service/notebook-kernel-service.ts +357 -357
- package/src/browser/service/notebook-model-resolver-service.ts +160 -160
- package/src/browser/service/notebook-monaco-text-model-service.ts +48 -48
- package/src/browser/service/notebook-options.ts +155 -155
- package/src/browser/service/notebook-renderer-messaging-service.ts +121 -121
- package/src/browser/service/notebook-service.ts +215 -215
- package/src/browser/style/index.css +483 -471
- package/src/browser/view/notebook-cell-editor.tsx +263 -247
- package/src/browser/view/notebook-cell-list-view.tsx +279 -262
- package/src/browser/view/notebook-cell-toolbar-factory.tsx +102 -102
- package/src/browser/view/notebook-cell-toolbar.tsx +74 -74
- package/src/browser/view/notebook-code-cell-view.tsx +350 -350
- package/src/browser/view/notebook-find-widget.tsx +335 -335
- package/src/browser/view/notebook-main-toolbar.tsx +235 -235
- package/src/browser/view/notebook-markdown-cell-view.tsx +208 -208
- package/src/browser/view/notebook-viewport-service.ts +61 -61
- package/src/browser/view-model/notebook-cell-model.ts +473 -466
- package/src/browser/view-model/notebook-cell-output-model.ts +100 -100
- package/src/browser/view-model/notebook-model.ts +550 -550
- package/src/common/index.ts +18 -18
- package/src/common/notebook-common.ts +337 -337
- package/src/common/notebook-protocol.ts +35 -35
- package/src/common/notebook-range.ts +30 -30
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2023 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as React from '@theia/core/shared/react';
|
|
18
|
-
import { CommandRegistry, CompoundMenuNodeRole, MenuModelRegistry, MenuNode } from '@theia/core';
|
|
19
|
-
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
-
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
21
|
-
import { NotebookCellSidebar, NotebookCellToolbar } from './notebook-cell-toolbar';
|
|
22
|
-
import { ContextMenuRenderer } from '@theia/core/lib/browser';
|
|
23
|
-
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
24
|
-
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
25
|
-
|
|
26
|
-
export interface NotebookCellToolbarItem {
|
|
27
|
-
id: string;
|
|
28
|
-
icon?: string;
|
|
29
|
-
label?: string;
|
|
30
|
-
onClick: (e: React.MouseEvent) => void;
|
|
31
|
-
isVisible: () => boolean;
|
|
32
|
-
contextKeys?: Set<string>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface toolbarItemOptions {
|
|
36
|
-
contextMenuArgs?: () => unknown[];
|
|
37
|
-
commandArgs?: () => unknown[];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@injectable()
|
|
41
|
-
export class NotebookCellToolbarFactory {
|
|
42
|
-
|
|
43
|
-
@inject(MenuModelRegistry)
|
|
44
|
-
protected menuRegistry: MenuModelRegistry;
|
|
45
|
-
|
|
46
|
-
@inject(ContextKeyService)
|
|
47
|
-
protected contextKeyService: ContextKeyService;
|
|
48
|
-
|
|
49
|
-
@inject(ContextMenuRenderer)
|
|
50
|
-
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
|
51
|
-
|
|
52
|
-
@inject(CommandRegistry)
|
|
53
|
-
protected readonly commandRegistry: CommandRegistry;
|
|
54
|
-
|
|
55
|
-
@inject(NotebookContextManager)
|
|
56
|
-
protected readonly notebookContextManager: NotebookContextManager;
|
|
57
|
-
|
|
58
|
-
renderCellToolbar(menuPath: string[], cell: NotebookCellModel, itemOptions: toolbarItemOptions): React.ReactNode {
|
|
59
|
-
return <NotebookCellToolbar getMenuItems={() => this.getMenuItems(menuPath, cell, itemOptions)}
|
|
60
|
-
onContextKeysChanged={this.notebookContextManager.onDidChangeContext} />;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
renderSidebar(menuPath: string[], cell: NotebookCellModel, itemOptions: toolbarItemOptions): React.ReactNode {
|
|
64
|
-
return <NotebookCellSidebar getMenuItems={() => this.getMenuItems(menuPath, cell, itemOptions)}
|
|
65
|
-
onContextKeysChanged={this.notebookContextManager.onDidChangeContext} />;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private getMenuItems(menuItemPath: string[], cell: NotebookCellModel, itemOptions: toolbarItemOptions): NotebookCellToolbarItem[] {
|
|
69
|
-
const inlineItems: NotebookCellToolbarItem[] = [];
|
|
70
|
-
for (const menuNode of this.menuRegistry.getMenu(menuItemPath).children) {
|
|
71
|
-
if (!menuNode.when || this.notebookContextManager.getCellContext(cell.handle).match(menuNode.when, this.notebookContextManager.context)) {
|
|
72
|
-
if (menuNode.role === CompoundMenuNodeRole.Flat) {
|
|
73
|
-
inlineItems.push(...menuNode.children?.map(child => this.createToolbarItem(child, itemOptions)) ?? []);
|
|
74
|
-
} else {
|
|
75
|
-
inlineItems.push(this.createToolbarItem(menuNode, itemOptions));
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return inlineItems;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private createToolbarItem(menuNode: MenuNode, itemOptions: toolbarItemOptions): NotebookCellToolbarItem {
|
|
83
|
-
const menuPath = menuNode.role === CompoundMenuNodeRole.Submenu ? this.menuRegistry.getPath(menuNode) : undefined;
|
|
84
|
-
return {
|
|
85
|
-
id: menuNode.id,
|
|
86
|
-
icon: menuNode.icon,
|
|
87
|
-
label: menuNode.label,
|
|
88
|
-
onClick: menuPath ?
|
|
89
|
-
e => this.contextMenuRenderer.render(
|
|
90
|
-
{
|
|
91
|
-
anchor: e.nativeEvent,
|
|
92
|
-
menuPath,
|
|
93
|
-
includeAnchorArg: false,
|
|
94
|
-
args: itemOptions.contextMenuArgs?.(),
|
|
95
|
-
context: this.notebookContextManager.context
|
|
96
|
-
}) :
|
|
97
|
-
() => this.commandRegistry.executeCommand(menuNode.command!, ...(itemOptions.commandArgs?.() ?? [])),
|
|
98
|
-
isVisible: () => menuPath ? true : Boolean(this.commandRegistry.getVisibleHandler(menuNode.command!, ...(itemOptions.commandArgs?.() ?? []))),
|
|
99
|
-
contextKeys: menuNode.when ? this.contextKeyService.parseKeys(menuNode.when) : undefined
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2023 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as React from '@theia/core/shared/react';
|
|
18
|
+
import { CommandRegistry, CompoundMenuNodeRole, MenuModelRegistry, MenuNode } from '@theia/core';
|
|
19
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
+
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
21
|
+
import { NotebookCellSidebar, NotebookCellToolbar } from './notebook-cell-toolbar';
|
|
22
|
+
import { ContextMenuRenderer } from '@theia/core/lib/browser';
|
|
23
|
+
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
24
|
+
import { NotebookContextManager } from '../service/notebook-context-manager';
|
|
25
|
+
|
|
26
|
+
export interface NotebookCellToolbarItem {
|
|
27
|
+
id: string;
|
|
28
|
+
icon?: string;
|
|
29
|
+
label?: string;
|
|
30
|
+
onClick: (e: React.MouseEvent) => void;
|
|
31
|
+
isVisible: () => boolean;
|
|
32
|
+
contextKeys?: Set<string>
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface toolbarItemOptions {
|
|
36
|
+
contextMenuArgs?: () => unknown[];
|
|
37
|
+
commandArgs?: () => unknown[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@injectable()
|
|
41
|
+
export class NotebookCellToolbarFactory {
|
|
42
|
+
|
|
43
|
+
@inject(MenuModelRegistry)
|
|
44
|
+
protected menuRegistry: MenuModelRegistry;
|
|
45
|
+
|
|
46
|
+
@inject(ContextKeyService)
|
|
47
|
+
protected contextKeyService: ContextKeyService;
|
|
48
|
+
|
|
49
|
+
@inject(ContextMenuRenderer)
|
|
50
|
+
protected readonly contextMenuRenderer: ContextMenuRenderer;
|
|
51
|
+
|
|
52
|
+
@inject(CommandRegistry)
|
|
53
|
+
protected readonly commandRegistry: CommandRegistry;
|
|
54
|
+
|
|
55
|
+
@inject(NotebookContextManager)
|
|
56
|
+
protected readonly notebookContextManager: NotebookContextManager;
|
|
57
|
+
|
|
58
|
+
renderCellToolbar(menuPath: string[], cell: NotebookCellModel, itemOptions: toolbarItemOptions): React.ReactNode {
|
|
59
|
+
return <NotebookCellToolbar getMenuItems={() => this.getMenuItems(menuPath, cell, itemOptions)}
|
|
60
|
+
onContextKeysChanged={this.notebookContextManager.onDidChangeContext} />;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
renderSidebar(menuPath: string[], cell: NotebookCellModel, itemOptions: toolbarItemOptions): React.ReactNode {
|
|
64
|
+
return <NotebookCellSidebar getMenuItems={() => this.getMenuItems(menuPath, cell, itemOptions)}
|
|
65
|
+
onContextKeysChanged={this.notebookContextManager.onDidChangeContext} />;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private getMenuItems(menuItemPath: string[], cell: NotebookCellModel, itemOptions: toolbarItemOptions): NotebookCellToolbarItem[] {
|
|
69
|
+
const inlineItems: NotebookCellToolbarItem[] = [];
|
|
70
|
+
for (const menuNode of this.menuRegistry.getMenu(menuItemPath).children) {
|
|
71
|
+
if (!menuNode.when || this.notebookContextManager.getCellContext(cell.handle).match(menuNode.when, this.notebookContextManager.context)) {
|
|
72
|
+
if (menuNode.role === CompoundMenuNodeRole.Flat) {
|
|
73
|
+
inlineItems.push(...menuNode.children?.map(child => this.createToolbarItem(child, itemOptions)) ?? []);
|
|
74
|
+
} else {
|
|
75
|
+
inlineItems.push(this.createToolbarItem(menuNode, itemOptions));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return inlineItems;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private createToolbarItem(menuNode: MenuNode, itemOptions: toolbarItemOptions): NotebookCellToolbarItem {
|
|
83
|
+
const menuPath = menuNode.role === CompoundMenuNodeRole.Submenu ? this.menuRegistry.getPath(menuNode) : undefined;
|
|
84
|
+
return {
|
|
85
|
+
id: menuNode.id,
|
|
86
|
+
icon: menuNode.icon,
|
|
87
|
+
label: menuNode.label,
|
|
88
|
+
onClick: menuPath ?
|
|
89
|
+
e => this.contextMenuRenderer.render(
|
|
90
|
+
{
|
|
91
|
+
anchor: e.nativeEvent,
|
|
92
|
+
menuPath,
|
|
93
|
+
includeAnchorArg: false,
|
|
94
|
+
args: itemOptions.contextMenuArgs?.(),
|
|
95
|
+
context: this.notebookContextManager.context
|
|
96
|
+
}) :
|
|
97
|
+
() => this.commandRegistry.executeCommand(menuNode.command!, ...(itemOptions.commandArgs?.() ?? [])),
|
|
98
|
+
isVisible: () => menuPath ? true : Boolean(this.commandRegistry.getVisibleHandler(menuNode.command!, ...(itemOptions.commandArgs?.() ?? []))),
|
|
99
|
+
contextKeys: menuNode.when ? this.contextKeyService.parseKeys(menuNode.when) : undefined
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2023 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-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
import * as React from '@theia/core/shared/react';
|
|
17
|
-
import { ACTION_ITEM } from '@theia/core/lib/browser';
|
|
18
|
-
import { NotebookCellToolbarItem } from './notebook-cell-toolbar-factory';
|
|
19
|
-
import { DisposableCollection, Event } from '@theia/core';
|
|
20
|
-
import { ContextKeyChangeEvent } from '@theia/core/lib/browser/context-key-service';
|
|
21
|
-
|
|
22
|
-
export interface NotebookCellToolbarProps {
|
|
23
|
-
getMenuItems: () => NotebookCellToolbarItem[];
|
|
24
|
-
onContextKeysChanged: Event<ContextKeyChangeEvent>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface NotebookCellToolbarState {
|
|
28
|
-
inlineItems: NotebookCellToolbarItem[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
abstract class NotebookCellActionBar extends React.Component<NotebookCellToolbarProps, NotebookCellToolbarState> {
|
|
32
|
-
|
|
33
|
-
protected toDispose = new DisposableCollection();
|
|
34
|
-
|
|
35
|
-
constructor(props: NotebookCellToolbarProps) {
|
|
36
|
-
super(props);
|
|
37
|
-
this.toDispose.push(props.onContextKeysChanged(e => {
|
|
38
|
-
const menuItems = this.props.getMenuItems();
|
|
39
|
-
if (menuItems.some(item => item.contextKeys ? e.affects(item.contextKeys) : false)) {
|
|
40
|
-
this.setState({ inlineItems: menuItems });
|
|
41
|
-
}
|
|
42
|
-
}));
|
|
43
|
-
this.state = { inlineItems: this.props.getMenuItems() };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
override componentWillUnmount(): void {
|
|
47
|
-
this.toDispose.dispose();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
protected renderItem(item: NotebookCellToolbarItem): React.ReactNode {
|
|
51
|
-
return <div key={item.id} title={item.label} onClick={item.onClick} className={`${item.icon} ${ACTION_ITEM} theia-notebook-cell-toolbar-item`} />;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class NotebookCellToolbar extends NotebookCellActionBar {
|
|
57
|
-
|
|
58
|
-
override render(): React.ReactNode {
|
|
59
|
-
return <div className='theia-notebook-cell-toolbar'>
|
|
60
|
-
{this.state.inlineItems.filter(e => e.isVisible()).map(item => this.renderItem(item))}
|
|
61
|
-
</div>;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export class NotebookCellSidebar extends NotebookCellActionBar {
|
|
67
|
-
|
|
68
|
-
override render(): React.ReactNode {
|
|
69
|
-
return <div className='theia-notebook-cell-sidebar-toolbar'>
|
|
70
|
-
{this.state.inlineItems.filter(e => e.isVisible()).map(item => this.renderItem(item))}
|
|
71
|
-
</div>;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2023 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-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
import * as React from '@theia/core/shared/react';
|
|
17
|
+
import { ACTION_ITEM } from '@theia/core/lib/browser';
|
|
18
|
+
import { NotebookCellToolbarItem } from './notebook-cell-toolbar-factory';
|
|
19
|
+
import { DisposableCollection, Event } from '@theia/core';
|
|
20
|
+
import { ContextKeyChangeEvent } from '@theia/core/lib/browser/context-key-service';
|
|
21
|
+
|
|
22
|
+
export interface NotebookCellToolbarProps {
|
|
23
|
+
getMenuItems: () => NotebookCellToolbarItem[];
|
|
24
|
+
onContextKeysChanged: Event<ContextKeyChangeEvent>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface NotebookCellToolbarState {
|
|
28
|
+
inlineItems: NotebookCellToolbarItem[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
abstract class NotebookCellActionBar extends React.Component<NotebookCellToolbarProps, NotebookCellToolbarState> {
|
|
32
|
+
|
|
33
|
+
protected toDispose = new DisposableCollection();
|
|
34
|
+
|
|
35
|
+
constructor(props: NotebookCellToolbarProps) {
|
|
36
|
+
super(props);
|
|
37
|
+
this.toDispose.push(props.onContextKeysChanged(e => {
|
|
38
|
+
const menuItems = this.props.getMenuItems();
|
|
39
|
+
if (menuItems.some(item => item.contextKeys ? e.affects(item.contextKeys) : false)) {
|
|
40
|
+
this.setState({ inlineItems: menuItems });
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
this.state = { inlineItems: this.props.getMenuItems() };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
override componentWillUnmount(): void {
|
|
47
|
+
this.toDispose.dispose();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected renderItem(item: NotebookCellToolbarItem): React.ReactNode {
|
|
51
|
+
return <div key={item.id} title={item.label} onClick={item.onClick} className={`${item.icon} ${ACTION_ITEM} theia-notebook-cell-toolbar-item`} />;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class NotebookCellToolbar extends NotebookCellActionBar {
|
|
57
|
+
|
|
58
|
+
override render(): React.ReactNode {
|
|
59
|
+
return <div className='theia-notebook-cell-toolbar'>
|
|
60
|
+
{this.state.inlineItems.filter(e => e.isVisible()).map(item => this.renderItem(item))}
|
|
61
|
+
</div>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class NotebookCellSidebar extends NotebookCellActionBar {
|
|
67
|
+
|
|
68
|
+
override render(): React.ReactNode {
|
|
69
|
+
return <div className='theia-notebook-cell-sidebar-toolbar'>
|
|
70
|
+
{this.state.inlineItems.filter(e => e.isVisible()).map(item => this.renderItem(item))}
|
|
71
|
+
</div>;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|