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
This commit is contained in:
Konstantin Kolosovsky
2018-05-16 14:39:33 +03:00
parent 9ad768bd56
commit c258895a08
6 changed files with 49 additions and 101 deletions
@@ -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());
@@ -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
@@ -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();
@@ -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
@@ -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<ChangesListView> DATA_KEY = DataKey.create("ChangeListView");
@NonNls public static final DataKey<Stream<VirtualFile>> 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<List<LocallyDeletedChange>> 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<Change> 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
@@ -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;