Search in sources :

Example 31 with ModifiableModuleModel

use of com.intellij.openapi.module.ModifiableModuleModel in project android by JetBrains.

the class ModuleDisposer method disposeModulesAndMarkImlFilesForDeletion.

public void disposeModulesAndMarkImlFilesForDeletion(@NotNull Collection<Module> modules, @NotNull Project project, @NotNull IdeModifiableModelsProvider ideModelsProvider) {
    if (!modules.isEmpty()) {
        ModifiableModuleModel moduleModel = ideModelsProvider.getModifiableModuleModel();
        List<File> imlFilesToRemove = new ArrayList<>();
        for (Module toDispose : modules) {
            File imlFilePath = new File(toSystemDependentName(toDispose.getModuleFilePath()));
            imlFilesToRemove.add(imlFilePath);
            moduleModel.disposeModule(toDispose);
        }
        DisposedModules.getInstance(project).markImlFilesForDeletion(imlFilesToRemove);
    }
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ArrayList(java.util.ArrayList) Module(com.intellij.openapi.module.Module) File(java.io.File)

Example 32 with ModifiableModuleModel

use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.

the class MoveModuleToGroupTopLevel 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 moduleModel = LangDataKeys.MODIFIABLE_MODULE_MODEL.getData(e.getDataContext());
    ModuleGrouper grouper = ModuleGrouper.instanceFor(project, moduleModel);
    List<String> topLevelGroupNames = new ArrayList<>(getTopLevelGroupNames(grouper));
    Collections.sort(topLevelGroupNames);
    List<AnAction> result = new ArrayList<>();
    result.add(new MoveModulesOutsideGroupAction());
    result.add(new MoveModulesToSubGroupAction(null));
    result.add(Separator.getInstance());
    for (String name : topLevelGroupNames) {
        result.add(new MoveModuleToGroup(new ModuleGroup(Collections.singletonList(name))));
    }
    return result.toArray(new AnAction[result.size()]);
}
Also used : Project(com.intellij.openapi.project.Project) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) MoveModulesOutsideGroupAction(com.intellij.ide.projectView.actions.MoveModulesOutsideGroupAction) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) MoveModulesToSubGroupAction(com.intellij.ide.projectView.actions.MoveModulesToSubGroupAction) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with ModifiableModuleModel

use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.

the class MoveModulesToGroupAction method doMove.

public static void doMove(final Module[] modules, final ModuleGroup group, @Nullable final DataContext dataContext) {
    Project project = modules[0].getProject();
    for (final Module module : modules) {
        ModifiableModuleModel model = dataContext != null ? LangDataKeys.MODIFIABLE_MODULE_MODEL.getData(dataContext) : null;
        if (model != null) {
            model.setModuleGroupPath(module, group == null ? null : group.getGroupPath());
        } else {
            ModuleManagerImpl.getInstanceImpl(project).setModuleGroupPath(module, group == null ? null : group.getGroupPath());
        }
    }
    AbstractProjectViewPane pane = ProjectView.getInstance(project).getCurrentProjectViewPane();
    if (pane != null) {
        pane.updateFromRoot(true);
    }
    if (!ProjectSettingsService.getInstance(project).processModulesMoved(modules, group) && pane != null) {
        if (group != null) {
            pane.selectModuleGroup(group, true);
        } else {
            pane.selectModule(modules[0], true);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane)

Example 34 with ModifiableModuleModel

use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.

the class NonProjectFileAccessTest method testAccessToModuleSystemFiles.

public void testAccessToModuleSystemFiles() throws Exception {
    final Module moduleWithoutContentRoot = new WriteCommandAction<Module>(getProject()) {

        @Override
        protected void run(@NotNull Result<Module> result) throws Throwable {
            String moduleName;
            ModifiableModuleModel moduleModel = ModuleManager.getInstance(getProject()).getModifiableModel();
            try {
                VirtualFile moduleDir = getProject().getBaseDir().createChildDirectory(this, "moduleWithoutContentRoot");
                moduleName = moduleModel.newModule(moduleDir.getPath() + "/moduleWithoutContentRoot.iml", EmptyModuleType.EMPTY_MODULE).getName();
                moduleModel.commit();
            } catch (Throwable t) {
                moduleModel.dispose();
                throw t;
            }
            result.setResult(ModuleManager.getInstance(getProject()).findModuleByName(moduleName));
        }
    }.execute().getResultObject();
    PlatformTestUtil.saveProject(getProject());
    VirtualFile fileUnderNonProjectModuleDir = createFileExternally(new File(moduleWithoutContentRoot.getModuleFile().getParent().getPath()));
    assertFalse(ProjectFileIndex.SERVICE.getInstance(getProject()).isInContent(fileUnderNonProjectModuleDir));
    typeAndCheck(moduleWithoutContentRoot.getModuleFile(), true);
    typeAndCheck(myModule.getModuleFile(), true);
    typeAndCheck(fileUnderNonProjectModuleDir, false);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Result(com.intellij.openapi.application.Result)

Example 35 with ModifiableModuleModel

use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.

the class AbstractModuleDataService method importData.

@Override
public void importData(@NotNull final Collection<DataNode<E>> toImport, @Nullable ProjectData projectData, @NotNull final Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    if (toImport.isEmpty()) {
        return;
    }
    final Collection<DataNode<E>> toCreate = filterExistingModules(toImport, modelsProvider, project);
    if (!toCreate.isEmpty()) {
        createModules(toCreate, modelsProvider, project);
    }
    for (DataNode<E> node : toImport) {
        Module module = node.getUserData(MODULE_KEY);
        if (module != null) {
            String productionModuleId = node.getData().getProductionModuleId();
            modelsProvider.setTestModuleProperties(module, productionModuleId);
            setModuleOptions(module, node);
            ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
            syncPaths(module, modifiableRootModel, node.getData());
            setLanguageLevel(modifiableRootModel, node.getData());
        }
    }
    for (DataNode<E> node : toImport) {
        Module module = node.getUserData(MODULE_KEY);
        if (module != null) {
            final String[] groupPath;
            groupPath = node.getData().getIdeModuleGroup();
            final ModifiableModuleModel modifiableModel = modelsProvider.getModifiableModuleModel();
            modifiableModel.setModuleGroupPath(module, groupPath);
        }
    }
}
Also used : ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) DataNode(com.intellij.openapi.externalSystem.model.DataNode) 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