-
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.
webview: add support for
activeWebviewPanelId
(#12182)
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
1 parent
cd74848
commit 24d7882
Showing
2 changed files
with
52 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
packages/plugin-ext/src/main/browser/webview/webview-context-keys.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,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(''); | ||
} | ||
} | ||
} |