mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] simplify runWhenLogIsReady method
There is no need to wait for VCS_PROJECT_LOG_CHANGED event, when createLog can just return VcsLogManager. GitOrigin-RevId: 2cd324d229926bf9a0edc8d135534a9b148558f9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
831ae5f56d
commit
e52dbd3c68
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.vcs.log.impl;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
@@ -19,12 +20,10 @@ import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ContentUtilEx;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.vcs.log.VcsLogUi;
|
||||
import com.intellij.vcs.log.ui.AbstractVcsLogUi;
|
||||
import com.intellij.vcs.log.ui.VcsLogPanel;
|
||||
import com.intellij.vcs.log.ui.VcsLogUiImpl;
|
||||
import com.intellij.vcs.log.util.VcsLogUtil;
|
||||
import org.jetbrains.annotations.CalledInAwt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,8 +31,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
@@ -200,29 +197,18 @@ public class VcsLogContentUtil {
|
||||
action.accept(log, manager);
|
||||
}
|
||||
else { // schedule showing the log, wait its initialization, and then open the tab
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
MessageBusConnection connection = project.getMessageBus().connect(log);
|
||||
connection.subscribe(VcsProjectLog.VCS_PROJECT_LOG_CHANGED, new VcsProjectLog.ProjectLogListener() {
|
||||
@Override
|
||||
public void logCreated(@NotNull VcsLogManager logManager) {
|
||||
latch.countDown();
|
||||
action.accept(log, logManager);
|
||||
connection.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
new Task.Backgroundable(project, "Loading Commits") {
|
||||
@Nullable private VcsLogManager myLogManager;
|
||||
|
||||
@Override
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
log.createLog(true);
|
||||
myLogManager = log.createLog(true);
|
||||
}
|
||||
|
||||
try {
|
||||
while (!latch.await(50, TimeUnit.MILLISECONDS)) {
|
||||
indicator.checkCanceled();
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOG.error(e);
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
if (myLogManager != null) {
|
||||
action.accept(log, myLogManager);
|
||||
}
|
||||
}
|
||||
}.queue();
|
||||
|
||||
@@ -133,16 +133,18 @@ public class VcsProjectLog implements Disposable {
|
||||
recreateLog();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@CalledInBackground
|
||||
void createLog(boolean forceInit) {
|
||||
VcsLogManager createLog(boolean forceInit) {
|
||||
Map<VirtualFile, VcsLogProvider> logProviders = getLogProviders();
|
||||
if (!logProviders.isEmpty()) {
|
||||
createLog(logProviders, forceInit);
|
||||
return createLog(logProviders, forceInit);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@CalledInBackground
|
||||
private void createLog(@NotNull Map<VirtualFile, VcsLogProvider> logProviders, boolean forceInit) {
|
||||
private VcsLogManager createLog(@NotNull Map<VirtualFile, VcsLogProvider> logProviders, boolean forceInit) {
|
||||
VcsLogManager logManager = myLogManager.getValue(logProviders);
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(() -> {
|
||||
@@ -156,6 +158,8 @@ public class VcsProjectLog implements Disposable {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return logManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user