Skip to content

Commit

Permalink
Support activeCustomEditorId context key (#13267)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner authored Jan 18, 2024
1 parent ff8148f commit f4ad0cd
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
import { ApplicationShell, FocusTracker, Widget } from '@theia/core/lib/browser';
import { ContextKey, ContextKeyService } from '@theia/core/lib/browser/context-key-service';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { CustomEditorWidget } from '../custom-editors/custom-editor-widget';
import { WebviewWidget } from './webview';

@injectable()
Expand All @@ -27,6 +28,11 @@ export class WebviewContextKeys {
*/
activeWebviewPanelId: ContextKey<string>;

/**
* Context key representing the `viewType` of the active `CustomEditorWidget`, if any.
*/
activeCustomEditorId: ContextKey<string>;

@inject(ApplicationShell)
protected applicationShell: ApplicationShell;

Expand All @@ -36,12 +42,19 @@ export class WebviewContextKeys {
@postConstruct()
protected init(): void {
this.activeWebviewPanelId = this.contextKeyService.createKey('activeWebviewPanelId', '');
this.activeCustomEditorId = this.contextKeyService.createKey('activeCustomEditorId', '');
this.applicationShell.onDidChangeCurrentWidget(this.handleDidChangeCurrentWidget, this);
}

protected handleDidChangeCurrentWidget(change: FocusTracker.IChangedArgs<Widget>): void {
if (change.newValue instanceof WebviewWidget) {
this.activeWebviewPanelId.set(change.newValue.viewType);
const { newValue } = change;
if (newValue instanceof CustomEditorWidget) {
this.activeCustomEditorId.set(newValue.viewType);
} else {
this.activeCustomEditorId.set('');
}
if (newValue instanceof WebviewWidget) {
this.activeWebviewPanelId.set(newValue.viewType);
} else {
this.activeWebviewPanelId.set('');
}
Expand Down

0 comments on commit f4ad0cd

Please sign in to comment.