use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class CommandProcessor method run.
private boolean run(boolean synchronously) {
synchronized (myLock) {
final CommandGroup commandGroup = getNextCommandGroup();
if (commandGroup == null || commandGroup.isEmpty())
return false;
final Condition conditionForGroup = commandGroup.getExpireCondition();
final FinalizableCommand command = commandGroup.takeNextCommand();
myCommandCount--;
Condition expire = command.getExpireCondition() != null ? command.getExpireCondition() : conditionForGroup;
if (expire == null)
expire = ApplicationManager.getApplication().getDisposed();
if (expire.value(null))
return true;
if (LOG.isDebugEnabled()) {
LOG.debug("CommandProcessor.run " + command);
}
if (synchronously) {
command.run();
return true;
}
// max. I'm not actually quite sure this should have NON_MODAL modality but it should
// definitely have some since runnables in command list may (and do) request some PSI activity
final boolean queueNext = myCommandCount > 0;
Application application = ApplicationManager.getApplication();
ModalityState modalityState = Registry.is("ide.perProjectModality") ? ModalityState.current() : ModalityState.NON_MODAL;
application.getInvokator().invokeLater(command, modalityState, expire).doWhenDone(() -> {
if (queueNext) {
run(false);
}
});
return true;
}
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class PaintersHelper method newWallpaperPainter.
private static AbstractPainter newWallpaperPainter(@NotNull final String propertyName, @NotNull final JComponent rootComponent) {
return new ImagePainter() {
Image image;
float alpha;
Insets insets;
Fill fillType;
Place place;
String current;
@Override
public boolean needsRepaint() {
return ensureImageLoaded();
}
@Override
public void executePaint(Component component, Graphics2D g) {
// covered by needsRepaint()
if (image == null)
return;
executePaint(g, component, image, fillType, place, alpha, insets);
}
boolean ensureImageLoaded() {
IdeFrame frame = UIUtil.getParentOfType(IdeFrame.class, rootComponent);
Project project = frame == null ? null : frame.getProject();
String value = getBackgroundSpec(project, propertyName);
if (!Comparing.equal(value, current)) {
current = value;
loadImageAsync(value);
// keep the current image for a while
}
return image != null;
}
private void resetImage(String value, Image newImage, float newAlpha, Fill newFill, Place newPlace) {
if (!Comparing.equal(current, value))
return;
boolean prevOk = image != null;
clearImages(-1);
image = newImage;
insets = JBUI.emptyInsets();
alpha = newAlpha;
fillType = newFill;
place = newPlace;
boolean newOk = newImage != null;
if (prevOk || newOk) {
ModalityState modalityState = ModalityState.stateForComponent(rootComponent);
if (modalityState.dominates(ModalityState.NON_MODAL)) {
UIUtil.getActiveWindow().repaint();
} else {
IdeBackgroundUtil.repaintAllWindows();
}
}
}
private void loadImageAsync(final String propertyValue) {
String[] parts = (propertyValue != null ? propertyValue : propertyName + ".png").split(",");
final float newAlpha = Math.abs(Math.min(StringUtil.parseInt(parts.length > 1 ? parts[1] : "", 10) / 100f, 1f));
final Fill newFillType = StringUtil.parseEnum(parts.length > 2 ? parts[2].toUpperCase(Locale.ENGLISH) : "", Fill.SCALE, Fill.class);
final Place newPlace = StringUtil.parseEnum(parts.length > 3 ? parts[3].toUpperCase(Locale.ENGLISH) : "", Place.CENTER, Place.class);
String filePath = parts[0];
if (StringUtil.isEmpty(filePath)) {
resetImage(propertyValue, null, newAlpha, newFillType, newPlace);
return;
}
try {
URL url = filePath.contains("://") ? new URL(filePath) : (FileUtil.isAbsolutePlatformIndependent(filePath) ? new File(filePath) : new File(PathManager.getConfigPath(), filePath)).toURI().toURL();
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final Image m = ImageLoader.loadFromUrl(url);
ModalityState modalityState = ModalityState.stateForComponent(rootComponent);
ApplicationManager.getApplication().invokeLater(() -> resetImage(propertyValue, m, newAlpha, newFillType, newPlace), modalityState);
});
} catch (Exception e) {
resetImage(propertyValue, null, newAlpha, newFillType, newPlace);
}
}
};
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class InstalledPackagesPanel method uninstallAction.
private void uninstallAction() {
final List<InstalledPackage> packages = getSelectedPackages();
final PackageManagementService selPackageManagementService = myPackageManagementService;
if (selPackageManagementService != null) {
ModalityState modalityState = ModalityState.current();
PackageManagementService.Listener listener = new PackageManagementService.Listener() {
@Override
public void operationStarted(String packageName) {
ApplicationManager.getApplication().invokeLater(() -> myPackagesTable.setPaintBusy(true), modalityState);
}
@Override
public void operationFinished(final String packageName, @Nullable final PackageManagementService.ErrorDescription errorDescription) {
ApplicationManager.getApplication().invokeLater(() -> {
myPackagesTable.clearSelection();
updatePackages(selPackageManagementService);
myPackagesTable.setPaintBusy(false);
if (errorDescription == null) {
if (packageName != null) {
myNotificationArea.showSuccess("Package '" + packageName + "' successfully uninstalled");
} else {
myNotificationArea.showSuccess("Packages successfully uninstalled");
}
} else {
myNotificationArea.showError("Uninstall packages failed. <a href=\"xxx\">Details...</a>", "Uninstall Packages Failed", errorDescription);
}
}, modalityState);
}
};
myPackageManagementService.uninstallPackages(packages, listener);
}
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class AbstractLayoutCodeProcessor method runLayoutCodeProcess.
private void runLayoutCodeProcess(final Runnable readAction, final Runnable writeAction) {
final ProgressWindow progressWindow = new ProgressWindow(true, myProject);
progressWindow.setTitle(myCommandName);
progressWindow.setText(myProgressText);
final ModalityState modalityState = ModalityState.current();
final Runnable process = () -> ApplicationManager.getApplication().runReadAction(readAction);
Runnable runnable = () -> {
try {
ProgressManager.getInstance().runProcess(process, progressWindow);
} catch (ProcessCanceledException e) {
return;
} catch (IndexNotReadyException e) {
LOG.warn(e);
return;
}
final Runnable writeRunnable = () -> CommandProcessor.getInstance().executeCommand(myProject, () -> {
try {
writeAction.run();
if (myPostRunnable != null) {
ApplicationManager.getApplication().invokeLater(myPostRunnable);
}
} catch (IndexNotReadyException e) {
LOG.warn(e);
}
}, myCommandName, null);
if (ApplicationManager.getApplication().isUnitTestMode()) {
writeRunnable.run();
} else {
ApplicationManager.getApplication().invokeLater(writeRunnable, modalityState, myProject.getDisposed());
}
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
} else {
ApplicationManager.getApplication().executeOnPooledThread(runnable);
}
}
use of com.intellij.openapi.application.ModalityState in project intellij-community by JetBrains.
the class DiffUtil method markDirtyAndRefresh.
/**
* Difference with {@link VfsUtil#markDirtyAndRefresh} is that refresh from VfsUtil will be performed with ModalityState.NON_MODAL.
*/
public static void markDirtyAndRefresh(boolean async, boolean recursive, boolean reloadChildren, @NotNull VirtualFile... files) {
ModalityState modalityState = ApplicationManager.getApplication().getDefaultModalityState();
VfsUtil.markDirty(recursive, reloadChildren, files);
RefreshQueue.getInstance().refresh(async, recursive, null, modalityState, files);
}
Aggregations