mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
+61
-86
@@ -24,7 +24,6 @@ import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.util.ui.EdtInvocationManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -73,13 +72,9 @@ public class ProgressIndicatorUtils {
|
||||
*/
|
||||
public static boolean runInReadActionWithWriteActionPriority(@NotNull final Runnable action,
|
||||
@Nullable ProgressIndicator progressIndicator) {
|
||||
final Ref<Boolean> result = new Ref<Boolean>(Boolean.FALSE);
|
||||
runWithWriteActionPriority(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
result.set(ApplicationManagerEx.getApplicationEx().tryRunReadAction(action));
|
||||
}
|
||||
}, progressIndicator == null ? new ProgressIndicatorBase() : progressIndicator);
|
||||
final Ref<Boolean> result = new Ref<>(Boolean.FALSE);
|
||||
runWithWriteActionPriority(() -> result.set(ApplicationManagerEx.getApplicationEx().tryRunReadAction(action)),
|
||||
progressIndicator == null ? new ProgressIndicatorBase() : progressIndicator);
|
||||
return result.get();
|
||||
}
|
||||
|
||||
@@ -120,29 +115,23 @@ public class ProgressIndicatorUtils {
|
||||
}
|
||||
};
|
||||
|
||||
boolean succeededWithAddingListener = application.tryRunReadAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Even if writeLock.lock() acquisition is in progress at this point then runProcess will block wanting read action which is
|
||||
// also ok as last resort.
|
||||
application.addApplicationListener(listener);
|
||||
}
|
||||
boolean succeededWithAddingListener = application.tryRunReadAction(() -> {
|
||||
// Even if writeLock.lock() acquisition is in progress at this point then runProcess will block wanting read action which is
|
||||
// also ok as last resort.
|
||||
application.addApplicationListener(listener);
|
||||
});
|
||||
if (!succeededWithAddingListener) { // second catch: writeLock.lock() acquisition is in progress or already acquired
|
||||
if (!progressIndicator.isCanceled()) progressIndicator.cancel();
|
||||
return false;
|
||||
}
|
||||
final Ref<Boolean> wasCancelled = new Ref<Boolean>();
|
||||
final Ref<Boolean> wasCancelled = new Ref<>();
|
||||
try {
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
action.run();
|
||||
}
|
||||
catch (ProcessCanceledException ignore) {
|
||||
wasCancelled.set(Boolean.TRUE);
|
||||
}
|
||||
ProgressManager.getInstance().runProcess(() -> {
|
||||
try {
|
||||
action.run();
|
||||
}
|
||||
catch (ProcessCanceledException ignore) {
|
||||
wasCancelled.set(Boolean.TRUE);
|
||||
}
|
||||
}, progressIndicator);
|
||||
}
|
||||
@@ -165,76 +154,62 @@ public class ProgressIndicatorUtils {
|
||||
// to tolerate any immediate modality changes (e.g. https://youtrack.jetbrains.com/issue/IDEA-135180)
|
||||
|
||||
//noinspection SSBasedInspection
|
||||
EdtInvocationManager.getInstance().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (application.isDisposed()) return;
|
||||
final ApplicationAdapter listener = new ApplicationAdapter() {
|
||||
EdtInvocationManager.getInstance().invokeLater(() -> {
|
||||
if (application.isDisposed()) return;
|
||||
final ApplicationAdapter listener = new ApplicationAdapter() {
|
||||
@Override
|
||||
public void beforeWriteActionStart(Object action) {
|
||||
if (!progressIndicator.isCanceled()) {
|
||||
progressIndicator.cancel();
|
||||
readTask.onCanceled(progressIndicator);
|
||||
}
|
||||
}
|
||||
};
|
||||
application.addApplicationListener(listener);
|
||||
try {
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void beforeWriteActionStart(Object action) {
|
||||
if (!progressIndicator.isCanceled()) {
|
||||
progressIndicator.cancel();
|
||||
readTask.onCanceled(progressIndicator);
|
||||
public void run() {
|
||||
boolean continued = false;
|
||||
try {
|
||||
final ReadTask.Continuation continuation = runUnderProgress(progressIndicator, readTask);
|
||||
continued = continuation != null;
|
||||
if (continuation != null) {
|
||||
application.invokeLater(() -> {
|
||||
application.removeApplicationListener(listener);
|
||||
if (!progressIndicator.isCanceled()) {
|
||||
continuation.getAction().run();
|
||||
}
|
||||
}, continuation.getModalityState());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (!continued) {
|
||||
application.removeApplicationListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
application.addApplicationListener(listener);
|
||||
try {
|
||||
executor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean continued = false;
|
||||
try {
|
||||
final ReadTask.Continuation continuation = runUnderProgress(progressIndicator, readTask);
|
||||
continued = continuation != null;
|
||||
if (continuation != null) {
|
||||
application.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
application.removeApplicationListener(listener);
|
||||
if (!progressIndicator.isCanceled()) {
|
||||
continuation.getAction().run();
|
||||
}
|
||||
}
|
||||
}, continuation.getModalityState());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (!continued) {
|
||||
application.removeApplicationListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return readTask.toString();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
application.removeApplicationListener(listener);
|
||||
throw e;
|
||||
}
|
||||
catch (Error e) {
|
||||
application.removeApplicationListener(listener);
|
||||
throw e;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return readTask.toString();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (RuntimeException | Error e) {
|
||||
application.removeApplicationListener(listener);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static ReadTask.Continuation runUnderProgress(@NotNull final ProgressIndicator progressIndicator, @NotNull final ReadTask task) {
|
||||
return ProgressManager.getInstance().runProcess(new Computable<ReadTask.Continuation>() {
|
||||
@Override
|
||||
public ReadTask.Continuation compute() {
|
||||
try {
|
||||
return task.runBackgroundProcess(progressIndicator);
|
||||
}
|
||||
catch (ProcessCanceledException ignore) {
|
||||
return null;
|
||||
}
|
||||
return ProgressManager.getInstance().runProcess(() -> {
|
||||
try {
|
||||
return task.runBackgroundProcess(progressIndicator);
|
||||
}
|
||||
catch (ProcessCanceledException ignore) {
|
||||
return null;
|
||||
}
|
||||
}, progressIndicator);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,39 +82,36 @@ public class EditorNotificationsImpl extends EditorNotifications {
|
||||
|
||||
@Override
|
||||
public void updateNotifications(@NotNull final VirtualFile file) {
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ProgressIndicator indicator = getCurrentProgress(file);
|
||||
if (indicator != null) {
|
||||
indicator.cancel();
|
||||
}
|
||||
file.putUserData(CURRENT_UPDATES, null);
|
||||
UIUtil.invokeLaterIfNeeded(() -> {
|
||||
ProgressIndicator indicator = getCurrentProgress(file);
|
||||
if (indicator != null) {
|
||||
indicator.cancel();
|
||||
}
|
||||
file.putUserData(CURRENT_UPDATES, null);
|
||||
|
||||
if (myProject.isDisposed() || !file.isValid()) {
|
||||
return;
|
||||
}
|
||||
if (myProject.isDisposed() || !file.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
indicator = new ProgressIndicatorBase();
|
||||
final ReadTask task = createTask(indicator, file);
|
||||
if (task == null) return;
|
||||
indicator = new ProgressIndicatorBase();
|
||||
final ReadTask task = createTask(indicator, file);
|
||||
if (task == null) return;
|
||||
|
||||
file.putUserData(CURRENT_UPDATES, new WeakReference<ProgressIndicator>(indicator));
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
ReadTask.Continuation continuation = task.performInReadAction(indicator);
|
||||
if (continuation != null) {
|
||||
continuation.getAction().run();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, ourExecutor, task);
|
||||
file.putUserData(CURRENT_UPDATES, new WeakReference<>(indicator));
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
ReadTask.Continuation continuation = task.performInReadAction(indicator);
|
||||
if (continuation != null) {
|
||||
continuation.getAction().run();
|
||||
}
|
||||
}
|
||||
else {
|
||||
ProgressIndicatorUtils.scheduleWithWriteActionPriority(indicator, ourExecutor, task);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ReadTask createTask(final ProgressIndicator indicator, @NotNull final VirtualFile file) {
|
||||
private ReadTask createTask(@NotNull final ProgressIndicator indicator, @NotNull final VirtualFile file) {
|
||||
final FileEditor[] editors = FileEditorManager.getInstance(myProject).getAllEditors(file);
|
||||
if (editors.length == 0) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user