@theia/notebook 1.53.0-next.55 → 1.53.0-next.64
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/index.d.ts +1 -0
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/notebook-frontend-module.d.ts.map +1 -1
- package/lib/browser/notebook-frontend-module.js +2 -0
- package/lib/browser/notebook-frontend-module.js.map +1 -1
- package/lib/browser/service/notebook-cell-editor-service.d.ts +16 -0
- package/lib/browser/service/notebook-cell-editor-service.d.ts.map +1 -0
- package/lib/browser/service/notebook-cell-editor-service.js +53 -0
- package/lib/browser/service/notebook-cell-editor-service.js.map +1 -0
- package/lib/browser/view/notebook-cell-editor.d.ts +2 -0
- package/lib/browser/view/notebook-cell-editor.d.ts.map +1 -1
- package/lib/browser/view/notebook-cell-editor.js +12 -1
- package/lib/browser/view/notebook-cell-editor.js.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.d.ts +2 -0
- package/lib/browser/view/notebook-code-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-code-cell-view.js +6 -1
- package/lib/browser/view/notebook-code-cell-view.js.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.d.ts +2 -0
- package/lib/browser/view/notebook-markdown-cell-view.d.ts.map +1 -1
- package/lib/browser/view/notebook-markdown-cell-view.js +8 -3
- package/lib/browser/view/notebook-markdown-cell-view.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/contributions/cell-operations.ts +44 -44
- package/src/browser/contributions/notebook-actions-contribution.ts +379 -379
- package/src/browser/contributions/notebook-cell-actions-contribution.ts +525 -525
- 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 -77
- package/src/browser/contributions/notebook-undo-redo-handler.ts +41 -41
- package/src/browser/index.ts +28 -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 -330
- package/src/browser/notebook-frontend-module.ts +121 -119
- package/src/browser/notebook-open-handler.ts +120 -120
- 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-cell-editor-service.ts +56 -0
- 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 +484 -483
- package/src/browser/view/notebook-cell-editor.tsx +276 -263
- package/src/browser/view/notebook-cell-list-view.tsx +279 -279
- 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 +355 -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 +215 -208
- package/src/browser/view/notebook-viewport-service.ts +61 -61
- package/src/browser/view-model/notebook-cell-model.ts +473 -473
- 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,162 +1,162 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2024 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 { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
import { ContextKeyChangeEvent, ContextKeyService, ContextMatcher, ScopedValueStore } from '@theia/core/lib/browser/context-key-service';
|
|
19
|
-
import { DisposableCollection, Emitter } from '@theia/core';
|
|
20
|
-
import { NotebookKernelService } from './notebook-kernel-service';
|
|
21
|
-
import {
|
|
22
|
-
NOTEBOOK_CELL_EDITABLE,
|
|
23
|
-
NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE,
|
|
24
|
-
NOTEBOOK_CELL_FOCUSED, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE,
|
|
25
|
-
NOTEBOOK_CELL_TYPE, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_KERNEL, NOTEBOOK_KERNEL_SELECTED,
|
|
26
|
-
NOTEBOOK_OUTPUT_INPUT_FOCUSED,
|
|
27
|
-
NOTEBOOK_VIEW_TYPE
|
|
28
|
-
} from '../contributions/notebook-context-keys';
|
|
29
|
-
import { NotebookEditorWidget } from '../notebook-editor-widget';
|
|
30
|
-
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
31
|
-
import { CellKind, NotebookCellsChangeType } from '../../common';
|
|
32
|
-
import { NotebookExecutionStateService } from './notebook-execution-state-service';
|
|
33
|
-
|
|
34
|
-
@injectable()
|
|
35
|
-
export class NotebookContextManager {
|
|
36
|
-
@inject(ContextKeyService) protected contextKeyService: ContextKeyService;
|
|
37
|
-
|
|
38
|
-
@inject(NotebookKernelService)
|
|
39
|
-
protected readonly notebookKernelService: NotebookKernelService;
|
|
40
|
-
|
|
41
|
-
@inject(NotebookExecutionStateService)
|
|
42
|
-
protected readonly executionStateService: NotebookExecutionStateService;
|
|
43
|
-
|
|
44
|
-
protected readonly toDispose = new DisposableCollection();
|
|
45
|
-
|
|
46
|
-
protected readonly onDidChangeContextEmitter = new Emitter<ContextKeyChangeEvent>();
|
|
47
|
-
readonly onDidChangeContext = this.onDidChangeContextEmitter.event;
|
|
48
|
-
|
|
49
|
-
protected _context?: HTMLElement;
|
|
50
|
-
|
|
51
|
-
scopedStore: ScopedValueStore;
|
|
52
|
-
|
|
53
|
-
get context(): HTMLElement | undefined {
|
|
54
|
-
return this._context;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
protected cellContexts: Map<number, Record<string, unknown>> = new Map();
|
|
58
|
-
|
|
59
|
-
init(widget: NotebookEditorWidget): void {
|
|
60
|
-
this._context = widget.node;
|
|
61
|
-
this.scopedStore = this.contextKeyService.createScoped(widget.node);
|
|
62
|
-
|
|
63
|
-
this.toDispose.dispose();
|
|
64
|
-
|
|
65
|
-
this.scopedStore.setContext(NOTEBOOK_VIEW_TYPE, widget?.notebookType);
|
|
66
|
-
|
|
67
|
-
// Kernel related keys
|
|
68
|
-
const kernel = widget?.model ? this.notebookKernelService.getSelectedNotebookKernel(widget.model) : undefined;
|
|
69
|
-
this.scopedStore.setContext(NOTEBOOK_KERNEL_SELECTED, !!kernel);
|
|
70
|
-
this.scopedStore.setContext(NOTEBOOK_KERNEL, kernel?.id);
|
|
71
|
-
this.toDispose.push(this.notebookKernelService.onDidChangeSelectedKernel(e => {
|
|
72
|
-
if (e.notebook.toString() === widget?.getResourceUri()?.toString()) {
|
|
73
|
-
this.scopedStore.setContext(NOTEBOOK_KERNEL_SELECTED, !!e.newKernel);
|
|
74
|
-
this.scopedStore.setContext(NOTEBOOK_KERNEL, e.newKernel);
|
|
75
|
-
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_KERNEL]));
|
|
76
|
-
}
|
|
77
|
-
}));
|
|
78
|
-
|
|
79
|
-
widget.model?.onDidChangeContent(events => {
|
|
80
|
-
if (events.some(e => e.kind === NotebookCellsChangeType.ModelChange || e.kind === NotebookCellsChangeType.Output)) {
|
|
81
|
-
this.scopedStore.setContext(NOTEBOOK_HAS_OUTPUTS, widget.model?.cells.some(cell => cell.outputs.length > 0));
|
|
82
|
-
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_HAS_OUTPUTS]));
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
this.scopedStore.setContext(NOTEBOOK_HAS_OUTPUTS, !!widget.model?.cells.find(cell => cell.outputs.length > 0));
|
|
87
|
-
|
|
88
|
-
// Cell Selection related keys
|
|
89
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_FOCUSED, !!widget.model?.selectedCell);
|
|
90
|
-
widget.model?.onDidChangeSelectedCell(e => {
|
|
91
|
-
this.selectedCellChanged(e.cell);
|
|
92
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_FOCUSED, !!e);
|
|
93
|
-
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_CELL_FOCUSED]));
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
this.toDispose.push(this.executionStateService.onDidChangeExecution(e => {
|
|
97
|
-
if (e.notebook.toString() === widget.model?.uri.toString()) {
|
|
98
|
-
this.setCellContext(e.cellHandle, NOTEBOOK_CELL_EXECUTING, !!e.changed);
|
|
99
|
-
this.setCellContext(e.cellHandle, NOTEBOOK_CELL_EXECUTION_STATE, e.changed?.state ?? 'idle');
|
|
100
|
-
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE]));
|
|
101
|
-
}
|
|
102
|
-
}));
|
|
103
|
-
|
|
104
|
-
widget.onDidChangeOutputInputFocus(focus => {
|
|
105
|
-
this.scopedStore.setContext(NOTEBOOK_OUTPUT_INPUT_FOCUSED, focus);
|
|
106
|
-
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_OUTPUT_INPUT_FOCUSED]));
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_VIEW_TYPE, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_KERNEL]));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
protected cellDisposables = new DisposableCollection();
|
|
113
|
-
|
|
114
|
-
selectedCellChanged(cell: NotebookCellModel | undefined): void {
|
|
115
|
-
this.cellDisposables.dispose();
|
|
116
|
-
|
|
117
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_TYPE, cell ? cell.cellKind === CellKind.Code ? 'code' : 'markdown' : undefined);
|
|
118
|
-
|
|
119
|
-
if (cell) {
|
|
120
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, cell.editing);
|
|
121
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_EDITABLE, cell.cellKind === CellKind.Markup && !cell.editing);
|
|
122
|
-
this.cellDisposables.push(cell.onDidRequestCellEditChange(cellEdit => {
|
|
123
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, cellEdit);
|
|
124
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_EDITABLE, cell.cellKind === CellKind.Markup && !cellEdit);
|
|
125
|
-
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_CELL_MARKDOWN_EDIT_MODE]));
|
|
126
|
-
}));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_CELL_TYPE]));
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
protected setCellContext(cellHandle: number, key: string, value: unknown): void {
|
|
134
|
-
let cellContext = this.cellContexts.get(cellHandle);
|
|
135
|
-
if (!cellContext) {
|
|
136
|
-
cellContext = {};
|
|
137
|
-
this.cellContexts.set(cellHandle, cellContext);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
cellContext[key] = value;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getCellContext(cellHandle: number): ContextMatcher {
|
|
144
|
-
return this.contextKeyService.createOverlay(Object.entries(this.cellContexts.get(cellHandle) ?? {}));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
changeCellFocus(focus: boolean): void {
|
|
148
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_FOCUSED, focus);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
changeCellListFocus(focus: boolean): void {
|
|
152
|
-
this.scopedStore.setContext(NOTEBOOK_CELL_LIST_FOCUSED, focus);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
createContextKeyChangedEvent(affectedKeys: string[]): ContextKeyChangeEvent {
|
|
156
|
-
return { affects: keys => affectedKeys.some(key => keys.has(key)) };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
dispose(): void {
|
|
160
|
-
this.toDispose.dispose();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2024 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 { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ContextKeyChangeEvent, ContextKeyService, ContextMatcher, ScopedValueStore } from '@theia/core/lib/browser/context-key-service';
|
|
19
|
+
import { DisposableCollection, Emitter } from '@theia/core';
|
|
20
|
+
import { NotebookKernelService } from './notebook-kernel-service';
|
|
21
|
+
import {
|
|
22
|
+
NOTEBOOK_CELL_EDITABLE,
|
|
23
|
+
NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE,
|
|
24
|
+
NOTEBOOK_CELL_FOCUSED, NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_MARKDOWN_EDIT_MODE,
|
|
25
|
+
NOTEBOOK_CELL_TYPE, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_KERNEL, NOTEBOOK_KERNEL_SELECTED,
|
|
26
|
+
NOTEBOOK_OUTPUT_INPUT_FOCUSED,
|
|
27
|
+
NOTEBOOK_VIEW_TYPE
|
|
28
|
+
} from '../contributions/notebook-context-keys';
|
|
29
|
+
import { NotebookEditorWidget } from '../notebook-editor-widget';
|
|
30
|
+
import { NotebookCellModel } from '../view-model/notebook-cell-model';
|
|
31
|
+
import { CellKind, NotebookCellsChangeType } from '../../common';
|
|
32
|
+
import { NotebookExecutionStateService } from './notebook-execution-state-service';
|
|
33
|
+
|
|
34
|
+
@injectable()
|
|
35
|
+
export class NotebookContextManager {
|
|
36
|
+
@inject(ContextKeyService) protected contextKeyService: ContextKeyService;
|
|
37
|
+
|
|
38
|
+
@inject(NotebookKernelService)
|
|
39
|
+
protected readonly notebookKernelService: NotebookKernelService;
|
|
40
|
+
|
|
41
|
+
@inject(NotebookExecutionStateService)
|
|
42
|
+
protected readonly executionStateService: NotebookExecutionStateService;
|
|
43
|
+
|
|
44
|
+
protected readonly toDispose = new DisposableCollection();
|
|
45
|
+
|
|
46
|
+
protected readonly onDidChangeContextEmitter = new Emitter<ContextKeyChangeEvent>();
|
|
47
|
+
readonly onDidChangeContext = this.onDidChangeContextEmitter.event;
|
|
48
|
+
|
|
49
|
+
protected _context?: HTMLElement;
|
|
50
|
+
|
|
51
|
+
scopedStore: ScopedValueStore;
|
|
52
|
+
|
|
53
|
+
get context(): HTMLElement | undefined {
|
|
54
|
+
return this._context;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected cellContexts: Map<number, Record<string, unknown>> = new Map();
|
|
58
|
+
|
|
59
|
+
init(widget: NotebookEditorWidget): void {
|
|
60
|
+
this._context = widget.node;
|
|
61
|
+
this.scopedStore = this.contextKeyService.createScoped(widget.node);
|
|
62
|
+
|
|
63
|
+
this.toDispose.dispose();
|
|
64
|
+
|
|
65
|
+
this.scopedStore.setContext(NOTEBOOK_VIEW_TYPE, widget?.notebookType);
|
|
66
|
+
|
|
67
|
+
// Kernel related keys
|
|
68
|
+
const kernel = widget?.model ? this.notebookKernelService.getSelectedNotebookKernel(widget.model) : undefined;
|
|
69
|
+
this.scopedStore.setContext(NOTEBOOK_KERNEL_SELECTED, !!kernel);
|
|
70
|
+
this.scopedStore.setContext(NOTEBOOK_KERNEL, kernel?.id);
|
|
71
|
+
this.toDispose.push(this.notebookKernelService.onDidChangeSelectedKernel(e => {
|
|
72
|
+
if (e.notebook.toString() === widget?.getResourceUri()?.toString()) {
|
|
73
|
+
this.scopedStore.setContext(NOTEBOOK_KERNEL_SELECTED, !!e.newKernel);
|
|
74
|
+
this.scopedStore.setContext(NOTEBOOK_KERNEL, e.newKernel);
|
|
75
|
+
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_KERNEL]));
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
|
|
79
|
+
widget.model?.onDidChangeContent(events => {
|
|
80
|
+
if (events.some(e => e.kind === NotebookCellsChangeType.ModelChange || e.kind === NotebookCellsChangeType.Output)) {
|
|
81
|
+
this.scopedStore.setContext(NOTEBOOK_HAS_OUTPUTS, widget.model?.cells.some(cell => cell.outputs.length > 0));
|
|
82
|
+
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_HAS_OUTPUTS]));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.scopedStore.setContext(NOTEBOOK_HAS_OUTPUTS, !!widget.model?.cells.find(cell => cell.outputs.length > 0));
|
|
87
|
+
|
|
88
|
+
// Cell Selection related keys
|
|
89
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_FOCUSED, !!widget.model?.selectedCell);
|
|
90
|
+
widget.model?.onDidChangeSelectedCell(e => {
|
|
91
|
+
this.selectedCellChanged(e.cell);
|
|
92
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_FOCUSED, !!e);
|
|
93
|
+
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_CELL_FOCUSED]));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.toDispose.push(this.executionStateService.onDidChangeExecution(e => {
|
|
97
|
+
if (e.notebook.toString() === widget.model?.uri.toString()) {
|
|
98
|
+
this.setCellContext(e.cellHandle, NOTEBOOK_CELL_EXECUTING, !!e.changed);
|
|
99
|
+
this.setCellContext(e.cellHandle, NOTEBOOK_CELL_EXECUTION_STATE, e.changed?.state ?? 'idle');
|
|
100
|
+
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_CELL_EXECUTING, NOTEBOOK_CELL_EXECUTION_STATE]));
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
widget.onDidChangeOutputInputFocus(focus => {
|
|
105
|
+
this.scopedStore.setContext(NOTEBOOK_OUTPUT_INPUT_FOCUSED, focus);
|
|
106
|
+
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_OUTPUT_INPUT_FOCUSED]));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_VIEW_TYPE, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_KERNEL]));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
protected cellDisposables = new DisposableCollection();
|
|
113
|
+
|
|
114
|
+
selectedCellChanged(cell: NotebookCellModel | undefined): void {
|
|
115
|
+
this.cellDisposables.dispose();
|
|
116
|
+
|
|
117
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_TYPE, cell ? cell.cellKind === CellKind.Code ? 'code' : 'markdown' : undefined);
|
|
118
|
+
|
|
119
|
+
if (cell) {
|
|
120
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, cell.editing);
|
|
121
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_EDITABLE, cell.cellKind === CellKind.Markup && !cell.editing);
|
|
122
|
+
this.cellDisposables.push(cell.onDidRequestCellEditChange(cellEdit => {
|
|
123
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_MARKDOWN_EDIT_MODE, cellEdit);
|
|
124
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_EDITABLE, cell.cellKind === CellKind.Markup && !cellEdit);
|
|
125
|
+
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_CELL_MARKDOWN_EDIT_MODE]));
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.onDidChangeContextEmitter.fire(this.createContextKeyChangedEvent([NOTEBOOK_CELL_TYPE]));
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
protected setCellContext(cellHandle: number, key: string, value: unknown): void {
|
|
134
|
+
let cellContext = this.cellContexts.get(cellHandle);
|
|
135
|
+
if (!cellContext) {
|
|
136
|
+
cellContext = {};
|
|
137
|
+
this.cellContexts.set(cellHandle, cellContext);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
cellContext[key] = value;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getCellContext(cellHandle: number): ContextMatcher {
|
|
144
|
+
return this.contextKeyService.createOverlay(Object.entries(this.cellContexts.get(cellHandle) ?? {}));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
changeCellFocus(focus: boolean): void {
|
|
148
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_FOCUSED, focus);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
changeCellListFocus(focus: boolean): void {
|
|
152
|
+
this.scopedStore.setContext(NOTEBOOK_CELL_LIST_FOCUSED, focus);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
createContextKeyChangedEvent(affectedKeys: string[]): ContextKeyChangeEvent {
|
|
156
|
+
return { affects: keys => affectedKeys.some(key => keys.has(key)) };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
dispose(): void {
|
|
160
|
+
this.toDispose.dispose();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -1,101 +1,101 @@
|
|
|
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
|
-
/*---------------------------------------------------------------------------------------------
|
|
18
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
19
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
20
|
-
*--------------------------------------------------------------------------------------------*/
|
|
21
|
-
|
|
22
|
-
import { Emitter } from '@theia/core';
|
|
23
|
-
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
24
|
-
import { ApplicationShell } from '@theia/core/lib/browser';
|
|
25
|
-
import { NotebookEditorWidget } from '../notebook-editor-widget';
|
|
26
|
-
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
27
|
-
import { NOTEBOOK_EDITOR_FOCUSED } from '../contributions/notebook-context-keys';
|
|
28
|
-
|
|
29
|
-
@injectable()
|
|
30
|
-
export class NotebookEditorWidgetService {
|
|
31
|
-
|
|
32
|
-
@inject(ApplicationShell)
|
|
33
|
-
protected applicationShell: ApplicationShell;
|
|
34
|
-
|
|
35
|
-
@inject(ContextKeyService)
|
|
36
|
-
protected contextKeyService: ContextKeyService;
|
|
37
|
-
|
|
38
|
-
protected readonly notebookEditors = new Map<string, NotebookEditorWidget>();
|
|
39
|
-
|
|
40
|
-
protected readonly onNotebookEditorAddEmitter = new Emitter<NotebookEditorWidget>();
|
|
41
|
-
protected readonly onNotebookEditorRemoveEmitter = new Emitter<NotebookEditorWidget>();
|
|
42
|
-
readonly onDidAddNotebookEditor = this.onNotebookEditorAddEmitter.event;
|
|
43
|
-
readonly onDidRemoveNotebookEditor = this.onNotebookEditorRemoveEmitter.event;
|
|
44
|
-
|
|
45
|
-
protected readonly onDidChangeFocusedEditorEmitter = new Emitter<NotebookEditorWidget | undefined>();
|
|
46
|
-
readonly onDidChangeFocusedEditor = this.onDidChangeFocusedEditorEmitter.event;
|
|
47
|
-
|
|
48
|
-
focusedEditor?: NotebookEditorWidget = undefined;
|
|
49
|
-
|
|
50
|
-
@postConstruct()
|
|
51
|
-
protected init(): void {
|
|
52
|
-
this.applicationShell.onDidChangeActiveWidget(event => {
|
|
53
|
-
this.notebookEditorFocusChanged(event.newValue as NotebookEditorWidget, event.newValue instanceof NotebookEditorWidget);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// --- editor management
|
|
58
|
-
|
|
59
|
-
addNotebookEditor(editor: NotebookEditorWidget): void {
|
|
60
|
-
if (this.notebookEditors.has(editor.id)) {
|
|
61
|
-
console.warn('Attempting to add duplicated notebook editor: ' + editor.id);
|
|
62
|
-
}
|
|
63
|
-
this.notebookEditors.set(editor.id, editor);
|
|
64
|
-
this.onNotebookEditorAddEmitter.fire(editor);
|
|
65
|
-
if (editor.isVisible) {
|
|
66
|
-
this.notebookEditorFocusChanged(editor, true);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
removeNotebookEditor(editor: NotebookEditorWidget): void {
|
|
71
|
-
if (this.notebookEditors.has(editor.id)) {
|
|
72
|
-
this.notebookEditors.delete(editor.id);
|
|
73
|
-
this.onNotebookEditorRemoveEmitter.fire(editor);
|
|
74
|
-
} else {
|
|
75
|
-
console.warn('Attempting to remove not registered editor: ' + editor.id);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getNotebookEditor(editorId: string): NotebookEditorWidget | undefined {
|
|
80
|
-
return this.notebookEditors.get(editorId);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
getNotebookEditors(): readonly NotebookEditorWidget[] {
|
|
84
|
-
return Array.from(this.notebookEditors.values());
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
notebookEditorFocusChanged(editor: NotebookEditorWidget, focus: boolean): void {
|
|
88
|
-
if (focus) {
|
|
89
|
-
if (editor !== this.focusedEditor) {
|
|
90
|
-
this.focusedEditor = editor;
|
|
91
|
-
this.contextKeyService.setContext(NOTEBOOK_EDITOR_FOCUSED, true);
|
|
92
|
-
this.onDidChangeFocusedEditorEmitter.fire(this.focusedEditor);
|
|
93
|
-
}
|
|
94
|
-
} else if (this.focusedEditor) {
|
|
95
|
-
this.focusedEditor = undefined;
|
|
96
|
-
this.contextKeyService.setContext(NOTEBOOK_EDITOR_FOCUSED, false);
|
|
97
|
-
this.onDidChangeFocusedEditorEmitter.fire(undefined);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}
|
|
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
|
+
/*---------------------------------------------------------------------------------------------
|
|
18
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
19
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
20
|
+
*--------------------------------------------------------------------------------------------*/
|
|
21
|
+
|
|
22
|
+
import { Emitter } from '@theia/core';
|
|
23
|
+
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
|
|
24
|
+
import { ApplicationShell } from '@theia/core/lib/browser';
|
|
25
|
+
import { NotebookEditorWidget } from '../notebook-editor-widget';
|
|
26
|
+
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
|
|
27
|
+
import { NOTEBOOK_EDITOR_FOCUSED } from '../contributions/notebook-context-keys';
|
|
28
|
+
|
|
29
|
+
@injectable()
|
|
30
|
+
export class NotebookEditorWidgetService {
|
|
31
|
+
|
|
32
|
+
@inject(ApplicationShell)
|
|
33
|
+
protected applicationShell: ApplicationShell;
|
|
34
|
+
|
|
35
|
+
@inject(ContextKeyService)
|
|
36
|
+
protected contextKeyService: ContextKeyService;
|
|
37
|
+
|
|
38
|
+
protected readonly notebookEditors = new Map<string, NotebookEditorWidget>();
|
|
39
|
+
|
|
40
|
+
protected readonly onNotebookEditorAddEmitter = new Emitter<NotebookEditorWidget>();
|
|
41
|
+
protected readonly onNotebookEditorRemoveEmitter = new Emitter<NotebookEditorWidget>();
|
|
42
|
+
readonly onDidAddNotebookEditor = this.onNotebookEditorAddEmitter.event;
|
|
43
|
+
readonly onDidRemoveNotebookEditor = this.onNotebookEditorRemoveEmitter.event;
|
|
44
|
+
|
|
45
|
+
protected readonly onDidChangeFocusedEditorEmitter = new Emitter<NotebookEditorWidget | undefined>();
|
|
46
|
+
readonly onDidChangeFocusedEditor = this.onDidChangeFocusedEditorEmitter.event;
|
|
47
|
+
|
|
48
|
+
focusedEditor?: NotebookEditorWidget = undefined;
|
|
49
|
+
|
|
50
|
+
@postConstruct()
|
|
51
|
+
protected init(): void {
|
|
52
|
+
this.applicationShell.onDidChangeActiveWidget(event => {
|
|
53
|
+
this.notebookEditorFocusChanged(event.newValue as NotebookEditorWidget, event.newValue instanceof NotebookEditorWidget);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// --- editor management
|
|
58
|
+
|
|
59
|
+
addNotebookEditor(editor: NotebookEditorWidget): void {
|
|
60
|
+
if (this.notebookEditors.has(editor.id)) {
|
|
61
|
+
console.warn('Attempting to add duplicated notebook editor: ' + editor.id);
|
|
62
|
+
}
|
|
63
|
+
this.notebookEditors.set(editor.id, editor);
|
|
64
|
+
this.onNotebookEditorAddEmitter.fire(editor);
|
|
65
|
+
if (editor.isVisible) {
|
|
66
|
+
this.notebookEditorFocusChanged(editor, true);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
removeNotebookEditor(editor: NotebookEditorWidget): void {
|
|
71
|
+
if (this.notebookEditors.has(editor.id)) {
|
|
72
|
+
this.notebookEditors.delete(editor.id);
|
|
73
|
+
this.onNotebookEditorRemoveEmitter.fire(editor);
|
|
74
|
+
} else {
|
|
75
|
+
console.warn('Attempting to remove not registered editor: ' + editor.id);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getNotebookEditor(editorId: string): NotebookEditorWidget | undefined {
|
|
80
|
+
return this.notebookEditors.get(editorId);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getNotebookEditors(): readonly NotebookEditorWidget[] {
|
|
84
|
+
return Array.from(this.notebookEditors.values());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
notebookEditorFocusChanged(editor: NotebookEditorWidget, focus: boolean): void {
|
|
88
|
+
if (focus) {
|
|
89
|
+
if (editor !== this.focusedEditor) {
|
|
90
|
+
this.focusedEditor = editor;
|
|
91
|
+
this.contextKeyService.setContext(NOTEBOOK_EDITOR_FOCUSED, true);
|
|
92
|
+
this.onDidChangeFocusedEditorEmitter.fire(this.focusedEditor);
|
|
93
|
+
}
|
|
94
|
+
} else if (this.focusedEditor) {
|
|
95
|
+
this.focusedEditor = undefined;
|
|
96
|
+
this.contextKeyService.setContext(NOTEBOOK_EDITOR_FOCUSED, false);
|
|
97
|
+
this.onDidChangeFocusedEditorEmitter.fire(undefined);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|