Skip to content

Commit

Permalink
webview: add support for activeWebviewPanelId (#12182)
Browse files Browse the repository at this point in the history
The commit adds support for the `activeWebviewPanelId` context when-clause.

Signed-off-by: vince-fugnitto <[email protected]>
Co-authored-by: Paul Marechal <[email protected]>
  • Loading branch information
vince-fugnitto and paul-marechal authored Feb 23, 2023
1 parent cd74848 commit 24d7882
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { PluginMenuCommandAdapter } from './menus/plugin-menu-command-adapter';
import './theme-icon-override';
import { PluginTerminalRegistry } from './plugin-terminal-registry';
import { DnDFileContentStore } from './view/dnd-file-content-store';
import { WebviewContextKeys } from './webview/webview-context-keys';

export default new ContainerModule((bind, unbind, isBound, rebind) => {

Expand Down Expand Up @@ -177,6 +178,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(WebviewWidget).toSelf();
bind(WebviewWidgetFactory).toDynamicValue(ctx => new WebviewWidgetFactory(ctx.container)).inSingletonScope();
bind(WidgetFactory).toService(WebviewWidgetFactory);
bind(WebviewContextKeys).toSelf().inSingletonScope();
bind(FrontendApplicationContribution).toService(WebviewContextKeys);

bind(CustomEditorContribution).toSelf().inSingletonScope();
bind(CommandContribution).toService(CustomEditorContribution);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// *****************************************************************************
// Copyright (C) 2023 Ericsson 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 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 { WebviewWidget } from './webview';

@injectable()
export class WebviewContextKeys {

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

@inject(ApplicationShell)
protected applicationShell: ApplicationShell;

@inject(ContextKeyService)
protected contextKeyService: ContextKeyService;

@postConstruct()
protected postConstruct(): void {
this.activeWebviewPanelId = this.contextKeyService.createKey('activeWebviewPanelId', '');
this.applicationShell.onDidChangeCurrentWidget(this.handleDidChangeCurrentWidget, this);
}

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

0 comments on commit 24d7882

Please sign in to comment.