diff --git a/platform/vcs-impl/src/com/intellij/vcs/VcsShowToolWindowTabAction.kt b/platform/vcs-impl/src/com/intellij/vcs/VcsShowToolWindowTabAction.kt index 6bb4b468d362..28dab8c7e7db 100644 --- a/platform/vcs-impl/src/com/intellij/vcs/VcsShowToolWindowTabAction.kt +++ b/platform/vcs-impl/src/com/intellij/vcs/VcsShowToolWindowTabAction.kt @@ -9,8 +9,7 @@ import com.intellij.openapi.vcs.changes.shelf.ShelvedChangesViewManager import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.LOCAL_CHANGES import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.SHELF -import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.getToolWindowFor -import com.intellij.openapi.wm.ToolWindow +import org.jetbrains.annotations.NonNls class VcsShowLocalChangesAction : VcsShowToolWindowTabAction() { override val tabName: String get() = LOCAL_CHANGES @@ -32,7 +31,9 @@ abstract class VcsShowToolWindowTabAction : DumbAwareAction() { protected abstract val tabName: String override fun update(e: AnActionEvent) { - e.presentation.isEnabledAndVisible = getToolWindow(e.project) != null + val project = e.project + e.presentation.isEnabledAndVisible = project != null && + ChangesViewContentManager.getToolWindowFor(project, tabName) != null } override fun getActionUpdateThread(): ActionUpdateThread { @@ -40,21 +41,33 @@ abstract class VcsShowToolWindowTabAction : DumbAwareAction() { } override fun actionPerformed(e: AnActionEvent) { - val project = e.project!! - val toolWindow = getToolWindow(project)!! - val contentManager = ChangesViewContentManager.getInstance(project) as ChangesViewContentManager - - val isToolWindowActive = toolWindow.isActive - val isContentSelected = contentManager.isContentSelected(tabName) - val tabSelector = Runnable { contentManager.selectContent(tabName, true) } - - when { - isToolWindowActive && isContentSelected -> toolWindow.hide(null) - isToolWindowActive && !isContentSelected -> tabSelector.run() - !isToolWindowActive && isContentSelected -> toolWindow.activate(null, true) - !isToolWindowActive && !isContentSelected -> toolWindow.activate(tabSelector, false) - } + val project = e.project ?: return + activateVcsTab(project, tabName, true) } - private fun getToolWindow(project: Project?): ToolWindow? = project?.let { getToolWindowFor(it, tabName) } + companion object { + @JvmStatic + fun activateVcsTab(project: Project, tabName: @NonNls String, isToggle: Boolean) { + val toolWindow = ChangesViewContentManager.getToolWindowFor(project, tabName) ?: return + val contentManager = ChangesViewContentManager.getInstance(project) as ChangesViewContentManager + + val isToolWindowActive = toolWindow.isActive + val isContentSelected = contentManager.isContentSelected(tabName) + val tabSelector = Runnable { contentManager.selectContent(tabName, true) } + + when { + isToolWindowActive && isContentSelected -> { + if (isToggle) { + toolWindow.hide(null) + } + else { + tabSelector.run() + } + } + isToolWindowActive && !isContentSelected -> tabSelector.run() + !isToolWindowActive && isContentSelected -> toolWindow.activate(null, true) + else -> toolWindow.activate(tabSelector, false) + } + } + } } \ No newline at end of file diff --git a/plugins/git4idea/src/git4idea/actions/GitUnstash.java b/plugins/git4idea/src/git4idea/actions/GitUnstash.java index 45305cee1e50..4dafa9b69764 100644 --- a/plugins/git4idea/src/git4idea/actions/GitUnstash.java +++ b/plugins/git4idea/src/git4idea/actions/GitUnstash.java @@ -1,14 +1,14 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package git4idea.actions; -import com.intellij.openapi.actionSystem.ActionManager; -import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.ex.ActionUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.changes.ChangeListManager; +import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.vcs.VcsShowToolWindowTabAction; import git4idea.i18n.GitBundle; +import git4idea.stash.ui.GitStashContentProvider; import git4idea.ui.GitUnstashDialog; import org.jetbrains.annotations.NotNull; @@ -29,15 +29,13 @@ public class GitUnstash extends GitRepositoryAction { @Override public void actionPerformed(@NotNull AnActionEvent e) { - AnAction showStashAction = ActionManager.getInstance().getAction("Git.Show.Stash"); - AnActionEvent newEvent = AnActionEvent.createFromDataContext(e.getPlace(), - showStashAction.getTemplatePresentation().clone(), - e.getDataContext()); - if (ActionUtil.lastUpdateAndCheckDumb(showStashAction, newEvent, true)) { - ActionUtil.performActionDumbAwareWithCallbacks(showStashAction, newEvent); - } else { - super.actionPerformed(e); + Project project = e.getProject(); + if (project != null && ChangesViewContentManager.getToolWindowFor(project, GitStashContentProvider.TAB_NAME) != null) { + VcsShowToolWindowTabAction.activateVcsTab(project, GitStashContentProvider.TAB_NAME, false); + return; } + + super.actionPerformed(e); } /**