'Project Structure' dialog: show unloaded modules as disabled items in 'Find Usages' popup (IDEA-174404)

This commit is contained in:
nik
2017-06-14 13:02:01 +02:00
parent dce36ba559
commit e529fa6a12
5 changed files with 36 additions and 3 deletions
@@ -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<ProjectStructureElementUsage>(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());
}
@@ -29,6 +29,10 @@ public abstract class PlaceInProjectStructure {
@Nullable
public abstract String getPlacePath();
public boolean canNavigate() {
return true;
}
@NotNull
public abstract ActionCallback navigate();
}
@@ -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() {
@@ -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
@@ -32,6 +32,7 @@ public abstract class ListCellRendererWithRightAlignedComponent<T> 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<T> implements Li
public void customize(JList list, T value, int index, boolean selected, boolean hasFocus) {
setText(myLeftText);
setIcon(myIcon);
setForeground(myLeftForeground);
}
};
myRightRenderer = new ListCellRendererWrapper<T>() {
@@ -89,6 +91,10 @@ public abstract class ListCellRendererWithRightAlignedComponent<T> implements Li
myRightText = text;
}
protected final void setLeftForeground(Color color) {
myLeftForeground = color;
}
protected final void setRightForeground(Color color) {
myRightForeground = color;
}