From e529fa6a127b584a1827baba0293dade69f25c0e Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 14 Jun 2017 12:56:58 +0200 Subject: [PATCH] 'Project Structure' dialog: show unloaded modules as disabled items in 'Find Usages' popup (IDEA-174404) --- .../FindUsagesInProjectStructureActionBase.java | 16 ++++++++++++++-- .../daemon/PlaceInProjectStructure.java | 4 ++++ .../daemon/PlaceInProjectStructureBase.java | 11 +++++++++++ .../daemon/UsagesInUnloadedModules.java | 2 +- ...istCellRendererWithRightAlignedComponent.java | 6 ++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FindUsagesInProjectStructureActionBase.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FindUsagesInProjectStructureActionBase.java index 29c1197e4212..6af178f3a638 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FindUsagesInProjectStructureActionBase.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/FindUsagesInProjectStructureActionBase.java @@ -24,6 +24,7 @@ import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; +import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.PlaceInProjectStructure; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElementUsage; import com.intellij.openapi.ui.Messages; @@ -32,6 +33,7 @@ import com.intellij.openapi.ui.popup.util.BaseListPopupStep; import com.intellij.ui.ListCellRendererWithRightAlignedComponent; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.popup.list.ListPopupImpl; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,7 +41,6 @@ import javax.swing.*; import java.awt.*; import java.util.Arrays; import java.util.Collection; -import java.util.Comparator; /** * @author nik @@ -81,10 +82,20 @@ public abstract class FindUsagesInProjectStructureActionBase extends AnAction im new BaseListPopupStep(ProjectBundle.message("dependencies.used.in.popup.title"), usagesArray) { @Override public PopupStep onChosen(final ProjectStructureElementUsage selected, final boolean finalChoice) { - selected.getPlace().navigate(); + PlaceInProjectStructure place = selected.getPlace(); + if (place.canNavigate()) { + place.navigate(); + } return FINAL_CHOICE; } + @Override + public boolean isSelectable(ProjectStructureElementUsage value) { + //todo[nik] currently non-selectable items in popup don't work in dialogs (IDEA-174448) + //return value.getPlace().canNavigate(); + return true; + } + @NotNull @Override public String getTextFor(ProjectStructureElementUsage value) { @@ -104,6 +115,7 @@ public abstract class FindUsagesInProjectStructureActionBase extends AnAction im protected void customize(ProjectStructureElementUsage value) { setLeftText(value.getPresentableName()); setIcon(value.getIcon()); + setLeftForeground(value.getPlace().canNavigate() ? UIUtil.getLabelTextForeground() : UIUtil.getLabelDisabledForeground()); setRightForeground(Color.GRAY); setRightText(value.getPresentableLocationInElement()); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/PlaceInProjectStructure.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/PlaceInProjectStructure.java index 03cf009b1b68..afd895fb6595 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/PlaceInProjectStructure.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/PlaceInProjectStructure.java @@ -29,6 +29,10 @@ public abstract class PlaceInProjectStructure { @Nullable public abstract String getPlacePath(); + public boolean canNavigate() { + return true; + } + @NotNull public abstract ActionCallback navigate(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/PlaceInProjectStructureBase.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/PlaceInProjectStructureBase.java index 4331c5f88b69..695026928b6b 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/PlaceInProjectStructureBase.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/PlaceInProjectStructureBase.java @@ -28,11 +28,17 @@ public class PlaceInProjectStructureBase extends PlaceInProjectStructure { private final Project myProject; private final Place myPlace; private final ProjectStructureElement myElement; + private boolean myCanNavigate; public PlaceInProjectStructureBase(Project project, Place place, ProjectStructureElement element) { + this(project, place, element, true); + } + + public PlaceInProjectStructureBase(Project project, Place place, ProjectStructureElement element, boolean navigate) { myProject = project; myPlace = place; myElement = element; + myCanNavigate = navigate; } @Override @@ -40,6 +46,11 @@ public class PlaceInProjectStructureBase extends PlaceInProjectStructure { return null; } + @Override + public boolean canNavigate() { + return myCanNavigate; + } + @NotNull @Override public ProjectStructureElement getContainingElement() { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/UsagesInUnloadedModules.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/UsagesInUnloadedModules.java index ba3ca5ded75b..502a63945c59 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/UsagesInUnloadedModules.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/daemon/UsagesInUnloadedModules.java @@ -65,7 +65,7 @@ public class UsagesInUnloadedModules extends ProjectStructureElementUsage { @Override public PlaceInProjectStructure getPlace() { Place configurablePlace = ProjectStructureConfigurable.getInstance(myContext.getProject()).createProjectConfigurablePlace(); - return new PlaceInProjectStructureBase(myContext.getProject(), configurablePlace, myContainingElement); + return new PlaceInProjectStructureBase(myContext.getProject(), configurablePlace, myContainingElement, false); } @Override diff --git a/platform/platform-impl/src/com/intellij/ui/ListCellRendererWithRightAlignedComponent.java b/platform/platform-impl/src/com/intellij/ui/ListCellRendererWithRightAlignedComponent.java index 2eba308d8a06..c3343d0396a8 100644 --- a/platform/platform-impl/src/com/intellij/ui/ListCellRendererWithRightAlignedComponent.java +++ b/platform/platform-impl/src/com/intellij/ui/ListCellRendererWithRightAlignedComponent.java @@ -32,6 +32,7 @@ public abstract class ListCellRendererWithRightAlignedComponent implements Li private String myRightText; private Icon myIcon; private Icon myRightIcon; + private Color myLeftForeground; private Color myRightForeground; public ListCellRendererWithRightAlignedComponent() { @@ -41,6 +42,7 @@ public abstract class ListCellRendererWithRightAlignedComponent implements Li public void customize(JList list, T value, int index, boolean selected, boolean hasFocus) { setText(myLeftText); setIcon(myIcon); + setForeground(myLeftForeground); } }; myRightRenderer = new ListCellRendererWrapper() { @@ -89,6 +91,10 @@ public abstract class ListCellRendererWithRightAlignedComponent implements Li myRightText = text; } + protected final void setLeftForeground(Color color) { + myLeftForeground = color; + } + protected final void setRightForeground(Color color) { myRightForeground = color; }