mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add dumb mode-related transactions
This commit is contained in:
+11
-14
@@ -22,6 +22,7 @@ package com.intellij.openapi.roots.impl;
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.TransactionGuard;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionException;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
@@ -49,7 +50,6 @@ import com.intellij.ui.GuiUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
import com.intellij.util.indexing.FileBasedIndexProjectHandler;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -408,20 +408,17 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater
|
||||
private static void reloadPsi(final VirtualFile file, final Project project) {
|
||||
final FileManagerImpl fileManager = (FileManagerImpl)((PsiManagerEx)PsiManager.getInstance(project)).getFileManager();
|
||||
if (fileManager.findCachedViewProvider(file) != null) {
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (project.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
fileManager.forceReload(file);
|
||||
}
|
||||
});
|
||||
Runnable runnable = () -> {
|
||||
if (project.isDisposed()) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
ApplicationManager.getApplication().runWriteAction(() -> fileManager.forceReload(file));
|
||||
};
|
||||
if (ApplicationManager.getApplication().isDispatchThread()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
TransactionGuard.submitTransaction(runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package com.intellij.internal;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.application.WrapInTransaction;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.DumbModeTask;
|
||||
import com.intellij.openapi.project.DumbServiceImpl;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -30,7 +30,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class ToggleDumbModeAction extends AnAction implements DumbAware {
|
||||
@WrapInTransaction
|
||||
public class ToggleDumbModeAction extends DumbAwareAction {
|
||||
private volatile boolean myDumb = false;
|
||||
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
|
||||
@@ -18,10 +18,7 @@ package com.intellij.openapi.project;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.startup.StartupManagerEx;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.AccessToken;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.*;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx;
|
||||
@@ -188,7 +185,7 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica
|
||||
return;
|
||||
}
|
||||
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (myProject.isDisposed()) {
|
||||
@@ -251,7 +248,13 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica
|
||||
}, ModalityState.any(), myProject.getDisposed());
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
if (application.isDispatchThread()) {
|
||||
runnable.run();
|
||||
} else {
|
||||
//noinspection SSBasedInspection
|
||||
SwingUtilities.invokeLater(() -> TransactionGuard.submitTransaction(runnable));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -530,16 +533,25 @@ public class DumbServiceImpl extends DumbService implements Disposable, Modifica
|
||||
private static void invokeAndWaitIfNeeded(Runnable runnable) {
|
||||
if (ApplicationManager.getApplication().isDispatchThread()) {
|
||||
runnable.run();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(runnable);
|
||||
}
|
||||
catch (InterruptedException ignore) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
Semaphore semaphore = new Semaphore();
|
||||
semaphore.down();
|
||||
//todo remove invokeLater when transactions are executed in "any" modality state
|
||||
//noinspection SSBasedInspection
|
||||
SwingUtilities.invokeLater(
|
||||
() -> TransactionGuard.getInstance().submitMergeableTransaction(TransactionKind.ANY_CHANGE, () -> {
|
||||
try {
|
||||
runnable.run();
|
||||
} finally {
|
||||
semaphore.up();
|
||||
}
|
||||
}));
|
||||
try {
|
||||
semaphore.waitFor();
|
||||
}
|
||||
catch (ProcessCanceledException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user