[platform] post-review fixes (IDEA-CR-15535)

This commit is contained in:
Roman Shevchenko
2016-11-08 19:46:41 +01:00
parent 54374e5c2b
commit 5877292c39
@@ -20,6 +20,7 @@ import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.editor.EditorBundle;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiElement;
@@ -27,6 +28,8 @@ import com.intellij.psi.SmartPointerManager;
import com.intellij.psi.SmartPsiElementPointer;
import org.jetbrains.annotations.NotNull;
import static com.intellij.openapi.util.Conditions.or;
public class PsiElementNavigatable implements Navigatable {
private final SmartPsiElementPointer<PsiElement> myPointer;
@@ -40,14 +43,15 @@ public class PsiElementNavigatable implements Navigatable {
if (element != null && element.isValid()) {
VirtualFile file = element.getContainingFile().getVirtualFile();
if (file != null) {
new Task.Backgroundable(element.getProject(), EditorBundle.message("editor.open.file.progress", file.getName())) {
new Task.Modal(element.getProject(), EditorBundle.message("editor.open.file.progress", file.getName()), true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
if (element.isValid() && !myProject.isDisposed()) {
int offset = ReadAction.compute(() -> element.getTextOffset()); // may trigger decompilation
indicator.checkCanceled();
int offset = ReadAction.compute(() -> element.isValid() ? element.getTextOffset() : -1); // may trigger decompilation
indicator.checkCanceled();
if (offset >= 0) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, file, offset);
ApplicationManager.getApplication().invokeLater(() -> descriptor.navigate(requestFocus), myProject.getDisposed());
Condition<?> expired = or(myProject.getDisposed(), o -> !file.isValid());
ApplicationManager.getApplication().invokeLater(() -> descriptor.navigate(requestFocus), expired);
}
}
}.queue();