Java Code Examples for com.intellij.openapi.module.ModifiableModuleModel#renameModule()

The following examples show how to use com.intellij.openapi.module.ModifiableModuleModel#renameModule() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void setDisplayName(String name) {
  name = name.trim();
  final ModifiableModuleModel modifiableModuleModel = myConfigurator.getModuleModel();
  if (StringUtil.isEmpty(name)) return; //empty string comes on double click on module node
  if (Comparing.strEqual(name, myModuleName)) return; //nothing changed
  try {
    modifiableModuleModel.renameModule(myModule, name);
  }
  catch (ModuleWithNameAlreadyExistsException ignored) {
  }
  myConfigurator.moduleRenamed(myModule, myModuleName, name);
  myModuleName = name;
  myConfigurator.setModified(!Comparing.strEqual(myModuleName, myModule.getName()));
  myContext.getDaemonAnalyzer().queueUpdateForAllElementsWithErrors();
}
 
Example 2
Source File: ModulePointerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testRenameModule() throws Exception {
  final NamedPointer<Module> pointer = ModuleUtilCore.createPointer(getProject(), "abc");
  final Module module = addModule("abc");
  ModifiableModuleModel model = getModuleManager().getModifiableModel();
  model.renameModule(module, "xyz");
  commitModel(model);
  assertSame(module, pointer.get());
  assertEquals("xyz", pointer.getName());
}
 
Example 3
Source File: RenameProjectHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canClose(final String inputString) {
  if (!inputString.equals(myProject.getName())) {
    myProject.setProjectName(inputString);
    myProject.save();
  }

  if (myModule != null && !inputString.equals(myModule.getName())) {
    final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(myProject).getModifiableModel();
    try {
      modifiableModel.renameModule(myModule, inputString);
    }
    catch (ModuleWithNameAlreadyExistsException moduleWithNameAlreadyExists) {
      Messages.showErrorDialog(myProject, IdeBundle.message("error.module.already.exists", inputString),
                               IdeBundle.message("title.rename.module"));
      return false;
    }
    final Ref<Boolean> success = Ref.create(Boolean.TRUE);
    CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            modifiableModel.commit();
          }
        });
      }
    }, IdeBundle.message("command.renaming.module", myModule.getName()), null);
    return success.get().booleanValue();
  }
  return true;
}
 
Example 4
Source File: RenameModuleHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private ModifiableModuleModel renameModule(String inputString) {
  final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(myProject).getModifiableModel();
  try {
    modifiableModel.renameModule(myModule, inputString);
  }
  catch (ModuleWithNameAlreadyExistsException moduleWithNameAlreadyExists) {
    Messages.showErrorDialog(myProject, IdeBundle.message("error.module.already.exists", inputString),
                             IdeBundle.message("title.rename.module"));
    return null;
  }
  return modifiableModel;
}