--- /dev/null
+/*
+ * Copyright 2000-2010 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.util;
+
+public interface CatchingConsumer<T, E extends Throwable> extends Consumer<T> {
+ void consume(E e);
+}
--- /dev/null
+/*
+ * Copyright 2000-2010 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.util;
+
+import com.intellij.openapi.application.Application;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.util.Ref;
+import com.intellij.openapi.util.ThrowableComputable;
+
+public class CalculateContinuation<T> {
+ public void calculateAndContinue(final ThrowableComputable<T, Exception> computable, final CatchingConsumer<T, Exception> consumer) {
+ final Application application = ApplicationManager.getApplication();
+
+ application.assertIsDispatchThread();
+
+ final Ref<T> t = new Ref<T>();
+ application.executeOnPooledThread(new Runnable() {
+ public void run() {
+ try {
+ t.set(computable.compute());
+ }
+ catch (final Exception e) {
+ application.invokeLater(new Runnable() {
+ public void run() {
+ consumer.consume(e);
+ }
+ });
+ }
+
+ application.invokeLater(new Runnable() {
+ public void run() {
+ consumer.consume(t.get());
+ }
+ });
+ }
+ });
+ }
+}
import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
+import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.VcsListener;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
+import com.intellij.util.CalculateContinuation;
+import com.intellij.util.CatchingConsumer;
import com.intellij.util.containers.HashMap;
import git4idea.GitBranchesSearcher;
import git4idea.GitVcs;
final VirtualFile baseDir = myProject.getBaseDir();
final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
- for (VirtualFile root : roots) {
+ for (final VirtualFile root : roots) {
if (! currentState.containsKey(root)) {
final GitLogTree tree = new GitLogTree(myProject, root);
tree.setParentDisposable(myProject);
content.setCloseable(false);
cvcm.addContent(content);
newKeys.put(root, content);
+
+ new CalculateContinuation<String>().calculateAndContinue(new ThrowableComputable<String, Exception>() {
+ public String compute() throws Exception {
+ return getCaption(baseDir, root);
+ }
+ }, new CatchingConsumer<String, Exception>() {
+ public void consume(Exception e) {
+ //should not
+ }
+ public void consume(final String caption) {
+ content.setDisplayName(caption);
+ }
+ });
}
}
}
private String getCaption(@Nullable VirtualFile baseDir, final VirtualFile root) {
- String result = root.getPresentableUrl();
+ String result = root.getPresentableUrl();
if (baseDir != null) {
if (baseDir.equals(root)) {
result = "<Project root>";