Skip to content

Commit

Permalink
feat: overlay-lock (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Himanshu-Singh-Chauhan authored and nang-dev committed Nov 8, 2024
1 parent 0c1a35e commit 589142e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/vs/workbench/browser/parts/overlay/pearOverlayPart.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable header/header */

import { Part } from "vs/workbench/browser/part";
import {
IWorkbenchLayoutService,
Expand Down Expand Up @@ -35,6 +37,7 @@ export class PearOverlayPart extends Part {
private _webviewService: WebviewService | undefined;

private state: "loading" | "open" | "closed" = "loading";
private _isLocked: boolean = false;

constructor(
@IThemeService themeService: IThemeService,
Expand Down Expand Up @@ -232,6 +235,10 @@ export class PearOverlayPart extends Part {
}

private close() {
if (this.isLocked) {
return; // Prevent closing when locked
}

if (this.state === "closed") {
return;
}
Expand Down Expand Up @@ -283,6 +290,18 @@ export class PearOverlayPart extends Part {
this.toggleOpenClose();
}

public lock(): void {
this._isLocked = true;
}

public unlock(): void {
this._isLocked = false;
}

public get isLocked(): boolean {
return this._isLocked;
}

toJSON(): object {
return {
type: Parts.PEAROVERLAY_PART,
Expand Down
45 changes: 44 additions & 1 deletion src/vs/workbench/browser/parts/overlay/pearOverlayService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable header/header */

import {
registerSingleton,
InstantiationType,
Expand Down Expand Up @@ -43,6 +45,21 @@ export interface IPearOverlayService extends IDisposable {
* Returns true if the PearAI popup is visible.
*/
isVisible(): boolean;

/**
* Locks the PearAI popup.
*/
lock(): void;

/**
* Unlocks the PearAI popup.
*/
unlock(): void;

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

export class PearOverlayService
Expand Down Expand Up @@ -102,6 +119,21 @@ export class PearOverlayService
const overlayService = accessor.get(IPearOverlayService);
overlayService.toggle();
});

CommandsRegistry.registerCommand("pearai.lockOverlay", (accessor) => {
const overlayService = accessor.get(IPearOverlayService);
overlayService.lock();
});

CommandsRegistry.registerCommand("pearai.unlockOverlay", (accessor) => {
const overlayService = accessor.get(IPearOverlayService);
overlayService.unlock();
});

CommandsRegistry.registerCommand("pearai.isOverlayLocked", (accessor) => {
const overlayService = accessor.get(IPearOverlayService);
return overlayService.isLocked();
});
}

get pearOverlayPart(): PearOverlayPart {
Expand All @@ -120,6 +152,18 @@ export class PearOverlayService
this._pearOverlayPart.toggle();
}

lock(): void {
this._pearOverlayPart.lock();
}

unlock(): void {
this._pearOverlayPart.unlock();
}

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

override dispose(): void {
super.dispose();
this._pearOverlayPart.dispose();
Expand All @@ -128,7 +172,6 @@ export class PearOverlayService
isVisible(): boolean {
return this._pearOverlayPart.isVisible();
}

}

registerSingleton(
Expand Down

0 comments on commit 589142e

Please sign in to comment.