From d2f9a7ac0151c68ab7efc7a2c8f58296addf0f61 Mon Sep 17 00:00:00 2001 From: Vincent Fugnitto Date: Wed, 1 Mar 2023 09:10:19 -0500 Subject: [PATCH] workspace: update add and remove folder (#12242) The commit removes the unecessary `preferences.ready` handling when registering the `add` and `remove` folder commands as we no longer support the `supportMultiRootWorkspace` preference. The changes should make it easier for downstream to unregister the command if necessary. Signed-off-by: vince-fugnitto --- .../src/browser/workspace-commands.ts | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/packages/workspace/src/browser/workspace-commands.ts b/packages/workspace/src/browser/workspace-commands.ts index 1bc8f5046ba1e..9805463057497 100644 --- a/packages/workspace/src/browser/workspace-commands.ts +++ b/packages/workspace/src/browser/workspace-commands.ts @@ -324,34 +324,32 @@ export class WorkspaceCommandContribution implements CommandContribution { await this.clipboardService.writeText(text); } })); - this.preferences.ready.then(() => { - registry.registerCommand(WorkspaceCommands.ADD_FOLDER, { - isEnabled: () => this.workspaceService.opened, - isVisible: () => this.workspaceService.opened, - execute: async () => { - const selection = await this.fileDialogService.showOpenDialog({ - title: WorkspaceCommands.ADD_FOLDER.label!, - canSelectFiles: false, - canSelectFolders: true, - canSelectMany: true, - }); - if (!selection) { - return; - } - const uris = Array.isArray(selection) ? selection : [selection]; - const workspaceSavedBeforeAdding = this.workspaceService.saved; - await this.addFolderToWorkspace(...uris); - if (!workspaceSavedBeforeAdding) { - this.saveWorkspaceWithPrompt(registry); - } + registry.registerCommand(WorkspaceCommands.ADD_FOLDER, { + isEnabled: () => this.workspaceService.opened, + isVisible: () => this.workspaceService.opened, + execute: async () => { + const selection = await this.fileDialogService.showOpenDialog({ + title: WorkspaceCommands.ADD_FOLDER.label!, + canSelectFiles: false, + canSelectFolders: true, + canSelectMany: true, + }); + if (!selection) { + return; } - }); - registry.registerCommand(WorkspaceCommands.REMOVE_FOLDER, this.newMultiUriAwareCommandHandler({ - execute: uris => this.removeFolderFromWorkspace(uris), - isEnabled: () => this.workspaceService.isMultiRootWorkspaceOpened, - isVisible: uris => this.areWorkspaceRoots(uris) && this.workspaceService.saved - })); + const uris = Array.isArray(selection) ? selection : [selection]; + const workspaceSavedBeforeAdding = this.workspaceService.saved; + await this.addFolderToWorkspace(...uris); + if (!workspaceSavedBeforeAdding) { + this.saveWorkspaceWithPrompt(registry); + } + } }); + registry.registerCommand(WorkspaceCommands.REMOVE_FOLDER, this.newMultiUriAwareCommandHandler({ + execute: uris => this.removeFolderFromWorkspace(uris), + isEnabled: () => this.workspaceService.isMultiRootWorkspaceOpened, + isVisible: uris => this.areWorkspaceRoots(uris) && this.workspaceService.saved + })); } openers: OpenHandler[];