Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webview: add support for activeWebviewPanelId #12182

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('');
}
}
}