VCS: Don't query for revision content in AWT thread.

This commit is contained in:
Kirill Likhodedov
2011-08-02 20:18:44 +04:00
parent 32eb9e03c1
commit 0ace2bf281
2 changed files with 51 additions and 29 deletions
@@ -85,7 +85,7 @@ public class ChangeDiffRequest implements ChangeRequestChain {
} }
@Nullable @Nullable
public DiffRequest init(final int idx) throws VcsException { public DiffRequest init(final int idx) {
if (idx < 0 || idx > (mySteps.size() - 1)) return null; if (idx < 0 || idx > (mySteps.size() - 1)) return null;
myIndex = idx - 1; myIndex = idx - 1;
final DiffRequest result = moveForward(); final DiffRequest result = moveForward();
@@ -19,6 +19,7 @@ import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diff.*; import com.intellij.openapi.diff.*;
import com.intellij.openapi.diff.impl.external.BinaryDiffTool; import com.intellij.openapi.diff.impl.external.BinaryDiffTool;
@@ -201,18 +202,22 @@ public class ShowDiffAction extends AnAction implements DumbAware {
}), newIndex, context); }), newIndex, context);
} }
public static void showDiffForChange(final Change[] changes, int index, final Project project, @NotNull ShowDiffUIContext context) { public static void showDiffForChange(final Change[] changes, final int index, final Project project, @NotNull final ShowDiffUIContext context) {
final Change selected = index >= 0 ? changes[index] : null; ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
if (isBinaryDiff(project, changes, index)) { public void run() {
showBinaryDiff(project, changes[index]); final Change selected = index >= 0 ? changes[index] : null;
return; if (isBinaryDiff(project, changes, index)) {
} showBinaryDiff(project, changes[index]);
showDiffForChange(Arrays.asList(changes), new Condition<Change>() { return;
@Override }
public boolean value(final Change change) { showDiffForChange(Arrays.asList(changes), new Condition<Change>() {
return selected == null ? false : selected.equals(change); @Override
} public boolean value(final Change change) {
}, project, context); return selected == null ? false : selected.equals(change);
}
}, project, context);
}
});
} }
private static FileContent createBinaryFileContent(final Project project, final ContentRevision contentRevision, final String fileName) private static FileContent createBinaryFileContent(final Project project, final ContentRevision contentRevision, final String fileName)
@@ -260,11 +265,19 @@ public class ShowDiffAction extends AnAction implements DumbAware {
try { try {
final SimpleDiffRequest request = createBinaryDiffRequest(project, change); final SimpleDiffRequest request = createBinaryDiffRequest(project, change);
if (DiffManager.getInstance().getDiffTool().canShow(request)) { if (DiffManager.getInstance().getDiffTool().canShow(request)) {
DiffManager.getInstance().getDiffTool().show(request); ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override public void run() {
DiffManager.getInstance().getDiffTool().show(request);
}
});
} }
} }
catch (VcsException e) { catch (final VcsException e) {
Messages.showWarningDialog(e.getMessage(), "Show Diff"); ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override public void run() {
Messages.showWarningDialog(e.getMessage(), "Show Diff");
}
});
} }
} }
@@ -289,26 +302,35 @@ public class ShowDiffAction extends AnAction implements DumbAware {
return isBinaryChange(change) && (change.getAfterRevision() == null || BinaryDiffTool.canShow(project, change.getVirtualFile())); return isBinaryChange(change) && (change.getAfterRevision() == null || BinaryDiffTool.canShow(project, change.getVirtualFile()));
} }
public static void showDiffImpl(final Project project, List<DiffRequestPresentable> changeList, int index, @NotNull final ShowDiffUIContext context) { public static void showDiffImpl(final Project project, List<DiffRequestPresentable> changeList, final int index, @NotNull final ShowDiffUIContext context) {
final ChangeDiffRequest request = new ChangeDiffRequest(project, changeList, context.getActionsFactory(), context.isShowFrame()); final ChangeDiffRequest request = new ChangeDiffRequest(project, changeList, context.getActionsFactory(), context.isShowFrame());
final DiffTool tool = DiffManager.getInstance().getDiffTool(); final DiffTool tool = DiffManager.getInstance().getDiffTool();
final DiffRequest simpleRequest;
try { try {
request.quickCheckHaveStuff(); request.quickCheckHaveStuff();
simpleRequest = request.init(index);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
final DiffRequest simpleRequest = request.init(index);
if (simpleRequest != null) {
final DiffNavigationContext navigationContext = context.getDiffNavigationContext();
if (navigationContext != null) {
simpleRequest.passForDataContext(DiffTool.SCROLL_TO_LINE, navigationContext);
}
tool.show(simpleRequest);
}
}
});
} }
catch (VcsException e) { catch (final VcsException e) {
Messages.showWarningDialog(e.getMessage(), "Show Diff"); ApplicationManager.getApplication().invokeLater(new Runnable() {
return; @Override public void run() {
Messages.showWarningDialog(e.getMessage(), "Show Diff");
}
});
} }
if (simpleRequest != null) {
final DiffNavigationContext navigationContext = context.getDiffNavigationContext();
if (navigationContext != null) {
simpleRequest.passForDataContext(DiffTool.SCROLL_TO_LINE, navigationContext);
}
tool.show(simpleRequest);
}
} }
private static boolean directoryOrBinary(final Change change) { private static boolean directoryOrBinary(final Change change) {