diff --git a/extensions/studio/src/browser/asset-browser/widget.tsx b/extensions/studio/src/browser/asset-browser/widget.tsx index bdcf397..0336845 100644 --- a/extensions/studio/src/browser/asset-browser/widget.tsx +++ b/extensions/studio/src/browser/asset-browser/widget.tsx @@ -10,6 +10,9 @@ import { } from "@theia/core/shared/inversify"; import { ReactWidget } from "@theia/core/lib/browser/widgets/react-widget"; import { OpenerService, open } from "@theia/core/lib/browser/opener-service"; +import { FileService } from "@theia/filesystem/lib/browser/file-service"; +import { WorkspaceService } from "@theia/workspace/lib/browser"; +import URI from "@theia/core/lib/common/uri"; import { AssetService, AssetEntry } from "./service"; export const ASSET_BROWSER_WIDGET_ID = "asset-browser"; @@ -25,6 +28,12 @@ export class AssetBrowserWidget extends ReactWidget { @inject(OpenerService) protected readonly openerService!: OpenerService; + @inject(FileService) + protected readonly fileService!: FileService; + + @inject(WorkspaceService) + protected readonly workspaceService!: WorkspaceService; + protected currentPath = ""; protected showBaseAssets = true; protected entries: AssetEntry[] = []; @@ -39,6 +48,31 @@ export class AssetBrowserWidget extends ReactWidget { this.title.iconClass = "codicon codicon-folder-opened"; this.addClass("asset-browser"); this.refresh(); + + this.toDispose.push( + this.fileService.onDidFilesChange((event) => { + if (this.isChangeRelevant(event)) { + this.refresh(); + } + }), + ); + } + + protected isChangeRelevant( + event: import("@theia/filesystem/lib/common/files").FileChangesEvent, + ): boolean { + const roots = this.workspaceService.tryGetRoots(); + if (roots.length === 0) { + return false; + } + const rootPath = new URI(roots[0].resource.toString()).path.toString(); + const prefixes = ["assets/mod/", "assets/dx/", "assets/us/"].map( + (layer) => rootPath + "/" + layer + this.currentPath, + ); + return event.changes.some((change) => { + const changePath = change.resource.path.toString(); + return prefixes.some((prefix) => changePath.startsWith(prefix)); + }); } protected async refresh(): Promise {