Skip to content

Commit

Permalink
Handle overlay integration shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
jpan8866 committed Oct 29, 2024
1 parent d4808c5 commit 0f8a95d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/vs/workbench/browser/parts/overlay/pearOverlayPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export class PearOverlayPart extends Part {
this.initialize();
}

isVisible(): boolean {
return this.state === "open";
}

private async initialize() {
const extensionDescription: WebviewExtensionDescription = {
id: new ExtensionIdentifier(PEAROVERLAY_ID),
Expand Down
36 changes: 36 additions & 0 deletions src/vs/workbench/browser/parts/overlay/pearOverlayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "vs/platform/instantiation/common/instantiation";
import { IEditorService } from "vs/workbench/services/editor/common/editorService";
import { ITerminalService } from "vs/workbench/contrib/terminal/browser/terminal";
import { CommandsRegistry } from "vs/platform/commands/common/commands";

export const IPearOverlayService = createDecorator<IPearOverlayService>(
"pearaiOverlayService",
Expand Down Expand Up @@ -37,6 +38,11 @@ export interface IPearOverlayService extends IDisposable {
* Toggles the visibility of the PearAI popup.
*/
toggle(): void;

/**
* Returns true if the PearAI popup is visible.
*/
isVisible(): boolean;
}

export class PearOverlayService
Expand All @@ -52,11 +58,13 @@ export class PearOverlayService
private readonly instantiationService: IInstantiationService,
@IEditorService private readonly _editorService: IEditorService,
@ITerminalService private readonly _terminalService: ITerminalService,
// @ICommandService private readonly commandService: ICommandService,
) {
super();
this._pearOverlayPart =
this.instantiationService.createInstance(PearOverlayPart);
this.registerListeners();
this.registerCommands();
}

private registerListeners(): void {
Expand All @@ -73,6 +81,29 @@ export class PearOverlayService
);
}

private registerCommands(): void {
// Register commands for external use e.g. in pearai submodule
CommandsRegistry.registerCommand('pearai.isOverlayVisible', (accessor) => {
const overlayService = accessor.get(IPearOverlayService);
return overlayService.isVisible();
});

CommandsRegistry.registerCommand('pearai.showOverlay', (accessor) => {
const overlayService = accessor.get(IPearOverlayService);
overlayService.show();
});

CommandsRegistry.registerCommand('pearai.hideOverlay', (accessor) => {
const overlayService = accessor.get(IPearOverlayService);
overlayService.hide();
});

CommandsRegistry.registerCommand('pearai.toggleOverlay', (accessor) => {
const overlayService = accessor.get(IPearOverlayService);
overlayService.toggle();
});
}

get pearOverlayPart(): PearOverlayPart {
return this._pearOverlayPart;
}
Expand All @@ -93,6 +124,11 @@ export class PearOverlayService
super.dispose();
this._pearOverlayPart.dispose();
}

isVisible(): boolean {
return this._pearOverlayPart.isVisible();
}

}

registerSingleton(
Expand Down

0 comments on commit 0f8a95d

Please sign in to comment.