From 08937a482e54594e2039f2f73217064362b2e690 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 9 May 2018 17:57:18 +0200 Subject: [PATCH] Improvements based on code review (IDEA-CR-32474) Add and use LocalChangeList.isBlank(), delete VcsDataKeys.CHANGES_IN_LIST, hide single default CL from scope chooser --- .../ChangeListsScopesProvider.java | 14 +++++++++++--- .../com/intellij/openapi/vcs/VcsDataKeys.java | 17 +---------------- .../openapi/vcs/changes/LocalChangeList.java | 19 ++++--------------- .../vcs/changes/ui/ChangesListView.java | 9 --------- .../ui/MultipleLocalChangeListsBrowser.java | 2 +- .../vcs/changes/ui/TreeModelBuilder.java | 10 ++++++++-- 6 files changed, 25 insertions(+), 46 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/packageDependencies/ChangeListsScopesProvider.java b/platform/lang-impl/src/com/intellij/packageDependencies/ChangeListsScopesProvider.java index b88a69ff24ec..23a3ce73ad46 100644 --- a/platform/lang-impl/src/com/intellij/packageDependencies/ChangeListsScopesProvider.java +++ b/platform/lang-impl/src/com/intellij/packageDependencies/ChangeListsScopesProvider.java @@ -3,8 +3,11 @@ package com.intellij.packageDependencies; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.changes.*; +import com.intellij.openapi.vcs.changes.ChangeList; +import com.intellij.openapi.vcs.changes.ChangeListManager; +import com.intellij.openapi.vcs.changes.LocalChangeList; import com.intellij.psi.search.scope.packageSet.CustomScopesProviderEx; import com.intellij.psi.search.scope.packageSet.NamedScope; import org.jetbrains.annotations.NotNull; @@ -37,8 +40,13 @@ public class ChangeListsScopesProvider extends CustomScopesProviderEx { final List result = new ArrayList<>(); result.add(new ChangeListScope(changeListManager)); - for (ChangeList list : changeListManager.getChangeListsCopy()) { - result.add(new ChangeListScope(changeListManager, list.getName())); + List changeLists = changeListManager.getChangeListsCopy(); + boolean skipSingleDefaultCL = Registry.is("vcs.skip.single.default.changelist") && + changeLists.size() == 1 && changeLists.get(0).isBlank(); + if (!skipSingleDefaultCL) { + for (ChangeList list : changeLists) { + result.add(new ChangeListScope(changeListManager, list.getName())); + } } return result; } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java index 2089654a5d62..9334e902b146 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs; @@ -54,7 +40,6 @@ public interface VcsDataKeys { DataKey> CHANGES_SELECTION = DataKey.create("vcs.ChangesSelection"); DataKey CHANGES_WITH_MOVED_CHILDREN = DataKey.create("ChangeListView.ChangesWithDetails"); DataKey SELECTED_CHANGES_IN_DETAILS = DataKey.create("ChangeListView.SelectedChangesWithMovedSubtrees"); - @NonNls DataKey> CHANGES_IN_LIST_KEY = DataKey.create("ChangeListView.ChangesInList"); @NonNls DataKey> MODIFIED_WITHOUT_EDITING_DATA_KEY = DataKey.create("ChangeListView.ModifiedWithoutEditing"); @NonNls DataKey HAVE_MODIFIED_WITHOUT_EDITING = DataKey.create("ChangeListView.HaveModifiedWithoutEditing"); @NonNls DataKey HAVE_LOCALLY_DELETED = DataKey.create("ChangeListView.HaveLocallyDeleted"); diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/LocalChangeList.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/LocalChangeList.java index b80ebe4209b6..82f482b8c7e1 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/LocalChangeList.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/LocalChangeList.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.vcs.changes; @@ -69,6 +55,9 @@ public abstract class LocalChangeList implements Cloneable, ChangeList { return DEFAULT_NAME.equals(getName()); } + public boolean isBlank() { + return hasDefaultName() && getData() == null; + } /** * Use {@link ChangeListManager#editName} diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesListView.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesListView.java index 4c9a625c7e73..31e9cf4edc41 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesListView.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesListView.java @@ -203,15 +203,6 @@ public class ChangesListView extends Tree implements TypeSafeDataProvider, DnDAw else if (key == PlatformDataKeys.HELP_ID) { sink.put(PlatformDataKeys.HELP_ID, HELP_ID); } - else if (key == VcsDataKeys.CHANGES_IN_LIST_KEY) { - final TreePath selectionPath = getSelectionPath(); - if (selectionPath != null && selectionPath.getPathCount() > 1) { - ChangesBrowserNode firstNode = (ChangesBrowserNode)selectionPath.getPathComponent(1); - if (firstNode instanceof ChangesBrowserChangeListNode) { - sink.put(VcsDataKeys.CHANGES_IN_LIST_KEY, firstNode.getAllChangesUnder()); - } - } - } else if (key == ChangesGroupingSupport.KEY) { sink.put(ChangesGroupingSupport.KEY, myGroupingSupport); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleLocalChangeListsBrowser.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleLocalChangeListsBrowser.java index abc4dea65c17..f04f24ebc18b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleLocalChangeListsBrowser.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/MultipleLocalChangeListsBrowser.java @@ -91,7 +91,7 @@ public class MultipleLocalChangeListsBrowser extends CommitDialogChangesBrowser if (Registry.is("vcs.skip.single.default.changelist")) { List allChangeLists = ChangeListManager.getInstance(project).getChangeLists(); - if (allChangeLists.size() == 1 && LocalChangeList.DEFAULT_NAME.equals(allChangeLists.get(0).getName())) { + if (allChangeLists.size() == 1 && allChangeLists.get(0).isBlank()) { myChangeListChooser.setVisible(false); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/TreeModelBuilder.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/TreeModelBuilder.java index b52e998cc8f0..05ac549ba1e0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/TreeModelBuilder.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/TreeModelBuilder.java @@ -189,8 +189,7 @@ public class TreeModelBuilder { @NotNull public TreeModelBuilder setChangeLists(@NotNull Collection changeLists, boolean skipSingleDefaultChangeList) { final RemoteRevisionsCache revisionsCache = RemoteRevisionsCache.getInstance(myProject); - boolean skipChangeListNode = skipSingleDefaultChangeList && changeLists.size() == 1 && - LocalChangeList.DEFAULT_NAME.equals(changeLists.iterator().next().getName()); + boolean skipChangeListNode = skipSingleDefaultChangeList && isSingleBlankChangeList(changeLists); for (ChangeList list : changeLists) { List changes = sorted(list.getChanges(), CHANGE_COMPARATOR); ChangeListRemoteState listRemoteState = new ChangeListRemoteState(changes.size()); @@ -216,6 +215,13 @@ public class TreeModelBuilder { return this; } + private static boolean isSingleBlankChangeList(Collection lists) { + if (lists.size() != 1) return false; + ChangeList single = lists.iterator().next(); + if (!(single instanceof LocalChangeList)) return false; + return ((LocalChangeList) single).isBlank(); + } + protected ChangesBrowserNode createChangeNode(Change change, ChangeNodeDecorator decorator) { return new ChangesBrowserChangeNode(myProject, change, decorator); }