From c258895a0887ea06d87ce736991c2364dc4d22fb Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Wed, 16 May 2018 00:22:10 +0300 Subject: [PATCH] vcs: Make "ChangesListView" extend "ChangesTree" This allows to: * remove some duplicated code * have checkboxes in local changes * show file scope background color in local changes - IDEA-120755 --- .../vcs/changes/ChangesViewManager.java | 2 +- .../vcs/changes/IgnoredViewDialog.java | 18 +--- .../vcs/changes/SpecificFilesViewDialog.java | 8 +- .../vcs/changes/UnversionedViewDialog.java | 18 +--- .../vcs/changes/ui/ChangesListView.java | 95 ++++++------------- .../openapi/vcs/changes/ui/ChangesTree.java | 9 ++ 6 files changed, 49 insertions(+), 101 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java index 9e88ad090f04..269e18bc38c3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java @@ -201,7 +201,7 @@ public class ChangesViewManager implements ChangesViewI, ProjectComponent, Persi ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.CHANGES_VIEW_TOOLBAR, group, false); toolbar.setTargetComponent(myView); - myView.setMenuActions((DefaultActionGroup)ActionManager.getInstance().getAction("ChangesViewPopupMenu")); + myView.installPopupHandler((DefaultActionGroup)ActionManager.getInstance().getAction("ChangesViewPopupMenu")); myView.getGroupingSupport().setGroupingKeysOrSkip(myState.groupingKeys); myProgressLabel = new JPanel(new BorderLayout()); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredViewDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredViewDialog.java index 9c31fed4bee3..441ca9cec4b9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredViewDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/IgnoredViewDialog.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// 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; import com.intellij.openapi.actionSystem.AnAction; @@ -37,7 +23,7 @@ public class IgnoredViewDialog extends SpecificFilesViewDialog { AnAction deleteAction = EmptyAction.registerWithShortcutSet("ChangesView.DeleteUnversioned", CommonShortcuts.getDelete(), myView); group.add(deleteAction); - myView.setMenuActions(new DefaultActionGroup(deleteAction)); + myView.installPopupHandler(new DefaultActionGroup(deleteAction)); } @NotNull diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SpecificFilesViewDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SpecificFilesViewDialog.java index 5b5e0c22d7fd..2d4b7fbc4468 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SpecificFilesViewDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/SpecificFilesViewDialog.java @@ -61,10 +61,14 @@ abstract class SpecificFilesViewDialog extends DialogWrapper { } @Override - protected void editSourceRegistration() { - EditSourceOnDoubleClickHandler.install(this, closer); + protected void installEnterKeyHandler() { EditSourceOnEnterKeyHandler.install(this, closer); } + + @Override + protected void installDoubleClickHandler() { + EditSourceOnDoubleClickHandler.install(this, closer); + } }; myChangeListManager = ChangeListManager.getInstance(project); createPanel(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UnversionedViewDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UnversionedViewDialog.java index 2773862807ed..6846684b18c6 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UnversionedViewDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/UnversionedViewDialog.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2010 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; import com.intellij.openapi.actionSystem.*; @@ -43,7 +29,7 @@ public class UnversionedViewDialog extends SpecificFilesViewDialog { group.add(toolbarGroup); - myView.setMenuActions(popupGroup); + myView.installPopupHandler(popupGroup); } @NotNull 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 9eaec2eb24d4..0aa8cada45c6 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 @@ -1,7 +1,6 @@ // 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.ui; -import com.intellij.ide.CopyProvider; import com.intellij.ide.dnd.DnDAware; import com.intellij.ide.util.treeView.TreeState; import com.intellij.openapi.actionSystem.*; @@ -13,12 +12,8 @@ import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.VcsDataKeys; import com.intellij.openapi.vcs.changes.*; -import com.intellij.openapi.vcs.changes.issueLinks.TreeLinkMouseListener; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.PopupHandler; -import com.intellij.ui.SmartExpander; -import com.intellij.ui.TreeSpeedSearch; -import com.intellij.ui.treeStructure.Tree; import com.intellij.util.EditSourceOnDoubleClickHandler; import com.intellij.util.EditSourceOnEnterKeyHandler; import com.intellij.util.containers.ContainerUtil; @@ -34,7 +29,6 @@ import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.MouseEvent; -import java.beans.PropertyChangeListener; import java.util.*; import java.util.List; import java.util.function.Predicate; @@ -48,11 +42,7 @@ import static com.intellij.util.containers.UtilKt.stream; import static java.util.stream.Collectors.toList; // TODO: Check if we could extend DnDAwareTree here instead of directly implementing DnDAware -public class ChangesListView extends Tree implements DataProvider, DnDAware { - private final Project myProject; - private final CopyProvider myCopyProvider; - @NotNull private final ChangesGroupingSupport myGroupingSupport; - +public class ChangesListView extends ChangesTree implements DataProvider, DnDAware { @NonNls public static final String HELP_ID = "ideaInterface.changes"; @NonNls public static final DataKey DATA_KEY = DataKey.create("ChangeListView"); @NonNls public static final DataKey> UNVERSIONED_FILES_DATA_KEY = DataKey.create("ChangeListView.UnversionedFiles"); @@ -61,23 +51,29 @@ public class ChangesListView extends Tree implements DataProvider, DnDAware { @NonNls public static final DataKey> LOCALLY_DELETED_CHANGES = DataKey.create("ChangeListView.LocallyDeletedChanges"); public ChangesListView(@NotNull Project project) { - myProject = project; - myGroupingSupport = new ChangesGroupingSupport(myProject, this, true); - - setModel(TreeModelBuilder.buildEmpty(project)); - - setShowsRootHandles(true); - setRootVisible(false); + super(project, false, true); setDragEnabled(true); + } - myCopyProvider = new ChangesBrowserNodeCopyProvider(this); + @Override + protected void installEnterKeyHandler() { + EditSourceOnEnterKeyHandler.install(this); + } - ChangesBrowserNodeRenderer renderer = new ChangesBrowserNodeRenderer(project, this::isShowFlatten, true); - setCellRenderer(renderer); + @Override + protected void installDoubleClickHandler() { + EditSourceOnDoubleClickHandler.install(this); + } - new TreeSpeedSearch(this, TO_TEXT_CONVERTER); - SmartExpander.installOn(this); - new TreeLinkMouseListener(renderer).installOn(this); + @NotNull + @Override + protected ChangesGroupingSupport installGroupingSupport() { + return new ChangesGroupingSupport(myProject, this, true); + } + + @Override + public int getToggleClickCount() { + return 2; } @Override @@ -85,28 +81,6 @@ public class ChangesListView extends Tree implements DataProvider, DnDAware { return (DefaultTreeModel)super.getModel(); } - public void addGroupingChangeListener(@NotNull PropertyChangeListener listener) { - myGroupingSupport.addPropertyChangeListener(listener); - } - - public void removeGroupingChangeListener(@NotNull PropertyChangeListener listener) { - myGroupingSupport.removePropertyChangeListener(listener); - } - - @NotNull - public ChangesGroupingSupport getGroupingSupport() { - return myGroupingSupport; - } - - @NotNull - public ChangesGroupingPolicyFactory getGrouping() { - return myGroupingSupport.getGrouping(); - } - - public boolean isShowFlatten() { - return !myGroupingSupport.isDirectory(); - } - public void updateModel(@NotNull DefaultTreeModel newModel) { TreeState state = TreeState.createOn(this, getRoot()); state.setScrollToSelection(false); @@ -118,6 +92,11 @@ public class ChangesListView extends Tree implements DataProvider, DnDAware { expandDefaultChangeList(oldRoot, newRoot); } + @Override + public void rebuildTree() { + // currently not used in ChangesListView code flow + } + private void expandDefaultChangeList(ChangesBrowserNode oldRoot, ChangesBrowserNode root) { if (oldRoot.getFileCount() != 0) return; if (TreeUtil.collectExpandedPaths(this).size() != 1) return; @@ -172,9 +151,6 @@ public class ChangesListView extends Tree implements DataProvider, DnDAware { ? new VirtualFileDeleteProvider() : null; } - if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) { - return myCopyProvider; - } if (UNVERSIONED_FILES_DATA_KEY.is(dataId)) { return getSelectedUnversionedFiles(); } @@ -202,10 +178,7 @@ public class ChangesListView extends Tree implements DataProvider, DnDAware { if (PlatformDataKeys.HELP_ID.is(dataId)) { return HELP_ID; } - if (ChangesGroupingSupport.KEY.is(dataId)) { - return myGroupingSupport; - } - return null; + return super.getData(dataId); } @NotNull @@ -346,11 +319,6 @@ public class ChangesListView extends Tree implements DataProvider, DnDAware { .filter(new DistinctChangePredicate()); } - @NotNull - public ChangesBrowserNode getRoot() { - return (ChangesBrowserNode)getModel().getRoot(); - } - @NotNull public Stream getChanges() { return getRoot().getObjectsUnderStream(Change.class); @@ -384,14 +352,9 @@ public class ChangesListView extends Tree implements DataProvider, DnDAware { .distinct(); } - public void setMenuActions(final ActionGroup menuGroup) { - PopupHandler.installPopupHandler(this, menuGroup, ActionPlaces.CHANGES_VIEW_POPUP, ActionManager.getInstance()); - editSourceRegistration(); - } - - protected void editSourceRegistration() { - EditSourceOnDoubleClickHandler.install(this); - EditSourceOnEnterKeyHandler.install(this); + @Override + public void installPopupHandler(@NotNull ActionGroup group) { + PopupHandler.installPopupHandler(this, group, ActionPlaces.CHANGES_VIEW_POPUP, ActionManager.getInstance()); } @Override diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java index 1d616393344d..ca72a6fa76aa 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTree.java @@ -48,6 +48,7 @@ import javax.swing.plaf.basic.BasicTreeUI; import javax.swing.tree.*; import java.awt.*; import java.awt.event.*; +import java.beans.PropertyChangeListener; import java.util.*; import java.util.List; @@ -233,6 +234,14 @@ public abstract class ChangesTree extends Tree implements DataProvider { return this; } + public void addGroupingChangeListener(@NotNull PropertyChangeListener listener) { + myGroupingSupport.addPropertyChangeListener(listener); + } + + public void removeGroupingChangeListener(@NotNull PropertyChangeListener listener) { + myGroupingSupport.removePropertyChangeListener(listener); + } + @NotNull public ChangesGroupingSupport getGroupingSupport() { return myGroupingSupport;