From 37a88f9b3d6b6e258ba4288c0c7ad7c0a52b855d Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 8 Apr 2011 17:53:17 +0400 Subject: [PATCH] progress for files --- .../changes/shelf/ShelveChangesManager.java | 5 +- .../com/intellij/vcsUtil/FilesProgress.java | 62 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 platform/vcs-impl/src/com/intellij/vcsUtil/FilesProgress.java diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java index 97ec0edcd960..f904fb734eb7 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelveChangesManager.java @@ -51,6 +51,7 @@ import com.intellij.util.continuation.*; import com.intellij.util.messages.MessageBus; import com.intellij.util.messages.Topic; import com.intellij.util.text.CharArrayCharSequence; +import com.intellij.vcsUtil.FilesProgress; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -237,9 +238,9 @@ public class ShelveChangesManager implements ProjectComponent, JDOMExternalizabl public List importChangeLists(final Collection files, final Consumer exceptionConsumer) { final List result = new ArrayList(files.size()); try { + final FilesProgress filesProgress = new FilesProgress(files.size(), "Processing "); for (VirtualFile file : files) { - ProgressManager.checkCanceled(); - + filesProgress.updateIndicator(file); final String description = file.getNameWithoutExtension().replace('_', ' '); final File patchPath = getPatchPath(description); final ShelvedChangeList list = new ShelvedChangeList(patchPath.getPath(), description, new SmartList(), diff --git a/platform/vcs-impl/src/com/intellij/vcsUtil/FilesProgress.java b/platform/vcs-impl/src/com/intellij/vcsUtil/FilesProgress.java new file mode 100644 index 000000000000..60dfc96bdf09 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/vcsUtil/FilesProgress.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.vcsUtil; + +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.vfs.VirtualFile; + +/** + * @author irengrig + * Date: 4/8/11 + * Time: 5:15 PM + */ +public class FilesProgress { + private final double myTotal; + private final String myPrefix; + private final ProgressIndicator myProgressIndicator; + private int myCnt; + private boolean myInText2; + + public FilesProgress(double total, final String prefix) { + myTotal = total; + myPrefix = prefix; + myProgressIndicator = ProgressManager.getInstance().getProgressIndicator(); + myCnt = 0; + myInText2 = false; + } + + public void updateIndicator(final VirtualFile vf) { + if (myProgressIndicator == null) return; + myProgressIndicator.checkCanceled(); + if (myInText2) { + myProgressIndicator.setText2(myPrefix + getFileDescriptionForProgress(vf)); + } else { + myProgressIndicator.setText(myPrefix + getFileDescriptionForProgress(vf)); + } + myProgressIndicator.setFraction(myCnt/myTotal); + ++ myCnt; + } + + private static String getFileDescriptionForProgress(final VirtualFile file) { + final VirtualFile parent = file.getParent(); + return file.getName() + " (" + (parent == null ? file.getPath() : parent.getPath()) + ")"; + } + + public void setInText2(boolean inText2) { + myInText2 = inText2; + } +}