project view: added action to mark a directory under excluded root as a new content root to cancel exclusion (IDEA-162102)

This commit is contained in:
nik
2016-10-06 12:41:41 +03:00
parent 07f1ec121e
commit c61d90531d
4 changed files with 59 additions and 1 deletions
@@ -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)
}
}
@@ -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) {
@@ -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
@@ -390,6 +390,7 @@
<group>
<group id="MarkSourceRootGroup" class="com.intellij.ide.projectView.actions.MarkSourceRootActionGroup"/>
<action id="MarkExcludeRoot" class="com.intellij.ide.projectView.actions.MarkExcludeRootAction" icon="AllIcons.Modules.ExcludeRoot"/>
<action id="MarkAsContentRoot" class="com.intellij.ide.projectView.actions.MarkAsContentRootAction"/>
<action id="UnmarkRoot" class="com.intellij.ide.projectView.actions.UnmarkRootAction"/>
<add-to-group group-id="MarkRootGroup"/>
</group>