Search in sources :

Example 6 with ModifiableModuleModel

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;
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ModuleWithNameAlreadyExists(com.intellij.openapi.module.ModuleWithNameAlreadyExists)

Example 7 with ModifiableModuleModel

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);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) ModuleManager(com.intellij.openapi.module.ModuleManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with ModifiableModuleModel

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());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel)

Example 9 with ModifiableModuleModel

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()]);
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) IdeBundle(com.intellij.ide.IdeBundle) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) Project(com.intellij.openapi.project.Project) MoveModulesToSubGroupAction(com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) MoveModulesToGroupAction(com.intellij.ide.projectView.actions.MoveModulesToGroupAction) Project(com.intellij.openapi.project.Project) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ArrayList(java.util.ArrayList) MoveModulesToGroupAction(com.intellij.ide.projectView.actions.MoveModulesToGroupAction) MoveModulesToSubGroupAction(com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with ModifiableModuleModel

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;
        }
    }
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module)

Aggregations

ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)44 Module (com.intellij.openapi.module.Module)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 ModuleManager (com.intellij.openapi.module.ModuleManager)10 Project (com.intellij.openapi.project.Project)9 NotNull (org.jetbrains.annotations.NotNull)8 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5 File (java.io.File)5 Result (com.intellij.openapi.application.Result)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (aQute.bnd.build.Project)2 MoveModulesToSubGroupAction (com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction)2 FlexProjectConfigurationEditor (com.intellij.lang.javascript.flex.projectStructure.model.impl.FlexProjectConfigurationEditor)2