From 6d46999c1a2d06d5ac8ef2df9ff4ec38122bbd36 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Thu, 25 May 2017 18:27:47 +0300 Subject: [PATCH] [project view] ProjectView.changeViewCB(viewId, subId) update LOG.error when view has no subviews but subId is not null. Select default subview when subId is null. If view had been selected then use last selected subview. If view had never been selected then select first subview. (IDEA-CR-21127) --- .../intellij/ide/projectView/ProjectView.java | 14 ++++++--- .../ide/projectView/impl/ProjectViewImpl.java | 31 ++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/ProjectView.java b/platform/lang-impl/src/com/intellij/ide/projectView/ProjectView.java index 2bb94e08d052..cc6916b8df6d 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/ProjectView.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/ProjectView.java @@ -39,13 +39,19 @@ public abstract class ProjectView { public abstract ActionCallback selectCB(Object element, VirtualFile file, boolean requestFocus); /** - * Changes currently selected view and subview (if any).
- * If a view (which is identified by {@code viewId}) has subviews but {@code subId} is {@code null} then no action is taken. + * Changes currently selected view and subview (if any). + *

+ * When default subview is requested:
+ * - if the view had never been selected then the first subview is selected
+ * - otherwise subview won't be changed + *

+ * It's an error when a view has no subviews and {@code subId} is not null. * - * @param subId subview id. {@code null} means view should not have subviews + * @param viewId id of view to be selected + * @param subId id of subview to be selected */ @NotNull - public abstract ActionCallback changeViewCB(@NotNull String viewId, @Nullable String subId); + public abstract ActionCallback changeViewCB(@NotNull String viewId, @Nullable("default subview") String subId); @Nullable public abstract PsiElement getParentOfCurrentSelection(); diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index 951dc118ff78..5ccdd2e85c2b 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -934,17 +934,34 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo @NotNull @Override - public ActionCallback changeViewCB(@NotNull String viewId, String subId) { + public ActionCallback changeViewCB(@NotNull String viewId, @Nullable String subId) { AbstractProjectViewPane pane = getProjectViewPaneById(viewId); LOG.assertTrue(pane != null, "Project view pane not found: " + viewId + "; subId:" + subId + "; project: " + myProject); - if (!viewId.equals(getCurrentViewId()) - || subId != null && !subId.equals(pane.getSubId())) { - for (Content content : getContentManager().getContents()) { - if (viewId.equals(content.getUserData(ID_KEY)) && StringUtil.equals(subId, content.getUserData(SUB_ID_KEY))) { - return getContentManager().setSelectedContentCB(content); - } + + boolean hasSubViews = pane.getSubIds().length > 0; + if (hasSubViews) { + if (subId == null) { + // we try not to change subview + // get currently selected subId from the pane + subId = pane.getSubId(); } } + else { + if (subId != null) { + LOG.error("View doesn't have subviews: " + viewId + "; subId:" + subId + "; project: " + myProject); + } + } + if (viewId.equals(myCurrentViewId) && Objects.equals(subId, myCurrentViewSubId)) return ActionCallback.REJECTED; + + // at this point null subId means that view has no subviews OR subview was never selected + // we then search first content with the right viewId ignoring subIds of contents + + for (Content content : getContentManager().getContents()) { + if (viewId.equals(content.getUserData(ID_KEY)) && (subId == null || subId.equals(content.getUserData(SUB_ID_KEY)))) { + return getContentManager().setSelectedContentCB(content); + } + } + return ActionCallback.REJECTED; }