Skip to content

Commit

Permalink
workspace: update add and remove folder (#12242)
Browse files Browse the repository at this point in the history
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 <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto authored Mar 1, 2023
1 parent 5e6bd8d commit d2f9a7a
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down

0 comments on commit d2f9a7a

Please sign in to comment.