From bb67875b64fca8754f0d196eec6dfd0266948ab4 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 5 Apr 2017 18:40:06 +0300 Subject: [PATCH] vcs: do not pass invalid file pointers to data context --- .../com/intellij/openapi/vcs/VcsDataKeys.java | 4 +-- .../vcs/update/ShowUpdatedDiffAction.java | 25 ++++++--------- .../openapi/vcs/update/UpdateInfoTree.java | 32 ++++++++++++------- 3 files changed, 33 insertions(+), 28 deletions(-) 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 c7b943d0a89c..3dc1bab2449f 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/VcsDataKeys.java @@ -62,8 +62,8 @@ public interface VcsDataKeys { DataKey SELECTED_CHANGES = DataKey.create("ChangeListView.SelectedChange"); DataKey HAVE_SELECTED_CHANGES = DataKey.create("ChangeListView.HaveSelectedChanges"); DataKey CHANGE_LEAD_SELECTION = DataKey.create("ChangeListView.ChangeLeadSelection"); - DataKey UPDATE_VIEW_SELECTED_PATH = DataKey.create("AbstractCommonUpdateAction.UpdateViewSelectedPath"); - DataKey>> UPDATE_VIEW_FILES_ITERABLE = DataKey.create("AbstractCommonUpdateAction.UpdatedFilesIterable"); + DataKey UPDATE_VIEW_SELECTED_PATH = DataKey.create("AbstractCommonUpdateAction.UpdateViewSelectedPath"); + DataKey>> UPDATE_VIEW_FILES_ITERABLE = DataKey.create("AbstractCommonUpdateAction.UpdatedFilesIterable"); DataKey LABEL_BEFORE = DataKey.create("LABEL_BEFORE"); DataKey LABEL_AFTER = DataKey.create("LABEL_AFTER"); DataKey PRESET_COMMIT_MESSAGE = DataKey.create("PRESET_COMMIT_MESSAGE"); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/ShowUpdatedDiffAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/ShowUpdatedDiffAction.java index 60a7d90df05b..ec6d7263233c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/ShowUpdatedDiffAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/ShowUpdatedDiffAction.java @@ -40,9 +40,7 @@ import com.intellij.openapi.vcs.FilePath; import com.intellij.openapi.vcs.FileStatus; import com.intellij.openapi.vcs.VcsDataKeys; import com.intellij.openapi.vcs.changes.actions.diff.ChangeGoToChangePopupAction; -import com.intellij.openapi.vfs.pointers.VirtualFilePointer; import com.intellij.util.Consumer; -import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,7 +65,7 @@ public class ShowUpdatedDiffAction extends AnAction implements DumbAware { } private boolean isEnabled(final DataContext dc) { - final Iterable> iterable = VcsDataKeys.UPDATE_VIEW_FILES_ITERABLE.getData(dc); + final Iterable> iterable = VcsDataKeys.UPDATE_VIEW_FILES_ITERABLE.getData(dc); return iterable != null; } @@ -76,10 +74,10 @@ public class ShowUpdatedDiffAction extends AnAction implements DumbAware { if ((!isVisible(dc)) || (!isEnabled(dc))) return; final Project project = CommonDataKeys.PROJECT.getData(dc); - final Iterable> iterable = e.getRequiredData(VcsDataKeys.UPDATE_VIEW_FILES_ITERABLE); + final Iterable> iterable = e.getRequiredData(VcsDataKeys.UPDATE_VIEW_FILES_ITERABLE); final Label before = (Label)e.getRequiredData(VcsDataKeys.LABEL_BEFORE); final Label after = (Label)e.getRequiredData(VcsDataKeys.LABEL_AFTER); - final String selectedUrl = VcsDataKeys.UPDATE_VIEW_SELECTED_PATH.getData(dc); + final FilePath selectedUrl = VcsDataKeys.UPDATE_VIEW_SELECTED_PATH.getData(dc); MyDiffRequestChain requestChain = new MyDiffRequestChain(project, iterable, before, after, selectedUrl); DiffManager.getInstance().showDiff(project, requestChain, DiffDialogHints.FRAME); @@ -94,17 +92,17 @@ public class ShowUpdatedDiffAction extends AnAction implements DumbAware { private int myIndex; public MyDiffRequestChain(@Nullable Project project, - @NotNull Iterable> iterable, + @NotNull Iterable> iterable, @NotNull Label before, @NotNull Label after, - @Nullable String selectedUrl) { + @Nullable FilePath selectedPath) { myProject = project; myBefore = before; myAfter = after; int selected = -1; - for (Pair pair : iterable) { - if (selected == -1 && pair.first.getUrl().equals(selectedUrl)) selected = myRequests.size(); + for (Pair pair : iterable) { + if (selected == -1 && pair.first.equals(selectedPath)) selected = myRequests.size(); myRequests.add(new MyDiffRequestProducer(pair.first, pair.second)); } if (selected != -1) myIndex = selected; @@ -145,21 +143,18 @@ public class ShowUpdatedDiffAction extends AnAction implements DumbAware { } private class MyDiffRequestProducer implements DiffRequestProducer { - @NotNull private final String myName; @NotNull private final FileStatus myFileStatus; @NotNull private final FilePath myFilePath; - public MyDiffRequestProducer(@NotNull VirtualFilePointer filePointer, @NotNull FileStatus fileStatus) { - myName = filePointer.getPresentableUrl(); + public MyDiffRequestProducer(@NotNull FilePath filePath, @NotNull FileStatus fileStatus) { myFileStatus = fileStatus; - - myFilePath = VcsUtil.getFilePath(filePointer.getPresentableUrl(), false); + myFilePath = filePath; } @NotNull @Override public String getName() { - return myName; + return myFilePath.getPresentableUrl(); } @NotNull diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java index 8b0cc6f78dce..690ef5c930d0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/update/UpdateInfoTree.java @@ -19,7 +19,6 @@ import com.intellij.history.Label; import com.intellij.icons.AllIcons; import com.intellij.ide.DefaultTreeExpander; import com.intellij.ide.TreeExpander; -import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileEditor.OpenFileDescriptor; @@ -50,6 +49,7 @@ import com.intellij.util.PlatformIcons; import com.intellij.util.containers.Convertor; import com.intellij.util.ui.StatusText; import com.intellij.util.ui.tree.TreeUtil; +import com.intellij.vcsUtil.VcsUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -69,7 +69,7 @@ import java.util.List; public class UpdateInfoTree extends PanelWithActionsAndCloseButton { private VirtualFile mySelectedFile; - private String mySelectedUrl; + private FilePath mySelectedUrl; private final Tree myTree = new Tree(); @NotNull private final Project myProject; private final UpdatedFiles myUpdatedFiles; @@ -178,9 +178,10 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { VirtualFilePointer pointer = null; if (treeNode instanceof FileTreeNode) { pointer = ((FileTreeNode)treeNode).getFilePointer(); + if (!pointer.isValid()) pointer = null; } if (pointer != null) { - mySelectedUrl = pointer.getUrl(); + mySelectedUrl = getFilePath(pointer); mySelectedFile = pointer.getFile(); } else { @@ -266,9 +267,9 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { return super.getData(dataId); } - private class MyTreeIterator implements Iterator> { + private class MyTreeIterator implements Iterator> { private final Enumeration myEnum; - private VirtualFilePointer myNext; + private FilePath myNext; private FileStatus myStatus; private MyTreeIterator() { @@ -280,8 +281,8 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { return myNext != null; } - public Pair next() { - final VirtualFilePointer result = myNext; + public Pair next() { + final FilePath result = myNext; final FileStatus status = myStatus; step(); return Pair.create(result, status); @@ -293,7 +294,10 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { final Object o = myEnum.nextElement(); if (o instanceof FileTreeNode) { final FileTreeNode treeNode = (FileTreeNode)o; - myNext = treeNode.getFilePointer(); + VirtualFilePointer filePointer = treeNode.getFilePointer(); + if (!filePointer.isValid()) continue; + + myNext = getFilePath(filePointer); myStatus = FileStatus.MODIFIED; final GroupTreeNode parent = findParentGroupTreeNode(treeNode.getParent()); @@ -301,7 +305,8 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { final String id = parent.getFileGroupId(); if (FileGroup.CREATED_ID.equals(id)) { myStatus = FileStatus.ADDED; - } else if (FileGroup.REMOVED_FROM_REPOSITORY_ID.equals(id)) { + } + else if (FileGroup.REMOVED_FROM_REPOSITORY_ID.equals(id)) { myStatus = FileStatus.DELETED; } } @@ -324,8 +329,8 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { } } - private class MyTreeIterable implements Iterable> { - public Iterator> iterator() { + private class MyTreeIterable implements Iterable> { + public Iterator> iterator() { return new MyTreeIterator(); } } @@ -486,4 +491,9 @@ public class UpdateInfoTree extends PanelWithActionsAndCloseButton { e.getPresentation().setEnabled(!myGroupByChangeList && VcsConfiguration.getInstance(myProject).UPDATE_FILTER_SCOPE_NAME != null); } } + + @NotNull + private static FilePath getFilePath(@NotNull VirtualFilePointer filePointer) { + return VcsUtil.getFilePath(filePointer.getPresentableUrl(), false); + } }