[vcs-log] keep main log ui in VcsLogContentProvider

This commit is contained in:
Julia Beliaeva
2017-08-21 02:23:15 +03:00
parent 0d2393912d
commit c15adc11e5
2 changed files with 34 additions and 25 deletions
@@ -20,6 +20,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentEP;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentProvider;
import com.intellij.ui.components.JBPanel;
import com.intellij.util.NotNullFunction;
@@ -47,6 +48,8 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
@NotNull private final VcsProjectLog myProjectLog;
@NotNull private final JPanel myContainer = new JBPanel(new BorderLayout());
@Nullable private volatile VcsLogUiImpl myUi;
public VcsLogContentProvider(@NotNull Project project, @NotNull VcsProjectLog projectLog) {
myProject = project;
myProjectLog = projectLog;
@@ -70,13 +73,17 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
}
}
@Nullable
public VcsLogUiImpl getUi() {
return myUi;
}
@CalledInAwt
private void addLogUi(@NotNull VcsLogManager logManager) {
LOG.assertTrue(ApplicationManager.getApplication().isDispatchThread());
if (myProjectLog.getMainLogUi() == null) {
VcsLogUiImpl ui = logManager.createLogUi(VcsLogTabsProperties.MAIN_LOG_ID, TAB_NAME);
myProjectLog.setMainUi(ui);
myContainer.add(new VcsLogPanel(logManager, ui), BorderLayout.CENTER);
if (myUi == null) {
myUi = logManager.createLogUi(VcsLogTabsProperties.MAIN_LOG_ID, TAB_NAME);
myContainer.add(new VcsLogPanel(logManager, myUi), BorderLayout.CENTER);
}
}
@@ -86,8 +93,11 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
// main ui
myContainer.removeAll();
VcsLogUiImpl ui = myProjectLog.getMainLogUi();
if (ui != null) Disposer.dispose(ui);
if (myUi != null) {
VcsLogUiImpl ui = myUi;
myUi = null;
Disposer.dispose(ui);
}
// other tabs
if (logManager != null) {
@@ -106,6 +116,17 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
disposeLogUi(myProjectLog.getLogManager());
}
@Nullable
public static VcsLogContentProvider getInstance(@NotNull Project project) {
ChangesViewContentEP[] extensions = project.getExtensions(ChangesViewContentEP.EP_NAME);
for (ChangesViewContentEP ep: extensions) {
if (ep.getClassName().equals(VcsLogContentProvider.class.getName())) {
return (VcsLogContentProvider)ep.getInstance(project);
}
}
return null;
}
public static class VcsLogVisibilityPredicate implements NotNullFunction<Project, Boolean> {
@NotNull
@Override
@@ -33,7 +33,10 @@ import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.messages.Topic;
import com.intellij.vcs.log.data.VcsLogData;
import com.intellij.vcs.log.ui.VcsLogUiImpl;
import org.jetbrains.annotations.*;
import org.jetbrains.annotations.CalledInAwt;
import org.jetbrains.annotations.CalledInBackground;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collection;
@@ -71,17 +74,14 @@ public class VcsProjectLog implements Disposable {
return Arrays.asList(ProjectLevelVcsManager.getInstance(myProject).getAllVcsRoots());
}
@CalledInAny
void setMainUi(@NotNull VcsLogUiImpl ui) {
myLogManager.setLogUi(ui);
}
/**
* The instance of the {@link VcsLogUiImpl} or null if the log was not initialized yet.
*/
@Nullable
public VcsLogUiImpl getMainLogUi() {
return myLogManager.getLogUi();
VcsLogContentProvider logContentProvider = VcsLogContentProvider.getInstance(myProject);
if (logContentProvider == null) return null;
return logContentProvider.getUi();
}
@Nullable
@@ -151,7 +151,6 @@ public class VcsProjectLog implements Disposable {
private class LazyVcsLogManager {
@Nullable private VcsLogManager myValue;
@Nullable private VcsLogUiImpl myUi;
@NotNull
@CalledInBackground
@@ -187,7 +186,6 @@ public class VcsProjectLog implements Disposable {
}
});
}
myUi = null;
myValue = null;
}
@@ -195,16 +193,6 @@ public class VcsProjectLog implements Disposable {
public synchronized VcsLogManager getCached() {
return myValue;
}
public synchronized void setLogUi(@NotNull VcsLogUiImpl ui) {
myUi = ui;
}
@Nullable
@CalledInAny
public synchronized VcsLogUiImpl getLogUi() {
return myUi;
}
}
public static class InitLogStartupActivity implements StartupActivity {