From 5bbddcbcadad768cf11749f5a3e3d768a757e3ef Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Fri, 18 Mar 2016 16:57:58 +0300 Subject: [PATCH] [vcs-log] refresh and open another log tab actions work for correct log manager instance --- .../vcs/log/impl/VcsLogContentProvider.java | 8 ++-- .../intellij/vcs/log/impl/VcsLogManager.java | 5 +-- .../vcs/log/impl/VcsLogProjectManager.java | 10 ----- .../intellij/vcs/log/ui/VcsLogDataKeys.java | 23 ++++++++++ .../com/intellij/vcs/log/ui/VcsLogPanel.java | 44 +++++++++++++++++++ .../ui/actions/OpenAnotherLogTabAction.java | 21 ++++----- .../vcs/log/ui/actions/RefreshLogAction.java | 22 +++------- 7 files changed, 90 insertions(+), 43 deletions(-) create mode 100644 platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogDataKeys.java create mode 100644 platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogPanel.java 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 13692da5a3e6..7d1b54bcef5b 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 @@ -33,6 +33,7 @@ import com.intellij.util.ContentsUtil; import com.intellij.util.NotNullFunction; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.messages.MessageBusConnection; +import com.intellij.vcs.log.ui.VcsLogPanel; import com.intellij.vcs.log.ui.VcsLogUiImpl; import org.jetbrains.annotations.NotNull; @@ -85,8 +86,7 @@ public class VcsLogContentProvider implements ChangesViewContentProvider { myLogManager.disposeLog(); } - public static void openAnotherLogTab(@NotNull Project project) { - VcsLogProjectManager logManager = VcsLogProjectManager.getInstance(project); + public static void openAnotherLogTab(@NotNull VcsLogManager logManager, @NotNull Project project) { ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.VCS); String shortName = generateShortName(toolWindow); @@ -111,14 +111,14 @@ public class VcsLogContentProvider implements ChangesViewContentProvider { } } - private static void addLogTab(@NotNull VcsLogProjectManager logManager, + private static void addLogTab(@NotNull VcsLogManager logManager, @NotNull ToolWindow toolWindow, @NotNull VcsLogUiImpl logUi, @NotNull String shortName) { logManager.watchTab(ContentUtilEx.getFullName(TAB_NAME, shortName), logUi); logUi.requestFocus(); ContentUtilEx - .addTabbedContent(toolWindow.getContentManager(), logUi.getMainFrame().getMainComponent(), TAB_NAME, shortName, true, logUi); + .addTabbedContent(toolWindow.getContentManager(), new VcsLogPanel(logManager, logUi), TAB_NAME, shortName, true, logUi); toolWindow.activate(null); } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java index e9492cdefc51..49a1c238da79 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogManager.java @@ -25,7 +25,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vcs.AbstractVcs; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsRoot; import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier; import com.intellij.openapi.vfs.VirtualFile; @@ -40,12 +39,12 @@ import com.intellij.vcs.log.data.VcsLogTabsProperties; import com.intellij.vcs.log.data.VcsLogUiProperties; import com.intellij.vcs.log.graph.PermanentGraph; import com.intellij.vcs.log.ui.VcsLogColorManagerImpl; +import com.intellij.vcs.log.ui.VcsLogPanel; import com.intellij.vcs.log.ui.VcsLogUiImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.Arrays; import java.util.Collection; import java.util.Map; @@ -105,7 +104,7 @@ public class VcsLogManager implements Disposable { watch(myUi); } myUi.requestFocus(); - return myUi.getMainFrame().getMainComponent(); + return new VcsLogPanel(this, myUi); } @NotNull diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogProjectManager.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogProjectManager.java index b7d69535e647..18a95b543ce8 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogProjectManager.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/impl/VcsLogProjectManager.java @@ -51,22 +51,12 @@ public class VcsLogProjectManager { return Arrays.asList(ProjectLevelVcsManager.getInstance(myProject).getAllVcsRoots()); } - public void watchTab(@NotNull String contentTabName, @NotNull VcsLogUiImpl logUi) { - myLogManager.watchTab(contentTabName, logUi); - } - @NotNull public JComponent initMainLog(@NotNull String contentTabName) { initData(); return myLogManager.initMainLog(contentTabName); } - @NotNull - public VcsLogUiImpl createLog(@NotNull String logId) { - initData(); - return myLogManager.createLog(logId); - } - public boolean initData() { if (myLogManager != null) return true; myLogManager = new VcsLogManager(myProject, myUiProperties, getVcsRoots()); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogDataKeys.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogDataKeys.java new file mode 100644 index 000000000000..408a249434d8 --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogDataKeys.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2016 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.vcs.log.ui; + +import com.intellij.openapi.actionSystem.DataKey; +import com.intellij.vcs.log.impl.VcsLogManager; + +public class VcsLogDataKeys { + public static final DataKey LOG_MANAGER = DataKey.create("Vcs.Log.Manager"); +} diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogPanel.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogPanel.java new file mode 100644 index 000000000000..1a2aea69400e --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogPanel.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2016 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.vcs.log.ui; + +import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.ui.components.JBPanel; +import com.intellij.vcs.log.impl.VcsLogManager; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.awt.*; + +public class VcsLogPanel extends JBPanel implements DataProvider { + @NotNull private final VcsLogManager myManager; + + public VcsLogPanel(@NotNull VcsLogManager manager, @NotNull VcsLogUiImpl logUi) { + super(new BorderLayout()); + myManager = manager; + add(logUi.getMainFrame().getMainComponent(), BorderLayout.CENTER); + } + + @Nullable + @Override + public Object getData(@NonNls String dataId) { + if (VcsLogDataKeys.LOG_MANAGER.is(dataId)) { + return myManager; + } + return null; + } +} diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/OpenAnotherLogTabAction.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/OpenAnotherLogTabAction.java index a72fca42e941..5919d59c25e6 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/OpenAnotherLogTabAction.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/OpenAnotherLogTabAction.java @@ -17,11 +17,14 @@ package com.intellij.vcs.log.ui.actions; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.registry.Registry; import com.intellij.vcs.log.impl.VcsLogContentProvider; +import com.intellij.vcs.log.impl.VcsLogManager; import com.intellij.vcs.log.impl.VcsLogProjectManager; -import com.intellij.vcs.log.ui.VcsLogUiImpl; +import com.intellij.vcs.log.ui.VcsLogDataKeys; public class OpenAnotherLogTabAction extends DumbAwareAction { protected OpenAnotherLogTabAction() { @@ -30,21 +33,19 @@ public class OpenAnotherLogTabAction extends DumbAwareAction { @Override public void update(AnActionEvent e) { - if (e.getProject() == null || !Registry.is("vcs.log.open.another.log.visible")) { + Project project = e.getProject(); + if (project == null || !Registry.is("vcs.log.open.another.log.visible")) { e.getPresentation().setEnabledAndVisible(false); return; } - VcsLogUiImpl mainLogUi = VcsLogProjectManager.getInstance(e.getProject()).getMainLogUi(); - if (mainLogUi == null) { - e.getPresentation().setEnabledAndVisible(false); - return; - } - - e.getPresentation().setEnabledAndVisible(true); + VcsLogProjectManager logProjectManager = VcsLogProjectManager.getInstance(project); + VcsLogManager logManager = e.getData(VcsLogDataKeys.LOG_MANAGER); + e.getPresentation() + .setEnabledAndVisible(logManager != null && logProjectManager.getLogManager() == logManager); // only for main log (it is a question, how and where we want to open tabs for external logs) } @Override public void actionPerformed(AnActionEvent e) { - VcsLogContentProvider.openAnotherLogTab(e.getProject()); + VcsLogContentProvider.openAnotherLogTab(e.getRequiredData(VcsLogDataKeys.LOG_MANAGER), e.getRequiredData(CommonDataKeys.PROJECT)); } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/RefreshLogAction.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/RefreshLogAction.java index 55253f635b14..66b16590a06f 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/RefreshLogAction.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/RefreshLogAction.java @@ -18,11 +18,8 @@ package com.intellij.vcs.log.ui.actions; import com.intellij.icons.AllIcons; import com.intellij.ide.actions.RefreshAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.project.Project; -import com.intellij.vcs.log.VcsLogDataKeys; -import com.intellij.vcs.log.data.VcsLogDataManager; -import com.intellij.vcs.log.impl.VcsLogProjectManager; +import com.intellij.vcs.log.impl.VcsLogManager; +import com.intellij.vcs.log.ui.VcsLogDataKeys; public class RefreshLogAction extends RefreshAction { public RefreshLogAction() { @@ -31,20 +28,13 @@ public class RefreshLogAction extends RefreshAction { @Override public void actionPerformed(AnActionEvent e) { - Project project = e.getRequiredData(CommonDataKeys.PROJECT); - VcsLogProjectManager.getInstance(project).getDataManager().refreshCompletely(); + VcsLogManager logManager = e.getRequiredData(VcsLogDataKeys.LOG_MANAGER); + logManager.getDataManager().refreshCompletely(); } @Override public void update(AnActionEvent e) { - Project project = e.getProject(); - if (project == null) { - e.getPresentation().setEnabledAndVisible(false); - } - else { - VcsLogProjectManager projectManager = VcsLogProjectManager.getInstance(project); - VcsLogDataManager dataManager = projectManager.getDataManager(); - e.getPresentation().setEnabledAndVisible(dataManager != null && e.getData(VcsLogDataKeys.VCS_LOG_UI) != null); - } + VcsLogManager logManager = e.getData(VcsLogDataKeys.LOG_MANAGER); + e.getPresentation().setEnabledAndVisible(logManager != null); } }