Search in sources :

Example 36 with ModalityState

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

the class CoreProgressManager method getCurrentThreadProgressModality.

@NotNull
public static ModalityState getCurrentThreadProgressModality() {
    ProgressIndicator indicator = threadTopLevelIndicators.get(Thread.currentThread().getId());
    ModalityState modality = indicator == null ? null : indicator.getModalityState();
    return modality != null ? modality : ModalityState.NON_MODAL;
}
Also used : ModalityState(com.intellij.openapi.application.ModalityState) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with ModalityState

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

the class AbstractProgressIndicatorBase method setModalityProgress.

@Override
public void setModalityProgress(ProgressIndicator modalityProgress) {
    LOG.assertTrue(!isRunning());
    myModalityProgress = modalityProgress;
    ModalityState currentModality = ApplicationManager.getApplication().getCurrentModalityState();
    myModalityState = myModalityProgress != null ? ((ModalityStateEx) currentModality).appendProgress(myModalityProgress) : currentModality;
    if (modalityProgress != null) {
        ((TransactionGuardImpl) TransactionGuard.getInstance()).enteredModality(myModalityState);
    }
}
Also used : ModalityStateEx(com.intellij.openapi.application.impl.ModalityStateEx) ModalityState(com.intellij.openapi.application.ModalityState) TransactionGuardImpl(com.intellij.openapi.application.TransactionGuardImpl)

Example 38 with ModalityState

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

the class PyIntegratedToolsProjectConfigurator method updateIntegratedTools.

private static void updateIntegratedTools(final Module module, final int delay) {
    ModalityState modality = ModalityState.current();
    final PyDocumentationSettings docSettings = PyDocumentationSettings.getInstance(module);
    AppExecutorUtil.getAppScheduledExecutorService().schedule(() -> ApplicationManager.getApplication().invokeLater(() -> {
        LOG.debug("Integrated tools configurator has started");
        if (module.isDisposed())
            return;
        @NotNull DocStringFormat docFormat = DocStringFormat.PLAIN;
        //check setup.py
        @NotNull String testRunner = detectTestRunnerFromSetupPy(module);
        if (!testRunner.isEmpty()) {
            LOG.debug("Test runner '" + testRunner + "' was discovered from setup.py in the module '" + module.getModuleFilePath() + "'");
        }
        //try to find test_runner import
        final String extension = PythonFileType.INSTANCE.getDefaultExtension();
        // Module#getModuleScope() and GlobalSearchScope#getModuleScope() search only in source roots
        final GlobalSearchScope searchScope = module.getModuleScope();
        final Collection<VirtualFile> pyFiles = FilenameIndex.getAllFilesByExt(module.getProject(), extension, searchScope);
        for (VirtualFile file : pyFiles) {
            if (file.getName().startsWith("test")) {
                if (testRunner.isEmpty()) {
                    //find test runner import
                    testRunner = checkImports(file, module);
                    if (!testRunner.isEmpty()) {
                        LOG.debug("Test runner '" + testRunner + "' was detected from imports in the file '" + file.getPath() + "'");
                    }
                }
            } else if (docFormat == DocStringFormat.PLAIN) {
                // detect docstring type
                docFormat = checkDocstring(file, module);
                if (docFormat != DocStringFormat.PLAIN) {
                    LOG.debug("Docstring format '" + docFormat + "' was detected from content of the file '" + file.getPath() + "'");
                }
            }
            if (!testRunner.isEmpty() && docFormat != DocStringFormat.PLAIN) {
                break;
            }
        }
        // Check test runners available in the module SDK
        if (testRunner.isEmpty()) {
            //check if installed in sdk
            final Sdk sdk = PythonSdkType.findPythonSdk(module);
            if (sdk != null && sdk.getSdkType() instanceof PythonSdkType) {
                final List<PyPackage> packages = PyPackageUtil.refreshAndGetPackagesModally(sdk);
                if (packages != null) {
                    final boolean nose = PyPackageUtil.findPackage(packages, PyNames.NOSE_TEST) != null;
                    final boolean pytest = PyPackageUtil.findPackage(packages, PyNames.PY_TEST) != null;
                    if (nose)
                        testRunner = PythonTestConfigurationsModel.PYTHONS_NOSETEST_NAME;
                    else if (pytest)
                        testRunner = PythonTestConfigurationsModel.PY_TEST_NAME;
                    if (!testRunner.isEmpty()) {
                        LOG.debug("Test runner '" + testRunner + "' was detected from SDK " + sdk);
                    }
                }
            }
        }
        final TestRunnerService runnerService = TestRunnerService.getInstance(module);
        if (runnerService != null) {
            if (testRunner.isEmpty()) {
                runnerService.setProjectConfiguration(PythonTestConfigurationsModel.PYTHONS_UNITTEST_NAME);
            } else {
                runnerService.setProjectConfiguration(testRunner);
                LOG.info("Test runner '" + testRunner + "' was detected by project configurator");
            }
        }
        // Documentation settings should have meaningful default already
        if (docFormat != DocStringFormat.PLAIN) {
            docSettings.setFormat(docFormat);
            LOG.info("Docstring format '" + docFormat + "' was detected by project configurator");
        }
    }, modality), delay, TimeUnit.MILLISECONDS);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocStringFormat(com.jetbrains.python.documentation.docstrings.DocStringFormat) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ModalityState(com.intellij.openapi.application.ModalityState) Collection(java.util.Collection) List(java.util.List) Sdk(com.intellij.openapi.projectRoots.Sdk) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) PyDocumentationSettings(com.jetbrains.python.documentation.PyDocumentationSettings)

Example 39 with ModalityState

use of com.intellij.openapi.application.ModalityState in project flutter-intellij by flutter.

the class FlutterSettingsConfigurable method updateVersionText.

private void updateVersionText() {
    final FlutterSdk sdk = FlutterSdk.forPath(getSdkPathText());
    if (sdk == null) {
        myVersionLabel.setText("");
        return;
    }
    final ModalityState modalityState = ModalityState.current();
    sdk.flutterVersion().start((ProcessOutput output) -> {
        final String stdout = output.getStdout();
        final String htmlText = "<html>" + StringUtil.replace(StringUtil.escapeXml(stdout.trim()), "\n", "<br/>") + "</html>";
        ApplicationManager.getApplication().invokeLater(() -> updateVersionTextIfCurrent(sdk, htmlText), modalityState);
    }, null);
}
Also used : ProcessOutput(com.intellij.execution.process.ProcessOutput) ModalityState(com.intellij.openapi.application.ModalityState)

Example 40 with ModalityState

use of com.intellij.openapi.application.ModalityState in project azure-tools-for-java by Microsoft.

the class SparkBatchJobDebuggerRunner method attachAndDebug.

private Observable<RunContentDescriptor> attachAndDebug(final ExecutionEnvironment environment, final RunProfileState state) {
    final Project project = environment.getProject();
    final JFrame ideFrame = WindowManager.getInstance().getFrame(project);
    final ModalityState ideModalityState = ideFrame != null ? stateForComponent(ideFrame) : any();
    return Observable.fromCallable(() -> {
        // Invoke GenericDebuggerRunner#doExecute to start real VM attach and debugging
        return doExecute(state, environment);
    }).subscribeOn(new IdeaSchedulers(project).dispatchUIThread(ideModalityState));
}
Also used : Project(com.intellij.openapi.project.Project) IdeaSchedulers(com.microsoft.intellij.rxjava.IdeaSchedulers) ModalityState(com.intellij.openapi.application.ModalityState)

Aggregations

ModalityState (com.intellij.openapi.application.ModalityState)40 Application (com.intellij.openapi.application.Application)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 NotNull (org.jetbrains.annotations.NotNull)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Disposable (com.intellij.openapi.Disposable)4 ListSelectionListener (javax.swing.event.ListSelectionListener)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Project (com.intellij.openapi.project.Project)3 List (java.util.List)3 CommonBundle (com.intellij.CommonBundle)2 com.intellij.find (com.intellij.find)2 ShowUsagesAction (com.intellij.find.actions.ShowUsagesAction)2 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)2 AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)2 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)2 ProjectTreeBuilder (com.intellij.ide.projectView.impl.ProjectTreeBuilder)2 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)2 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)2