From 237e80615ccc8be082e77c08510e32b8489ae896 Mon Sep 17 00:00:00 2001 From: Yaroslav Lepenkin Date: Mon, 26 Jan 2015 19:25:45 +0300 Subject: [PATCH] Setting proper text on progress indicator (IDEA-34049) on bulk reformat/optimize actions --- .../actions/AbstractLayoutCodeProcessor.java | 28 +++++++++++++++---- .../src/messages/ApplicationBundle.properties | 2 ++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java index 5fd44fe874ac..e2447f775f6a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/AbstractLayoutCodeProcessor.java @@ -18,6 +18,7 @@ package com.intellij.codeInsight.actions; import com.intellij.codeInsight.CodeInsightBundle; import com.intellij.lang.LanguageFormatting; +import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.command.CommandProcessor; @@ -32,6 +33,7 @@ import com.intellij.openapi.progress.util.ProgressWindow; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectCoreUtil; +import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.roots.GeneratedSourcesFilter; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.ex.MessagesEx; @@ -498,16 +500,18 @@ public abstract class AbstractLayoutCodeProcessor { } if (!myFilesCountingFinished) { + updateIndicatorText(ApplicationBundle.message("bulk.reformat.prepare.progress.text"), ""); countingIteration(); return true; } - updateIndicator(myFilesProcessed); + updateIndicatorFraction(myFilesProcessed); if (myFileTreeIterator.hasNext()) { final PsiFile file = myFileTreeIterator.next(); myFilesProcessed++; if (file.isWritable() && canBeFormatted(file) && acceptedByFilters(file)) { + updateIndicatorText(ApplicationBundle.message("bulk.reformat.process.progress.text"), getPresentablePath(file)); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { @@ -536,11 +540,23 @@ public abstract class AbstractLayoutCodeProcessor { } } - private void updateIndicator(int filesProcessed) { - if (myCompositeTask != null) { - ProgressIndicator indicator = myCompositeTask.getIndicator(); - if (indicator != null) - indicator.setFraction((double)filesProcessed / myTotalFiles); + private void updateIndicatorText(@NotNull String upperLabel, @NotNull String downLabel) { + ProgressIndicator indicator = myCompositeTask.getIndicator(); + if (indicator != null) { + indicator.setText(upperLabel); + indicator.setText2(downLabel); + } + } + + private String getPresentablePath(@NotNull PsiFile file) { + VirtualFile vFile = file.getVirtualFile(); + return vFile != null ? ProjectUtil.calcRelativeToProjectPath(vFile, myProject) : file.getName(); + } + + private void updateIndicatorFraction(int processed) { + ProgressIndicator indicator = myCompositeTask.getIndicator(); + if (indicator != null) { + indicator.setFraction((double)processed / myTotalFiles); } } diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index aefd8b22ceff..45c1cb1dcdd7 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -682,6 +682,8 @@ wrapping.after.annotations=After last field annotation reformat.changed.text.file.too.big.notification.groupId=Reformat changed text reformat.changed.text.file.too.big.notification.title=Couldn't calculate changed ranges reformat.changed.text.file.too.big.notification.text=file {0} is too big or there are too many changes +bulk.reformat.prepare.progress.text=Preparing... +bulk.reformat.process.progress.text=Processing... code.style.indents.detector.display.name=Automatic indent options detector code.style.indents.detector.message=Indent options for the file are overwritten by {0}