Custom ModuleBuilder only for new projects, not modules

Hello,

I would like to create a custom project generator that shows up in the “New Project” dialog window. However, I do not want this generator in the “New Module” window.

To achieve this, I have created a custom ModuleType and a corresponding ModuleBuilder, and then added the ModuleType to plugin.xml. Unsurprisingly, the custom project generator shows up in both “New Project” and “New Module” windows. What should I do to make the project generator hidden from the “New Module” window?

I am aware of the `ModuleBuilder.isAvailable` method, and I can return false to hide the generator. However, I don't know how to distinguish between creating a project vs. a module in the context of `isAvailable`.

@Override
public boolean isAvailable() {
    return false; // This would hide the generator from both "New Project" and "New Module" dialog windows. I want to hide it solely from the "New Module" window.
}

If relevant, here's the current implementation:

Thanks in advance

2
3 comments

Did you manage to figure it out? I've got similar case but using `GeneratorNewProjectWizardBuilderAdapter`. There is also `canCreateModule` but it does not seem to affect New Module menu visibility.

0

I fixed it by checking that the action that opened the dialog is the NewProject action

  @Override
  public boolean isAvailable() {
    // Only show the builder when creating a new project
    return Objects.equals(
        ((ActionManagerImpl) ActionManagerImpl.getInstance())
            .getLastPreformedActionId(),
        "NewProject");
  }
1

For me those actions are:

  • NewModuleInGroup
  • NewProject
  • NewModule
  • WelcomeScreen.CreateNewProject

So indeed, if contains “Module” do not make it available, thanks

0

Please sign in to leave a comment.