Search in sources :

Example 31 with Application

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();
}
Also used : UISettings(com.intellij.ide.ui.UISettings) Application(com.intellij.openapi.application.Application) ApplicationManager.getApplication(com.intellij.openapi.application.ApplicationManager.getApplication)

Example 32 with Application

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);
}
Also used : KeyEvent(java.awt.event.KeyEvent) Alarm(com.intellij.util.Alarm) Application(com.intellij.openapi.application.Application) IOException(java.io.IOException)

Example 33 with Application

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);
}
Also used : MessageBus(com.intellij.util.messages.MessageBus) Application(com.intellij.openapi.application.Application)

Example 34 with Application

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;
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) Application(com.intellij.openapi.application.Application) Executor(java.util.concurrent.Executor) ModalityState(com.intellij.openapi.application.ModalityState) CompletableFuture(java.util.concurrent.CompletableFuture) EdtInvocationManager(com.intellij.util.ui.EdtInvocationManager) Disposable(com.intellij.openapi.Disposable) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) Nullable(org.jetbrains.annotations.Nullable) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ApplicationAdapter(com.intellij.openapi.application.ApplicationAdapter) BiConsumer(java.util.function.BiConsumer) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ApplicationManagerEx(com.intellij.openapi.application.ex.ApplicationManagerEx) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) PooledThreadExecutor(org.jetbrains.ide.PooledThreadExecutor) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) NotNull(org.jetbrains.annotations.NotNull) CompletableFuture(java.util.concurrent.CompletableFuture) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) ApplicationAdapter(com.intellij.openapi.application.ApplicationAdapter) Application(com.intellij.openapi.application.Application) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with Application

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);
    }
}
Also used : FileStatus(com.intellij.openapi.vcs.FileStatus) FileStatusListener(com.intellij.openapi.vcs.FileStatusListener) Application(com.intellij.openapi.application.Application) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Aggregations

Application (com.intellij.openapi.application.Application)188 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 IOException (java.io.IOException)14 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)9 ModalityState (com.intellij.openapi.application.ModalityState)8 Ref (com.intellij.openapi.util.Ref)7 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)4 Document (com.intellij.openapi.editor.Document)4 Module (com.intellij.openapi.module.Module)4 Computable (com.intellij.openapi.util.Computable)4 PsiFile (com.intellij.psi.PsiFile)4 File (java.io.File)4 Editor (com.intellij.openapi.editor.Editor)3