Search in sources :

Example 6 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable 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)

Example 7 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class BraceHighlightingHandler method lookForInjectedAndMatchBracesInOtherThread.

static void lookForInjectedAndMatchBracesInOtherThread(@NotNull final Editor editor, @NotNull final Alarm alarm, @NotNull final Processor<BraceHighlightingHandler> processor) {
    ApplicationManagerEx.getApplicationEx().assertIsDispatchThread();
    if (!isValidEditor(editor))
        return;
    if (!PROCESSED_EDITORS.add(editor)) {
        // Assuming to be in EDT here.
        return;
    }
    final int offset = editor.getCaretModel().getOffset();
    final Project project = editor.getProject();
    final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (!isValidFile(psiFile))
        return;
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(() -> {
            final PsiFile injected;
            try {
                if (psiFile instanceof PsiBinaryFile || !isValidEditor(editor) || !isValidFile(psiFile)) {
                    injected = null;
                } else {
                    injected = getInjectedFileIfAny(editor, project, offset, psiFile, alarm);
                }
            } catch (RuntimeException e) {
                // Reset processing flag in case of unexpected exception.
                ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {

                    @Override
                    public void run() {
                        PROCESSED_EDITORS.remove(editor);
                    }
                });
                throw e;
            }
            ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {

                @Override
                public void run() {
                    try {
                        if (isValidEditor(editor) && isValidFile(injected)) {
                            Editor newEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injected);
                            BraceHighlightingHandler handler = new BraceHighlightingHandler(project, newEditor, alarm, injected);
                            processor.process(handler);
                        }
                    } finally {
                        PROCESSED_EDITORS.remove(editor);
                    }
                }
            }, ModalityState.stateForComponent(editor.getComponent()));
        })) {
            // write action is queued in AWT. restart after it's finished
            ApplicationManager.getApplication().invokeLater(() -> {
                PROCESSED_EDITORS.remove(editor);
                lookForInjectedAndMatchBracesInOtherThread(editor, alarm, processor);
            }, ModalityState.stateForComponent(editor.getComponent()));
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) Editor(com.intellij.openapi.editor.Editor) LightweightHint(com.intellij.ui.LightweightHint) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 8 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class ExternalDependenciesManagerImpl method loadState.

@Override
public void loadState(ExternalDependenciesState state) {
    ArrayList<ProjectExternalDependency> oldDependencies = new ArrayList<>(myDependencies);
    myDependencies.clear();
    for (DependencyOnPluginState dependency : state.myDependencies) {
        myDependencies.add(new DependencyOnPlugin(dependency.myId, dependency.myMinVersion, dependency.myMaxVersion, dependency.myChannel));
    }
    if (!oldDependencies.equals(myDependencies) && !myDependencies.isEmpty()) {
        StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new DumbAwareRunnable() {

            @Override
            public void run() {
                CheckRequiredPluginsActivity.runCheck(myProject);
            }
        });
    }
}
Also used : ArrayList(java.util.ArrayList) ProjectExternalDependency(com.intellij.externalDependencies.ProjectExternalDependency) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) DependencyOnPlugin(com.intellij.externalDependencies.DependencyOnPlugin)

Example 9 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class PlatformProjectViewOpener method configureProject.

@Override
public void configureProject(final Project project, @NotNull final VirtualFile baseDir, Ref<Module> moduleRef) {
    ToolWindowManagerEx manager = (ToolWindowManagerEx) ToolWindowManager.getInstance(project);
    ToolWindow toolWindow = manager.getToolWindow(ToolWindowId.PROJECT_VIEW);
    if (toolWindow == null) {
        manager.addToolWindowManagerListener(new MyListener(manager, project));
    } else {
        StartupManager.getInstance(project).runWhenProjectIsInitialized(new DumbAwareRunnable() {

            @Override
            public void run() {
                activateProjectToolWindow(project, toolWindow);
            }
        });
    }
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx)

Example 10 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class NotificationsManagerImpl method doNotify.

private static void doNotify(@NotNull final Notification notification, @Nullable NotificationDisplayType displayType, @Nullable final Project project) {
    final NotificationsConfigurationImpl configuration = NotificationsConfigurationImpl.getInstanceImpl();
    if (!configuration.isRegistered(notification.getGroupId())) {
        configuration.register(notification.getGroupId(), displayType == null ? NotificationDisplayType.BALLOON : displayType);
    }
    final NotificationSettings settings = NotificationsConfigurationImpl.getSettings(notification.getGroupId());
    boolean shouldLog = settings.isShouldLog();
    boolean displayable = settings.getDisplayType() != NotificationDisplayType.NONE;
    boolean willBeShown = displayable && NotificationsConfigurationImpl.getInstanceImpl().SHOW_BALLOONS;
    if (!shouldLog && !willBeShown) {
        notification.expire();
    }
    if (NotificationsConfigurationImpl.getInstanceImpl().SHOW_BALLOONS) {
        final Runnable runnable = new DumbAwareRunnable() {

            @Override
            public void run() {
                showNotification(notification, project);
            }
        };
        if (project == null) {
            UIUtil.invokeLaterIfNeeded(runnable);
        } else if (!project.isDisposed()) {
            StartupManager.getInstance(project).runWhenProjectIsInitialized(runnable);
        }
    }
}
Also used : DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Aggregations

DumbAwareRunnable (com.intellij.openapi.project.DumbAwareRunnable)16 ToolWindow (com.intellij.openapi.wm.ToolWindow)3 Notification (com.intellij.notification.Notification)2 NotificationListener (com.intellij.notification.NotificationListener)2 Application (com.intellij.openapi.application.Application)2 Project (com.intellij.openapi.project.Project)2 FileStatusListener (com.intellij.openapi.vcs.FileStatusListener)2 DependencyOnPlugin (com.intellij.externalDependencies.DependencyOnPlugin)1 ProjectExternalDependency (com.intellij.externalDependencies.ProjectExternalDependency)1 UISettings (com.intellij.ide.ui.UISettings)1 Editor (com.intellij.openapi.editor.Editor)1 EditorColorsListener (com.intellij.openapi.editor.colors.EditorColorsListener)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)1 ExternalSystemSettingsListenerAdapter (com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 Library (com.intellij.openapi.roots.libraries.Library)1 Balloon (com.intellij.openapi.ui.popup.Balloon)1 JBPopupAdapter (com.intellij.openapi.ui.popup.JBPopupAdapter)1 LightweightWindowEvent (com.intellij.openapi.ui.popup.LightweightWindowEvent)1