Search in sources :

Example 6 with SequentialModalProgressTask

use of com.intellij.util.SequentialModalProgressTask in project intellij-community by JetBrains.

the class CompositeSequentialTask method getFieldNamesAffectingCodeFragment.

@NotNull
public CodeStyleSettingsToShow getFieldNamesAffectingCodeFragment(LanguageCodeStyleSettingsProvider.SettingsType... types) {
    CodeStyleSettingsManager codeStyleSettingsManager = CodeStyleSettingsManager.getInstance(myProject);
    CodeStyleSettings clonedSettings = codeStyleSettingsManager.getCurrentSettings().clone();
    myCommonSettings = clonedSettings.getCommonSettings(myProvider.getLanguage());
    try {
        codeStyleSettingsManager.setTemporarySettings(clonedSettings);
        String title = CodeInsightBundle.message("configure.code.style.on.fragment.dialog.title");
        SequentialModalProgressTask progressTask = new SequentialModalProgressTask(myProject, StringUtil.capitalizeWords(title, true));
        progressTask.setCancelText(CodeInsightBundle.message("configure.code.style.on.fragment.dialog.cancel"));
        CompositeSequentialTask compositeTask = new CompositeSequentialTask(progressTask);
        compositeTask.setProgressText(CodeInsightBundle.message("configure.code.style.on.fragment.dialog.progress.text"));
        compositeTask.setProgressText2(CodeInsightBundle.message("configure.code.style.on.fragment.dialog.progress.text.under"));
        final Map<LanguageCodeStyleSettingsProvider.SettingsType, FilterFieldsTask> typeToTask = ContainerUtil.newHashMap();
        for (LanguageCodeStyleSettingsProvider.SettingsType type : types) {
            Set<String> fields = myProvider.getSupportedFields(type);
            FilterFieldsTask task = new FilterFieldsTask(fields);
            compositeTask.addTask(task);
            typeToTask.put(type, task);
        }
        Set<String> otherFields = myProvider.getSupportedFields();
        final FilterFieldsTask otherFieldsTask = new FilterFieldsTask(otherFields);
        if (!otherFields.isEmpty()) {
            compositeTask.addTask(otherFieldsTask);
        }
        progressTask.setTask(compositeTask);
        progressTask.setMinIterationTime(10);
        ProgressManager.getInstance().run(progressTask);
        return new CodeStyleSettingsToShow() {

            @Override
            public List<String> getSettings(LanguageCodeStyleSettingsProvider.SettingsType type) {
                FilterFieldsTask task = typeToTask.get(type);
                return task.getAffectedFields();
            }

            @Override
            public List<String> getOtherSetting() {
                return ContainerUtil.newArrayList(otherFieldsTask.getAffectedFields());
            }
        };
    } finally {
        codeStyleSettingsManager.dropTemporarySettings();
    }
}
Also used : SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with SequentialModalProgressTask

use of com.intellij.util.SequentialModalProgressTask in project intellij-community by JetBrains.

the class UpdateCopyrightAction method analyze.

@Override
protected void analyze(@NotNull final Project project, @NotNull final AnalysisScope scope) {
    PropertiesComponent.getInstance().setValue(UPDATE_EXISTING_COPYRIGHTS, String.valueOf(myUpdateExistingCopyrightsCb.isSelected()), "true");
    final Map<PsiFile, Runnable> preparations = new LinkedHashMap<>();
    Task.Backgroundable task = new Task.Backgroundable(project, "Prepare Copyright...", true) {

        @Override
        public void run(@NotNull final ProgressIndicator indicator) {
            scope.accept(new PsiElementVisitor() {

                @Override
                public void visitFile(final PsiFile file) {
                    if (indicator.isCanceled()) {
                        return;
                    }
                    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
                    final UpdateCopyrightProcessor processor = new UpdateCopyrightProcessor(project, module, file);
                    final Runnable runnable = processor.preprocessFile(file, myUpdateExistingCopyrightsCb.isSelected());
                    if (runnable != EmptyRunnable.getInstance()) {
                        preparations.put(file, runnable);
                    }
                }
            });
        }

        @Override
        public void onSuccess() {
            if (!preparations.isEmpty()) {
                if (!FileModificationService.getInstance().preparePsiElementsForWrite(preparations.keySet()))
                    return;
                final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, UpdateCopyrightProcessor.TITLE, true);
                progressTask.setMinIterationTime(200);
                progressTask.setTask(new UpdateCopyrightSequentialTask(preparations, progressTask));
                CommandProcessor.getInstance().executeCommand(project, () -> {
                    CommandProcessor.getInstance().markCurrentCommandAsGlobal(project);
                    ProgressManager.getInstance().run(progressTask);
                }, getTemplatePresentation().getText(), null);
            }
        }
    };
    ProgressManager.getInstance().run(task);
}
Also used : SequentialTask(com.intellij.util.SequentialTask) Task(com.intellij.openapi.progress.Task) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) NotNull(org.jetbrains.annotations.NotNull) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) LinkedHashMap(java.util.LinkedHashMap) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) Module(com.intellij.openapi.module.Module)

Example 8 with SequentialModalProgressTask

use of com.intellij.util.SequentialModalProgressTask in project intellij-community by JetBrains.

the class ConvertSchemaPrefixToDefaultIntention method convertTagsAndAttributes.

private static void convertTagsAndAttributes(String ns, final List<XmlTag> tags, final List<XmlAttribute> attrs, Project project) {
    final int localNameIndex = ns.length() + 1;
    final int totalCount = tags.size() + attrs.size();
    final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, "Changing to default namespace", true);
    progressTask.setTask(new SequentialTask() {

        int tagIndex = 0;

        int attrIndex = 0;

        @Override
        public void prepare() {
        }

        @Override
        public boolean isDone() {
            return tagIndex + attrIndex >= totalCount;
        }

        @Override
        public boolean iteration() {
            progressTask.getIndicator().setFraction(((double) (tagIndex + attrIndex)) / totalCount);
            ApplicationManager.getApplication().runWriteAction(() -> {
                if (tagIndex < tags.size()) {
                    XmlTag tag = tags.get(tagIndex++);
                    final String s = tag.getName().substring(localNameIndex);
                    if (!s.isEmpty()) {
                        tag.setName(s);
                    }
                } else if (attrIndex < attrs.size()) {
                    XmlAttribute attr = attrs.get(attrIndex++);
                    //noinspection ConstantConditions
                    attr.setValue(attr.getValue().substring(localNameIndex));
                }
            });
            return isDone();
        }

        @Override
        public void stop() {
        }
    });
    ProgressManager.getInstance().run(progressTask);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) SequentialTask(com.intellij.util.SequentialTask) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) XmlTag(com.intellij.psi.xml.XmlTag)

Example 9 with SequentialModalProgressTask

use of com.intellij.util.SequentialModalProgressTask in project android by JetBrains.

the class InferSupportAnnotationsAction method applyRunnable.

private static Runnable applyRunnable(Project project, Computable<UsageInfo[]> computable) {
    return () -> {
        LocalHistoryAction action = LocalHistory.getInstance().startAction(INFER_SUPPORT_ANNOTATIONS);
        try {
            new WriteCommandAction(project, INFER_SUPPORT_ANNOTATIONS) {

                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    UsageInfo[] infos = computable.compute();
                    if (infos.length > 0) {
                        Set<PsiElement> elements = new LinkedHashSet<>();
                        for (UsageInfo info : infos) {
                            PsiElement element = info.getElement();
                            if (element != null) {
                                PsiFile containingFile = element.getContainingFile();
                                // Skip results in .class files; these are typically from extracted AAR files
                                VirtualFile virtualFile = containingFile.getVirtualFile();
                                if (virtualFile.getFileType().isBinary()) {
                                    continue;
                                }
                                ContainerUtil.addIfNotNull(elements, containingFile);
                            }
                        }
                        if (!FileModificationService.getInstance().preparePsiElementsForWrite(elements))
                            return;
                        SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, INFER_SUPPORT_ANNOTATIONS, false);
                        progressTask.setMinIterationTime(200);
                        progressTask.setTask(new AnnotateTask(project, progressTask, infos));
                        ProgressManager.getInstance().run(progressTask);
                    } else {
                        InferSupportAnnotations.nothingFoundMessage(project);
                    }
                }
            }.execute();
        } finally {
            action.finish();
        }
    };
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NotNull(org.jetbrains.annotations.NotNull) SequentialModalProgressTask(com.intellij.util.SequentialModalProgressTask) Result(com.intellij.openapi.application.Result) LocalHistoryAction(com.intellij.history.LocalHistoryAction) UsageInfo(com.intellij.usageView.UsageInfo)

Aggregations

SequentialModalProgressTask (com.intellij.util.SequentialModalProgressTask)9 NotNull (org.jetbrains.annotations.NotNull)5 LocalHistoryAction (com.intellij.history.LocalHistoryAction)3 Result (com.intellij.openapi.application.Result)3 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 UsageInfo (com.intellij.usageView.UsageInfo)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 SequentialTask (com.intellij.util.SequentialTask)2 Module (com.intellij.openapi.module.Module)1 Task (com.intellij.openapi.progress.Task)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 PsiElement (com.intellij.psi.PsiElement)1 JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 LinkedHashMap (java.util.LinkedHashMap)1