Remove "Add folder to workspace..." from "More Actions..."

Hi,

I want to remove the Add folder to workspace... from More Actions... and from the right click options. I used the hello world extension examples and was able to remove it from under the file menu but can’t seem to find the correct command and registry for more actions and right click. Till now I have found that the i need to extend the FileNavigatorContribution to unregister the FileNavigatorCommands.ADD_ROOT_FOLDER but cant pinpoint the exact registry or commands. Any help would be appreciated.

Thanks.

@san thank you for the discussion, the ... (more menu) is actually a toolbar item, so the item add folder to workspace... is registered here:

You should be able to remove the item like so:

toolbarRegistry.unregisterItem(WorkspaceCommands.ADD_FOLDER.id);

Thank you @vince-fugnitto for your reply. I was able to remove it from the File navigator. Now will apply the solution you provided. Thank you again for the prompt response.

1 Like

Hi again,

So i have the following code:

import { injectable } from '@theia/core/shared/inversify';
import { CommandRegistry } from '@theia/core/lib/common';
import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';
import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution';
import { FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
import { TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';

@injectable()
export class TheiaNavigatorExtensionCommandContribution extends FileNavigatorContribution {

    registerCommands(registry: CommandRegistry): void {
        super.registerCommands(registry);
            registry.unregisterCommand(FileNavigatorCommands.ADD_ROOT_FOLDER,);
    }

    registerToolbar(registry: TabBarToolbarRegistry): void {
        super.registerToolbarItems(registry);
            registry.unregisterItem(WorkspaceCommands.ADD_FOLDER.id);
    }
}

The unregisterCommand for the FileNavigatorCommands is working but the unregsiterItem for WorkspaceCommads is not working. I am not sure if what i did is correct. Any idea on this?

@san I believe that it has to do with the fact that we register the command when the PreferenceService is ready, so you can in theory wait for it to be ready in order to unregister it. Also please note that it is not necessary to extend FileNavigatorContribution in order to perform the modifications:

import { inject, injectable } from '@theia/core/shared/inversify';
import { CommandContribution, CommandRegistry } from '@theia/core';
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { WorkspaceCommands } from '@theia/workspace/lib/browser';
import { PreferenceService } from '@theia/core/lib/browser';

@injectable()
export class CustomizationContribution implements CommandContribution, TabBarToolbarContribution {

    @inject(PreferenceService)
    protected readonly preferenceService: PreferenceService;

    registerCommands(registry: CommandRegistry): void {
        this.preferenceService.ready.then(() => {
            registry.unregisterCommand(WorkspaceCommands.ADD_FOLDER.id);
        });
    }

    registerToolbarItems(registry: TabBarToolbarRegistry): void {
        registry.unregisterItem(WorkspaceCommands.ADD_FOLDER.id);
    }

}
1 Like

Hi,
Thanks for your reponse.
I applied this solution, but I can still see Add Folder to Workpsace... option in the tool bar. I also have another extension like:

import { injectable } from '@theia/core/shared/inversify';
// import { CommandRegistry, MenuModelRegistry } from '@theia/core/lib/common';
import { CommandRegistry } from '@theia/core/lib/common';
import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';
import { WorkspaceFrontendContribution } from '@theia/workspace/lib/browser/workspace-frontend-contribution';

@injectable()
export class TheiaWorkspaceExtensionCommandContribution extends WorkspaceFrontendContribution {


    private blacklist = [
        WorkspaceCommands.OPEN,
        WorkspaceCommands.OPEN_FILE,
        WorkspaceCommands.OPEN_FOLDER,
        WorkspaceCommands.OPEN_WORKSPACE,
        WorkspaceCommands.OPEN_RECENT_WORKSPACE,
        WorkspaceCommands.ADD_FOLDER,
        WorkspaceCommands.SAVE_WORKSPACE_AS,
        WorkspaceCommands.CLOSE,
    ];

    registerCommands(registry: CommandRegistry): void {
        super.registerCommands(registry);
        for (const command of this.blacklist) {
            registry.unregisterCommand(command.id);
        }
    }
}

This was able to remove the Add Foler to Workspace... from the File menu. And created another extension with the solution you provided but I can still it in the command palette and in More Action... tool bar.
What I have noticed is for this command it is registered using registerMoreToolbarItem like here: theia/navigator-contribution.ts at 60209ecf17f695518856fe3bcf4383dea5512950 · eclipse-theia/theia · GitHub
Does it have to do anything with this?

Hi again,
So instead of creating another. ts file I applied the solution to the existing .ts file i had with all the extension, and it worked. I don’t know why but it works.
Is it a good practice to create each individual .ts file for each extension or a singular .ts file with all the extension?

Thank you again for your help. Really appreciate it.

Update: So i figured out that I didn’t point to the new files in theiaExtensions in package.json. That is why it didn’t work.