-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jonah Iden <[email protected]>
- Loading branch information
1 parent
205eca9
commit 4c5025b
Showing
41 changed files
with
1,897 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/notebook/src/browser/service/notebook-editor-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 TypeFox and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Disposable, DisposableCollection, Emitter } from '@theia/core'; | ||
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify'; | ||
import { ApplicationShell } from '@theia/core/lib/browser'; | ||
import { NotebookEditorWidget, NOTEBOOK_EDITOR_ID_PREFIX } from '../notebook-editor-widget'; | ||
|
||
@injectable() | ||
export class NotebookEditorWidgetService implements Disposable { | ||
|
||
@inject(ApplicationShell) | ||
protected applicationShell: ApplicationShell; | ||
|
||
private readonly notebookEditors = new Map<string, NotebookEditorWidget>(); | ||
|
||
private readonly onNotebookEditorAddEmitter = new Emitter<NotebookEditorWidget>(); | ||
private readonly onNotebookEditorsRemoveEmitter = new Emitter<NotebookEditorWidget>(); | ||
readonly onDidAddNotebookEditor = this.onNotebookEditorAddEmitter.event; | ||
readonly onDidRemoveNotebookEditor = this.onNotebookEditorsRemoveEmitter.event; | ||
|
||
private readonly onFocusedEditorChangedEmitter = new Emitter<NotebookEditorWidget>(); | ||
readonly onFocusedEditorChanged = this.onFocusedEditorChangedEmitter.event; | ||
|
||
private readonly listeners = new DisposableCollection(); | ||
|
||
currentfocusedEditor?: NotebookEditorWidget = undefined; | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
this.listeners.push(this.applicationShell.onDidChangeActiveWidget(event => { | ||
if (event.newValue?.id.startsWith(NOTEBOOK_EDITOR_ID_PREFIX) && event.newValue !== this.currentfocusedEditor) { | ||
this.currentfocusedEditor = event.newValue as NotebookEditorWidget; | ||
this.onFocusedEditorChangedEmitter.fire(this.currentfocusedEditor); | ||
} | ||
})); | ||
} | ||
|
||
dispose(): void { | ||
this.onNotebookEditorAddEmitter.dispose(); | ||
this.onNotebookEditorsRemoveEmitter.dispose(); | ||
this.listeners.dispose(); | ||
} | ||
|
||
// --- editor management | ||
|
||
addNotebookEditor(editor: NotebookEditorWidget): void { | ||
this.notebookEditors.set(editor.id, editor); | ||
this.onNotebookEditorAddEmitter.fire(editor); | ||
} | ||
|
||
removeNotebookEditor(editor: NotebookEditorWidget): void { | ||
if (this.notebookEditors.has(editor.id)) { | ||
this.notebookEditors.delete(editor.id); | ||
this.onNotebookEditorsRemoveEmitter.fire(editor); | ||
} | ||
} | ||
|
||
getNotebookEditor(editorId: string): NotebookEditorWidget | undefined { | ||
return this.notebookEditors.get(editorId); | ||
} | ||
|
||
listNotebookEditors(): readonly NotebookEditorWidget[] { | ||
return [...this.notebookEditors].map(e => e[1]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.