use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class ScrollSettings method isEligibleFor.
static boolean isEligibleFor(Component component) {
if (component == null || !component.isShowing())
return false;
Application application = getApplication();
if (application == null || application.isUnitTestMode())
return false;
if (PowerSaveMode.isEnabled())
return false;
if (RemoteDesktopService.isRemoteSession())
return false;
UISettings settings = UISettings.getInstanceOrNull();
return settings != null && settings.getSmoothScrolling();
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class DarculaLaf method initialize.
@Override
public void initialize() {
try {
base.initialize();
} catch (Exception ignore) {
}
myDisposable = Disposer.newDisposable();
Application application = ApplicationManager.getApplication();
if (application != null) {
Disposer.register(application, myDisposable);
}
myMnemonicAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myDisposable);
IdeEventQueue.getInstance().addDispatcher(e -> {
if (e instanceof KeyEvent && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ALT) {
myAltPressed = e.getID() == KeyEvent.KEY_PRESSED;
myMnemonicAlarm.cancelAllRequests();
final Component focusOwner = IdeFocusManager.findInstance().getFocusOwner();
if (focusOwner != null) {
myMnemonicAlarm.addRequest(() -> repaintMnemonics(focusOwner, myAltPressed), 10);
}
}
return false;
}, myDisposable);
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class NoAccessDuringPsiEvents method isInsideEventProcessing.
public static boolean isInsideEventProcessing() {
Application application = ApplicationManager.getApplication();
if (!application.isWriteAccessAllowed())
return false;
MessageBus bus = application.getMessageBus();
return bus.hasUndeliveredEvents(VirtualFileManager.VFS_CHANGES) || bus.hasUndeliveredEvents(PsiModificationTracker.TOPIC);
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class ProgressIndicatorUtils method scheduleWithWriteActionPriority.
@NotNull
public static CompletableFuture<?> scheduleWithWriteActionPriority(@NotNull final ProgressIndicator progressIndicator, @NotNull final Executor executor, @NotNull final ReadTask readTask) {
final Application application = ApplicationManager.getApplication();
// invoke later even if on EDT
// to avoid tasks eagerly restarting immediately, allocating many pooled threads
// which get cancelled too soon when a next write action arrives in the same EDT batch
// (can happen when processing multiple VFS events or writing multiple files on save)
// use SwingUtilities instead of application.invokeLater
// to tolerate any immediate modality changes (e.g. https://youtrack.jetbrains.com/issue/IDEA-135180)
CompletableFuture<?> future = new CompletableFuture<>();
//noinspection SSBasedInspection
EdtInvocationManager.getInstance().invokeLater(() -> {
if (application.isDisposed() || progressIndicator.isCanceled()) {
future.complete(null);
return;
}
final ApplicationAdapter listener = new ApplicationAdapter() {
@Override
public void beforeWriteActionStart(@NotNull Object action) {
if (!progressIndicator.isCanceled()) {
progressIndicator.cancel();
readTask.onCanceled(progressIndicator);
}
}
};
application.addApplicationListener(listener);
future.whenComplete((BiConsumer<Object, Throwable>) (o, throwable) -> application.removeApplicationListener(listener));
try {
executor.execute(new Runnable() {
@Override
public void run() {
final ReadTask.Continuation continuation;
try {
continuation = runUnderProgress(progressIndicator, readTask);
} catch (Throwable e) {
future.completeExceptionally(e);
throw e;
}
if (continuation == null) {
future.complete(null);
} else {
application.invokeLater(new Runnable() {
@Override
public void run() {
try {
if (!progressIndicator.isCanceled()) {
continuation.getAction().run();
}
} finally {
future.complete(null);
}
}
@Override
public String toString() {
return "continuation of " + readTask;
}
}, continuation.getModalityState());
}
}
@Override
public String toString() {
return readTask.toString();
}
});
} catch (RuntimeException | Error e) {
application.removeApplicationListener(listener);
future.completeExceptionally(e);
throw e;
}
});
return future;
}
use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.
the class FileStatusManagerImpl method fileStatusChanged.
@Override
public void fileStatusChanged(final VirtualFile file) {
final Application application = ApplicationManager.getApplication();
if (!application.isDispatchThread() && !application.isUnitTestMode()) {
ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {
@Override
public void run() {
fileStatusChanged(file);
}
});
return;
}
if (file == null || !file.isValid())
return;
FileStatus cachedStatus = getCachedStatus(file);
if (cachedStatus == FileStatusNull.INSTANCE) {
return;
}
if (cachedStatus == null) {
cacheChangedFileStatus(file, FileStatusNull.INSTANCE);
return;
}
FileStatus newStatus = calcStatus(file);
if (cachedStatus == newStatus)
return;
cacheChangedFileStatus(file, newStatus);
for (FileStatusListener listener : myListeners) {
listener.fileStatusChanged(file);
}
}
Aggregations