mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: remove 'performActionDumbAwareWithCallbacks' usage in GitUnstash
GitOrigin-RevId: c4b6beada73afa00dc3dc730a159594940f58cfb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2cc8fa2e69
commit
9ec33c4dab
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user