From c61d90531d8b1c374cb80f286c550d453ff2dfea Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 6 Oct 2016 12:41:18 +0300 Subject: [PATCH] project view: added action to mark a directory under excluded root as a new content root to cancel exclusion (IDEA-162102) --- .../actions/MarkAsContentRootAction.kt | 51 +++++++++++++++++++ .../actions/MarkRootActionBase.java | 6 ++- .../src/messages/ActionsBundle.properties | 2 + resources/src/idea/RichPlatformActions.xml | 1 + 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkAsContentRootAction.kt diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkAsContentRootAction.kt b/platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkAsContentRootAction.kt new file mode 100644 index 000000000000..2228bb399437 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkAsContentRootAction.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.projectView.actions + +import com.intellij.ide.projectView.impl.ProjectRootsUtil +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.project.DumbAwareAction +import com.intellij.openapi.roots.ModuleRootManager +import com.intellij.openapi.roots.ProjectRootManager + +/** + * @author nik + */ +class MarkAsContentRootAction : DumbAwareAction() { + override fun update(e: AnActionEvent) { + val files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY) + val module = MarkRootActionBase.getModule(e, files) + if (module == null || files == null) { + e.presentation.isEnabledAndVisible = false + return + } + val fileIndex = ProjectRootManager.getInstance(module.project).fileIndex + e.presentation.isEnabledAndVisible = files.all { + it.isDirectory && fileIndex.isExcluded(it) && ProjectRootsUtil.findExcludeFolder(module, it) == null + } + } + + override fun actionPerformed(e: AnActionEvent) { + val files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY) ?: return + val module = MarkRootActionBase.getModule(e, files) ?: return + val model = ModuleRootManager.getInstance(module).modifiableModel + files.forEach { + model.addContentEntry(it) + } + MarkRootActionBase.commitModel(module, model) + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkRootActionBase.java b/platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkRootActionBase.java index 4e7683e180b5..0c5d26fdaf15 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkRootActionBase.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/actions/MarkRootActionBase.java @@ -77,6 +77,10 @@ public abstract class MarkRootActionBase extends DumbAwareAction { modifyRoots(file, entry); } } + commitModel(module, model); + } + + static void commitModel(@NotNull Module module, ModifiableRootModel model) { DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> ApplicationManager.getApplication().runWriteAction(() -> { model.commit(); @@ -148,7 +152,7 @@ public abstract class MarkRootActionBase extends DumbAwareAction { } @Nullable - private static Module getModule(@NotNull AnActionEvent e, @Nullable VirtualFile[] files) { + static Module getModule(@NotNull AnActionEvent e, @Nullable VirtualFile[] files) { if (files == null) return null; Module module = e.getData(LangDataKeys.MODULE); if (module == null) { diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index af16c4e70ff2..0e44f01f5673 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -1476,6 +1476,8 @@ group.Vcs.Browse.text=Browse VCS Repository action.Graph.print.reset=Reset action.MarkExcludeRoot.text=Excluded action.UnmarkRoot.text=Unmark Root +action.MarkAsContentRoot.text=Cancel Exclusion +action.MarkAsContentRoot.description=Cancel exclusion for the selected directory to make its files processable by IDE's actions action.CreateLibraryFromFile.text=Add as Library... action.ImportModuleFromImlFile.text=Import Module action.ImportModuleFromImlFile.description=Import iml file as a module to the project diff --git a/resources/src/idea/RichPlatformActions.xml b/resources/src/idea/RichPlatformActions.xml index 8b01f1bc4930..f45f64028afc 100644 --- a/resources/src/idea/RichPlatformActions.xml +++ b/resources/src/idea/RichPlatformActions.xml @@ -390,6 +390,7 @@ +