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();
}
}
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);
}
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);
}
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();
}
};
}
Aggregations