From 163ee89ff79bc1c5060662bf682a871d64836bba Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Tue, 8 Aug 2017 23:23:41 +0300 Subject: [PATCH] [vcs-log] move code that opens log to VcsLogContentProvider --- .../vcs/log/impl/VcsLogContentProvider.java | 41 ++++++++++++++++ .../log/GitShowCommitInLogAction.java | 48 +------------------ 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentProvider.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentProvider.java index 6b76e19a2ecb..d980b1a52683 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentProvider.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogContentProvider.java @@ -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 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 { @NotNull @Override diff --git a/plugins/git4idea/src/git4idea/log/GitShowCommitInLogAction.java b/plugins/git4idea/src/git4idea/log/GitShowCommitInLogAction.java index 5590179734cc..df977403cdd6 100644 --- a/plugins/git4idea/src/git4idea/log/GitShowCommitInLogAction.java +++ b/plugins/git4idea/src/git4idea/log/GitShowCommitInLogAction.java @@ -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