mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: do not pass invalid file pointers to data context
This commit is contained in:
committed by
Aleksey Pivovarov
parent
437c1520db
commit
bb67875b64
@@ -62,8 +62,8 @@ public interface VcsDataKeys {
|
||||
DataKey<Change[]> SELECTED_CHANGES = DataKey.create("ChangeListView.SelectedChange");
|
||||
DataKey<Boolean> HAVE_SELECTED_CHANGES = DataKey.create("ChangeListView.HaveSelectedChanges");
|
||||
DataKey<Change[]> CHANGE_LEAD_SELECTION = DataKey.create("ChangeListView.ChangeLeadSelection");
|
||||
DataKey<String> UPDATE_VIEW_SELECTED_PATH = DataKey.create("AbstractCommonUpdateAction.UpdateViewSelectedPath");
|
||||
DataKey<Iterable<Pair<VirtualFilePointer, FileStatus>>> UPDATE_VIEW_FILES_ITERABLE = DataKey.create("AbstractCommonUpdateAction.UpdatedFilesIterable");
|
||||
DataKey<FilePath> UPDATE_VIEW_SELECTED_PATH = DataKey.create("AbstractCommonUpdateAction.UpdateViewSelectedPath");
|
||||
DataKey<Iterable<Pair<FilePath, FileStatus>>> UPDATE_VIEW_FILES_ITERABLE = DataKey.create("AbstractCommonUpdateAction.UpdatedFilesIterable");
|
||||
DataKey<Object> LABEL_BEFORE = DataKey.create("LABEL_BEFORE");
|
||||
DataKey<Object> LABEL_AFTER = DataKey.create("LABEL_AFTER");
|
||||
DataKey<String> PRESET_COMMIT_MESSAGE = DataKey.create("PRESET_COMMIT_MESSAGE");
|
||||
|
||||
@@ -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<Pair<VirtualFilePointer, FileStatus>> iterable = VcsDataKeys.UPDATE_VIEW_FILES_ITERABLE.getData(dc);
|
||||
final Iterable<Pair<FilePath, FileStatus>> 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<Pair<VirtualFilePointer, FileStatus>> iterable = e.getRequiredData(VcsDataKeys.UPDATE_VIEW_FILES_ITERABLE);
|
||||
final Iterable<Pair<FilePath, FileStatus>> 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<Pair<VirtualFilePointer, FileStatus>> iterable,
|
||||
@NotNull Iterable<Pair<FilePath, FileStatus>> iterable,
|
||||
@NotNull Label before,
|
||||
@NotNull Label after,
|
||||
@Nullable String selectedUrl) {
|
||||
@Nullable FilePath selectedPath) {
|
||||
myProject = project;
|
||||
myBefore = before;
|
||||
myAfter = after;
|
||||
|
||||
int selected = -1;
|
||||
for (Pair<VirtualFilePointer, FileStatus> pair : iterable) {
|
||||
if (selected == -1 && pair.first.getUrl().equals(selectedUrl)) selected = myRequests.size();
|
||||
for (Pair<FilePath, FileStatus> 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
|
||||
|
||||
@@ -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<Pair<VirtualFilePointer, FileStatus>> {
|
||||
private class MyTreeIterator implements Iterator<Pair<FilePath, FileStatus>> {
|
||||
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<VirtualFilePointer, FileStatus> next() {
|
||||
final VirtualFilePointer result = myNext;
|
||||
public Pair<FilePath, FileStatus> 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<Pair<VirtualFilePointer, FileStatus>> {
|
||||
public Iterator<Pair<VirtualFilePointer, FileStatus>> iterator() {
|
||||
private class MyTreeIterable implements Iterable<Pair<FilePath, FileStatus>> {
|
||||
public Iterator<Pair<FilePath, FileStatus>> 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user