mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Read action doesn't need to be in EDT
This commit is contained in:
@@ -18,6 +18,7 @@ package git4idea;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -55,7 +56,7 @@ public interface PlatformFacade {
|
||||
ProjectRootManager getProjectRootManager(@NotNull Project project);
|
||||
|
||||
/**
|
||||
* Invokes {@link com.intellij.openapi.application.Application#runReadAction(Runnable)} in AWT and waits if needed.
|
||||
* Invokes {@link com.intellij.openapi.application.Application#runReadAction(Computable)}.
|
||||
*/
|
||||
void runReadActionAndWaitIfNeeded(@NotNull Runnable runnable);
|
||||
<T> T runReadAction(@NotNull Computable<T> computable);
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -53,12 +53,8 @@ public class PlatformFacadeImpl implements PlatformFacade {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runReadActionAndWaitIfNeeded(@NotNull final Runnable runnable) {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override public void run() {
|
||||
ApplicationManager.getApplication().runReadAction(runnable);
|
||||
}
|
||||
});
|
||||
public <T> T runReadAction(@NotNull Computable<T> computable) {
|
||||
return ApplicationManager.getApplication().runReadAction(computable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package git4idea.roots;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import git4idea.PlatformFacade;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -24,7 +25,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -94,10 +94,10 @@ public class GitRootDetector {
|
||||
return roots;
|
||||
}
|
||||
|
||||
myPlatformFacade.runReadActionAndWaitIfNeeded(new Runnable() {
|
||||
@Override public void run() {
|
||||
myPlatformFacade.runReadAction(new Computable<Object>() {
|
||||
@Nullable @Override public Object compute() {
|
||||
if (myProject.isDisposed() || !dir.isDirectory()) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (hasGitDir(dir)) {
|
||||
roots.add(dir);
|
||||
@@ -105,6 +105,7 @@ public class GitRootDetector {
|
||||
for (VirtualFile child : dir.getChildren()) {
|
||||
roots.addAll(scanForRootsInsideDir(child, depth + 1));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -118,24 +119,22 @@ public class GitRootDetector {
|
||||
|
||||
@Nullable
|
||||
private VirtualFile scanForSingleRootAboveDir(@NotNull final VirtualFile projectDir) {
|
||||
final AtomicReference<VirtualFile> parent = new AtomicReference<VirtualFile>();
|
||||
myPlatformFacade.runReadActionAndWaitIfNeeded(new Runnable() {
|
||||
@Override public void run() {
|
||||
return myPlatformFacade.runReadAction(new Computable<VirtualFile>() {
|
||||
@Nullable @Override public VirtualFile compute() {
|
||||
if (myProject.isDisposed()) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
VirtualFile par = projectDir.getParent();
|
||||
while (par != null) {
|
||||
if (hasGitDir(par)) {
|
||||
parent.set(par);
|
||||
return;
|
||||
return par;
|
||||
}
|
||||
par = par.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return parent.get();
|
||||
}
|
||||
|
||||
private static boolean hasGitDir(@NotNull VirtualFile dir) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import git4idea.PlatformFacade
|
||||
import git4idea.tests.TestDialogManager
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.openapi.util.Computable
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -72,8 +73,8 @@ public class GitTestPlatformFacade implements PlatformFacade {
|
||||
}
|
||||
|
||||
@Override
|
||||
void runReadActionAndWaitIfNeeded(Runnable runnable) {
|
||||
runnable.run()
|
||||
<T> T runReadAction(@NotNull Computable<T> computable) {
|
||||
computable.compute()
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user