Search in sources :

Example 56 with ProgressIndicator

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

the class InitialConfigurationDialog method doOKAction.

@Override
protected void doOKAction() {
    Project project = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myMainPanel));
    super.doOKAction();
    // set keymap
    ((KeymapManagerImpl) KeymapManager.getInstance()).setActiveKeymap((Keymap) myKeymapComboBox.getSelectedItem());
    // set color scheme
    EditorColorsManager.getInstance().setGlobalScheme((EditorColorsScheme) myColorSchemeComboBox.getSelectedItem());
    // create default todo_pattern for color scheme
    TodoConfiguration.getInstance().resetToDefaultTodoPatterns();
    final boolean createScript = myCreateScriptCheckbox.isSelected();
    final boolean createEntry = myCreateEntryCheckBox.isSelected();
    if (createScript || createEntry) {
        final String pathName = myScriptPathTextField.getText();
        final boolean globalEntry = myGlobalEntryCheckBox.isSelected();
        ProgressManager.getInstance().run(new Task.Backgroundable(project, getTitle()) {

            @Override
            public void run(@NotNull final ProgressIndicator indicator) {
                indicator.setFraction(0.0);
                if (createScript) {
                    indicator.setText("Creating launcher script...");
                    try {
                        CreateLauncherScriptAction.createLauncherScript(pathName);
                    } catch (Exception e) {
                        CreateLauncherScriptAction.reportFailure(e, getProject());
                    }
                }
                indicator.setFraction(0.5);
                if (createEntry) {
                    indicator.setText("Creating desktop entry...");
                    try {
                        CreateDesktopEntryAction.createDesktopEntry(globalEntry);
                    } catch (Exception e) {
                        CreateDesktopEntryAction.reportFailure(e, getProject());
                    }
                }
                indicator.setFraction(1.0);
            }
        });
    }
    UIManager.LookAndFeelInfo info = (UIManager.LookAndFeelInfo) myAppearanceComboBox.getSelectedItem();
    LafManagerImpl lafManager = (LafManagerImpl) LafManager.getInstance();
    if (info.getName().contains("Darcula") != (LafManager.getInstance().getCurrentLookAndFeel() instanceof DarculaLookAndFeelInfo)) {
        lafManager.setLookAndFeelAfterRestart(info);
        String message = "IDE appearance settings will be applied after restart. Would you like to restart now?";
        int rc = Messages.showYesNoDialog(project, message, "IDE Appearance", Messages.getQuestionIcon());
        if (rc == Messages.YES) {
            ((ApplicationImpl) ApplicationManager.getApplication()).restart(true);
        }
    } else if (!info.equals(lafManager.getCurrentLookAndFeel())) {
        lafManager.setCurrentLookAndFeel(info);
        lafManager.updateUI();
    }
}
Also used : Task(com.intellij.openapi.progress.Task) DarculaLookAndFeelInfo(com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo) ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) DarculaLookAndFeelInfo(com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo) Project(com.intellij.openapi.project.Project) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) LafManagerImpl(com.intellij.ide.ui.laf.LafManagerImpl) KeymapManagerImpl(com.intellij.openapi.keymap.impl.KeymapManagerImpl)

Example 57 with ProgressIndicator

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

the class DaemonCodeAnalyzerImpl method runMainPasses.

@Override
@NotNull
public List<HighlightInfo> runMainPasses(@NotNull PsiFile psiFile, @NotNull Document document, @NotNull final ProgressIndicator progress) {
    if (ApplicationManager.getApplication().isDispatchThread()) {
        throw new IllegalStateException("Must not run highlighting from under EDT");
    }
    if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
        throw new IllegalStateException("Must run highlighting from under read action");
    }
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (!(indicator instanceof DaemonProgressIndicator)) {
        throw new IllegalStateException("Must run highlighting under progress with DaemonProgressIndicator");
    }
    // clear status maps to run passes from scratch so that refCountHolder won't conflict and try to restart itself on partially filled maps
    myFileStatusMap.markAllFilesDirty("prepare to run main passes");
    stopProcess(false, "disable background daemon");
    myPassExecutorService.cancelAll(true);
    final List<HighlightInfo> result;
    try {
        result = new ArrayList<>();
        final VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null && !virtualFile.getFileType().isBinary()) {
            List<TextEditorHighlightingPass> passes = TextEditorHighlightingPassRegistrarEx.getInstanceEx(myProject).instantiateMainPasses(psiFile, document, HighlightInfoProcessor.getEmpty());
            Collections.sort(passes, (o1, o2) -> {
                if (o1 instanceof GeneralHighlightingPass)
                    return -1;
                if (o2 instanceof GeneralHighlightingPass)
                    return 1;
                return 0;
            });
            try {
                for (TextEditorHighlightingPass pass : passes) {
                    pass.doCollectInformation(progress);
                    result.addAll(pass.getInfos());
                }
            } catch (ProcessCanceledException e) {
                LOG.debug("Canceled: " + progress);
                throw e;
            }
        }
    } finally {
        stopProcess(true, "re-enable background daemon after main passes run");
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextEditorHighlightingPass(com.intellij.codeHighlighting.TextEditorHighlightingPass) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 58 with ProgressIndicator

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

the class LocalInspectionsPass method visitPriorityElementsAndInit.

@NotNull
private List<InspectionContext> visitPriorityElementsAndInit(@NotNull Map<LocalInspectionToolWrapper, Set<String>> toolToSpecifiedLanguageIds, @NotNull final InspectionManager iManager, final boolean isOnTheFly, @NotNull final ProgressIndicator indicator, @NotNull final List<PsiElement> elements, @NotNull final LocalInspectionToolSession session, @NotNull final Set<String> elementDialectIds) {
    final List<InspectionContext> init = new ArrayList<>();
    List<Map.Entry<LocalInspectionToolWrapper, Set<String>>> entries = new ArrayList<>(toolToSpecifiedLanguageIds.entrySet());
    Processor<Map.Entry<LocalInspectionToolWrapper, Set<String>>> processor = pair -> {
        LocalInspectionToolWrapper toolWrapper = pair.getKey();
        Set<String> dialectIdsSpecifiedForTool = pair.getValue();
        runToolOnElements(toolWrapper, dialectIdsSpecifiedForTool, iManager, isOnTheFly, indicator, elements, session, init, elementDialectIds);
        return true;
    };
    boolean result = JobLauncher.getInstance().invokeConcurrentlyUnderProgress(entries, indicator, myFailFastOnAcquireReadAction, processor);
    if (!result)
        throw new ProcessCanceledException();
    return init;
}
Also used : Language(com.intellij.lang.Language) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) Trinity(com.intellij.openapi.util.Trinity) UIUtil(com.intellij.util.ui.UIUtil) com.intellij.codeInspection.ex(com.intellij.codeInspection.ex) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) Keymap(com.intellij.openapi.keymap.Keymap) THashMap(gnu.trove.THashMap) IdeActions(com.intellij.openapi.actionSystem.IdeActions) ProjectInspectionProfileManager(com.intellij.profile.codeInspection.ProjectInspectionProfileManager) HighlightingLevelManager(com.intellij.codeInsight.daemon.impl.analysis.HighlightingLevelManager) Logger(com.intellij.openapi.diagnostic.Logger) InspectionToolPresentation(com.intellij.codeInspection.ui.InspectionToolPresentation) CommonProcessors(com.intellij.util.CommonProcessors) RangeMarker(com.intellij.openapi.editor.RangeMarker) ProgressManager(com.intellij.openapi.progress.ProgressManager) DocumentWindow(com.intellij.injected.editor.DocumentWindow) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) TextRange(com.intellij.openapi.util.TextRange) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) Pass(com.intellij.codeHighlighting.Pass) Nullable(org.jetbrains.annotations.Nullable) DaemonBundle(com.intellij.codeInsight.daemon.DaemonBundle) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Processor(com.intellij.util.Processor) SmartHashSet(com.intellij.util.containers.SmartHashSet) ApplicationManager(com.intellij.openapi.application.ApplicationManager) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) InspectionProjectProfileManager(com.intellij.profile.codeInspection.InspectionProjectProfileManager) java.util(java.util) KeymapManager(com.intellij.openapi.keymap.KeymapManager) JobLauncher(com.intellij.concurrency.JobLauncher) NonNls(org.jetbrains.annotations.NonNls) TransferToEDTQueue(com.intellij.util.containers.TransferToEDTQueue) QuickFixAction(com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction) ContainerUtil(com.intellij.util.containers.ContainerUtil) Function(java.util.function.Function) ConcurrentMap(java.util.concurrent.ConcurrentMap) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) EmptyIntentionAction(com.intellij.codeInsight.intention.EmptyIntentionAction) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) StringUtil(com.intellij.openapi.util.text.StringUtil) ConcurrencyUtil(com.intellij.util.ConcurrencyUtil) com.intellij.codeInspection(com.intellij.codeInspection) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) Pair(com.intellij.openapi.util.Pair) Condition(com.intellij.openapi.util.Condition) THashSet(gnu.trove.THashSet) SmartHashSet(com.intellij.util.containers.SmartHashSet) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 59 with ProgressIndicator

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

the class LocalInspectionsPass method doInspectInBatch.

public void doInspectInBatch(@NotNull final GlobalInspectionContextImpl context, @NotNull final InspectionManager iManager, @NotNull final List<LocalInspectionToolWrapper> toolWrappers) {
    final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
    inspect(new ArrayList<>(toolWrappers), iManager, false, false, progress);
    addDescriptorsFromInjectedResults(iManager, context);
    List<InspectionResult> resultList = result.get(getFile());
    if (resultList == null)
        return;
    for (InspectionResult inspectionResult : resultList) {
        LocalInspectionToolWrapper toolWrapper = inspectionResult.tool;
        for (ProblemDescriptor descriptor : inspectionResult.foundProblems) {
            addDescriptors(toolWrapper, descriptor, context);
        }
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 60 with ProgressIndicator

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

the class HTMLExportUtil method writeFile.

public static void writeFile(final String folder, @NonNls final String fileName, CharSequence buf, final Project project) {
    ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    final File fullPath = new File(folder + File.separator + fileName);
    if (indicator != null) {
        ProgressManager.checkCanceled();
        indicator.setText(InspectionsBundle.message("inspection.export.generating.html.for", fullPath.getAbsolutePath()));
    }
    try {
        FileWriter writer = null;
        try {
            final File dir = fullPath.getParentFile();
            if (!dir.exists() && !dir.mkdirs()) {
                showErrorMessage("Can't create dir", dir, project);
                return;
            }
            if (!dir.canWrite() && !fullPath.canWrite()) {
                showErrorMessage("Permission denied", fullPath, project);
                return;
            }
            writer = new FileWriter(fullPath, false);
            writer.write(buf.toString().toCharArray());
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                //Cannot do anything in case of exception
                }
            }
        }
    } catch (IOException e) {
        showErrorMessage(String.valueOf(e.getCause()), fullPath, project);
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)351 Task (com.intellij.openapi.progress.Task)138 NotNull (org.jetbrains.annotations.NotNull)98 VirtualFile (com.intellij.openapi.vfs.VirtualFile)96 Project (com.intellij.openapi.project.Project)78 File (java.io.File)52 IOException (java.io.IOException)47 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)44 Nullable (org.jetbrains.annotations.Nullable)43 ProgressManager (com.intellij.openapi.progress.ProgressManager)35 List (java.util.List)30 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)28 Ref (com.intellij.openapi.util.Ref)27 VcsException (com.intellij.openapi.vcs.VcsException)25 ArrayList (java.util.ArrayList)23 ApplicationManager (com.intellij.openapi.application.ApplicationManager)22 Module (com.intellij.openapi.module.Module)21 Logger (com.intellij.openapi.diagnostic.Logger)20 java.util (java.util)20 Processor (com.intellij.util.Processor)18