[vcs-log] move code that opens log to VcsLogContentProvider

This commit is contained in:
Julia Beliaeva
2017-08-09 00:05:12 +03:00
parent f701aaad1a
commit 163ee89ff7
2 changed files with 42 additions and 47 deletions
@@ -18,10 +18,13 @@ package com.intellij.vcs.log.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentProvider;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
@@ -29,6 +32,7 @@ import com.intellij.ui.components.JBPanel;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
import com.intellij.ui.content.TabbedContent;
import com.intellij.util.Consumer;
import com.intellij.util.ContentUtilEx;
import com.intellij.util.ContentsUtil;
import com.intellij.util.NotNullFunction;
@@ -193,6 +197,43 @@ public class VcsLogContentProvider implements ChangesViewContentProvider {
}
}
public static void openMainLogAndExecute(@NotNull Project project, @NotNull Consumer<VcsLogUiImpl> consumer) {
VcsProjectLog projectLog = VcsProjectLog.getInstance(project);
boolean logReady = projectLog.getMainLogUi() != null;
ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(ChangesViewContentManager.TOOLWINDOW_ID);
ContentManager cm = window.getContentManager();
Content[] contents = cm.getContents();
for (Content content : contents) {
if (TAB_NAME.equals(content.getDisplayName())) {
cm.setSelectedContent(content);
break;
}
}
VcsLogUiImpl logUi = projectLog.getMainLogUi();
if (logUi == null) {
VcsBalloonProblemNotifier.showOverChangesView(project, "Vcs Log Not Ready", MessageType.WARNING);
return;
}
Runnable openLogAndRun = () -> {
if (!window.isVisible()) {
window.activate(() -> consumer.consume(logUi), true);
}
else {
consumer.consume(logUi);
}
};
if (logReady) {
openLogAndRun.run();
return;
}
logUi.invokeOnChange(openLogAndRun);
}
public static class VcsLogVisibilityPredicate implements NotNullFunction<Project, Boolean> {
@NotNull
@Override
@@ -25,19 +25,12 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.VcsKey;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import com.intellij.openapi.vcs.history.VcsFileRevision;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
import com.intellij.vcs.log.impl.VcsLogContentProvider;
import com.intellij.vcs.log.impl.VcsProjectLog;
import com.intellij.vcs.log.ui.VcsLogUiImpl;
@@ -65,46 +58,7 @@ public class GitShowCommitInLogAction extends DumbAwareAction {
return;
}
VcsProjectLog projectLog = VcsProjectLog.getInstance(project);
boolean logReady = projectLog.getMainLogUi() != null;
ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(ChangesViewContentManager.TOOLWINDOW_ID);
ContentManager cm = window.getContentManager();
Content[] contents = cm.getContents();
for (Content content : contents) {
if (VcsLogContentProvider.TAB_NAME.equals(content.getDisplayName())) {
cm.setSelectedContent(content);
break;
}
}
VcsLogUiImpl logUi = projectLog.getMainLogUi();
if (logUi == null) {
showLogNotReadyMessage(project);
return;
}
Runnable selectAndOpenLog = () -> {
Runnable selectCommit = () -> jumpToRevisionUnderProgress(project, logUi, revision);
if (!window.isVisible()) {
window.activate(selectCommit, true);
}
else {
selectCommit.run();
}
};
if (logReady) {
selectAndOpenLog.run();
return;
}
logUi.invokeOnChange(selectAndOpenLog);
}
private static void showLogNotReadyMessage(@NotNull Project project) {
VcsBalloonProblemNotifier.showOverChangesView(project, GitBundle.getString("vcs.history.action.gitlog.error"), MessageType.WARNING);
VcsLogContentProvider.openMainLogAndExecute(project, logUi -> jumpToRevisionUnderProgress(project, logUi, revision));
}
@Nullable