use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class RenameProjectHandler method renameProject.
public static boolean renameProject(@NotNull ProjectEx project, @Nullable Module module, String newName) {
if (shouldRenameProject(project, module, newName)) {
project.setProjectName(newName);
project.save();
}
if (module != null && !newName.equals(module.getName())) {
final ModifiableModuleModel modifiableModel = ModuleManager.getInstance(project).getModifiableModel();
try {
modifiableModel.renameModule(module, newName);
} catch (ModuleWithNameAlreadyExists moduleWithNameAlreadyExists) {
Messages.showErrorDialog(project, IdeBundle.message("error.module.already.exists", newName), IdeBundle.message("title.rename.module"));
return false;
}
final Ref<Boolean> success = Ref.create(Boolean.TRUE);
CommandProcessor.getInstance().executeCommand(project, () -> ApplicationManager.getApplication().runWriteAction(() -> modifiableModel.commit()), IdeBundle.message("command.renaming.module", module.getName()), null);
return success.get().booleanValue();
}
return true;
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class ModuleDeleteProvider method deleteElement.
@Override
public void deleteElement(@NotNull DataContext dataContext) {
final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
assert modules != null;
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
assert project != null;
String names = StringUtil.join(Arrays.asList(modules), module -> "\'" + module.getName() + "\'", ", ");
int ret = Messages.showOkCancelDialog(getConfirmationText(modules, names), getActionTitle(), Messages.getQuestionIcon());
if (ret != Messages.OK)
return;
CommandProcessor.getInstance().executeCommand(project, () -> {
final Runnable action = () -> {
final ModuleManager moduleManager = ModuleManager.getInstance(project);
final Module[] currentModules = moduleManager.getModules();
final ModifiableModuleModel modifiableModuleModel = moduleManager.getModifiableModel();
final Map<Module, ModifiableRootModel> otherModuleRootModels = new HashMap<>();
for (final Module module : modules) {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
for (final Module otherModule : currentModules) {
if (otherModule == module || ArrayUtilRt.find(modules, otherModule) != -1)
continue;
if (!otherModuleRootModels.containsKey(otherModule)) {
otherModuleRootModels.put(otherModule, ModuleRootManager.getInstance(otherModule).getModifiableModel());
}
}
removeModule(module, modifiableModel, otherModuleRootModels.values(), modifiableModuleModel);
}
final ModifiableRootModel[] modifiableRootModels = otherModuleRootModels.values().toArray(new ModifiableRootModel[otherModuleRootModels.size()]);
ModifiableModelCommitter.multiCommit(modifiableRootModels, modifiableModuleModel);
};
ApplicationManager.getApplication().runWriteAction(action);
}, ProjectBundle.message("module.remove.command"), null);
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class ImportModuleFromImlFileAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
final Project project = getEventProject(e);
if (files == null || project == null)
return;
try {
final ModifiableModuleModel model = ModuleManager.getInstance(project).getModifiableModel();
for (VirtualFile file : files) {
model.loadModule(file.getPath());
}
WriteAction.run(() -> model.commit());
} catch (Exception ex) {
LOG.info(ex);
Messages.showErrorDialog(project, "Cannot import module: " + ex.getMessage(), CommonBundle.getErrorTitle());
}
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class MoveModuleToGroup method getChildren.
@Override
@NotNull
public AnAction[] getChildren(@Nullable AnActionEvent e) {
if (e == null)
return EMPTY_ARRAY;
Project project = getEventProject(e);
if (project == null)
return EMPTY_ARRAY;
ModifiableModuleModel modifiableModuleModel = LangDataKeys.MODIFIABLE_MODULE_MODEL.getData(e.getDataContext());
List<AnAction> result = new ArrayList<>();
result.add(new MoveModulesToGroupAction(myModuleGroup, IdeBundle.message("action.move.module.to.this.group")));
result.add(new MoveModulesToSubGroupAction(myModuleGroup));
result.add(Separator.getInstance());
ModuleGrouper grouper = ModuleGrouper.instanceFor(project, modifiableModuleModel);
result.addAll(myModuleGroup.childGroups(grouper).stream().sorted((moduleGroup1, moduleGroup2) -> {
assert moduleGroup1.getGroupPath().length == moduleGroup2.getGroupPath().length;
return moduleGroup1.toString().compareToIgnoreCase(moduleGroup2.toString());
}).map(MoveModuleToGroup::new).collect(Collectors.toList()));
return result.toArray(new AnAction[result.size()]);
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class ModuleProjectStructureElement method checkModulesNames.
public void checkModulesNames(ProjectStructureProblemsHolder problemsHolder) {
final ModifiableModuleModel moduleModel = myContext.getModulesConfigurator().getModuleModel();
final Module[] all = moduleModel.getModules();
if (!ArrayUtil.contains(myModule, all)) {
//module has been deleted
return;
}
for (Module each : all) {
if (each != myModule && myContext.getRealName(each).equals(myContext.getRealName(myModule))) {
problemsHolder.registerProblem(ProjectBundle.message("project.roots.module.duplicate.name.message"), null, ProjectStructureProblemType.error("duplicate-module-name"), createPlace(), null);
break;
}
}
}
Aggregations