mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs] ChangesTreeList: extract method for searching for file in tree
This commit is contained in:
@@ -26,6 +26,7 @@ import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.EmptyRunnable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
@@ -400,28 +401,10 @@ public abstract class ChangesTreeList<T> extends JPanel implements TypeSafeDataP
|
||||
}
|
||||
} else {
|
||||
if (toSelect != null) {
|
||||
ChangesBrowserNode root = (ChangesBrowserNode)model.getRoot();
|
||||
final int[] rowToSelect = new int[] {-1};
|
||||
TreeUtil.traverse(root, new TreeUtil.Traverse() {
|
||||
@Override
|
||||
public boolean accept(Object node) {
|
||||
if (node instanceof DefaultMutableTreeNode) {
|
||||
Object userObject = ((DefaultMutableTreeNode)node).getUserObject();
|
||||
if (userObject instanceof Change) {
|
||||
Change change = (Change)userObject;
|
||||
VirtualFile virtualFile = change.getVirtualFile();
|
||||
if ((virtualFile != null && virtualFile.equals(toSelect)) || seemsToBeMoved(change, toSelect)) {
|
||||
TreeNode[] path = ((DefaultMutableTreeNode)node).getPath();
|
||||
rowToSelect[0] = myTree.getRowForPath(new TreePath(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rowToSelect[0] == -1;
|
||||
}
|
||||
});
|
||||
|
||||
scrollRow = rowToSelect[0] == -1 ? scrollRow : rowToSelect[0];
|
||||
int rowInTree = findRowContainingFile((TreeNode)model.getRoot(), toSelect);
|
||||
if (rowInTree > -1) {
|
||||
scrollRow = rowInTree;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,6 +426,33 @@ public abstract class ChangesTreeList<T> extends JPanel implements TypeSafeDataP
|
||||
}
|
||||
}
|
||||
|
||||
private int findRowContainingFile(@NotNull TreeNode root, @Nullable final VirtualFile toSelect) {
|
||||
if (toSelect == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
final Ref<Integer> row = Ref.create(-1);
|
||||
TreeUtil.traverse(root, new TreeUtil.Traverse() {
|
||||
@Override
|
||||
public boolean accept(Object node) {
|
||||
if (node instanceof DefaultMutableTreeNode) {
|
||||
Object userObject = ((DefaultMutableTreeNode)node).getUserObject();
|
||||
if (userObject instanceof Change) {
|
||||
Change change = (Change)userObject;
|
||||
VirtualFile virtualFile = change.getVirtualFile();
|
||||
if ((virtualFile != null && virtualFile.equals(toSelect)) || seemsToBeMoved(change, toSelect)) {
|
||||
TreeNode[] path = ((DefaultMutableTreeNode)node).getPath();
|
||||
row.set(myTree.getRowForPath(new TreePath(path)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return row.get() == -1;
|
||||
}
|
||||
});
|
||||
return row.get();
|
||||
}
|
||||
|
||||
private static boolean seemsToBeMoved(Change change, VirtualFile toSelect) {
|
||||
ContentRevision afterRevision = change.getAfterRevision();
|
||||
if (afterRevision == null) return false;
|
||||
|
||||
Reference in New Issue
Block a user