[vcs] provide api for placing tabs into the commit tool window
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Sun, 1 Nov 2020 16:58:35 +0000 (19:58 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Mon, 23 Nov 2020 19:02:46 +0000 (19:02 +0000)
GitOrigin-RevId: c3aa1441d627dbf535a56314322d27abc3d37e3c

platform/vcs-impl/resources/META-INF/VcsExtensions.xml
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesViewContentEP.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesViewContentManager.kt
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/VcsToolWindowFactory.kt
plugins/git4idea/resources/META-INF/plugin.xml

index d80972e00e67d8f9dac353d9c5406abd4078f8f6..e8cf9607a56767637dd3e4625f38a72ec821944b 100644 (file)
                         className="com.intellij.openapi.vcs.changes.ChangesViewManager$ContentProvider"
                         preloaderClassName="com.intellij.openapi.vcs.changes.ChangesViewManager$ContentPreloader"
                         predicateClassName="com.intellij.openapi.vcs.changes.ChangesViewManager$ContentPredicate"
-                        displayNameSupplierClassName="com.intellij.openapi.vcs.changes.ChangesViewManager$DisplayNameSupplier"/>
+                        displayNameSupplierClassName="com.intellij.openapi.vcs.changes.ChangesViewManager$DisplayNameSupplier"
+                        isInCommitToolWindow="true"/>
 
     <statusBarWidgetProvider implementation="com.intellij.openapi.vcs.changes.committed.IncomingChangesIndicatorProvider"/>
     <editorNotificationProvider implementation="com.intellij.openapi.vcs.changes.committed.OutdatedVersionNotifier"/>
index 88d54cdf0b059db5188e379e700838a7e1afc908..0118199d4a2a0729fbb95d3a8127ead664bf14de 100644 (file)
@@ -85,8 +85,7 @@ import java.util.stream.Collectors;
 import static com.intellij.icons.AllIcons.Vcs.Patch_applied;
 import static com.intellij.openapi.vcs.changes.shelf.DiffShelvedChangesActionProvider.createAppliedTextPatch;
 import static com.intellij.openapi.vcs.changes.ui.ChangesGroupingSupport.REPOSITORY_GROUPING;
-import static com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.SHELF;
-import static com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.getToolWindowFor;
+import static com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.*;
 import static com.intellij.openapi.vcs.changes.ui.ChangesViewContentManagerKt.isCommitToolWindow;
 import static com.intellij.util.FontUtil.spaceAndThinSpace;
 import static com.intellij.util.containers.ContainerUtil.*;
@@ -154,6 +153,7 @@ public class ShelvedChangesViewManager implements Disposable {
         myContent.setTabName(SHELF); //NON-NLS overridden by displayName above
         MyDnDTarget dnDTarget = new MyDnDTarget(myPanel.myProject, myContent);
         myContent.putUserData(Content.TAB_DND_TARGET_KEY, dnDTarget);
+        myContent.putUserData(IS_IN_COMMIT_TOOLWINDOW_KEY, true);
 
         myContent.setCloseable(false);
         myContent.setDisposer(myPanel);
index 3c2a8fe8923e1758791413e3a65e032f2b6614d8..ac3abb825cb1e31c885d13cc8cca03bf895c9025 100644 (file)
@@ -42,6 +42,9 @@ public class ChangesViewContentEP implements PluginAware {
   @Attribute("displayNameSupplierClassName")
   public String displayNameSupplierClassName;
 
+  @Attribute("isInCommitToolWindow")
+  public boolean isInCommitToolWindow;
+
   private PluginDescriptor myPluginDescriptor;
   private ChangesViewContentProvider myInstance;
 
@@ -90,6 +93,14 @@ public class ChangesViewContentEP implements PluginAware {
     this.displayNameSupplierClassName = displayNameSupplierClassName;
   }
 
+  public boolean isInCommitToolWindow() {
+    return isInCommitToolWindow;
+  }
+
+  public void setInCommitToolWindow(boolean isInCommitToolWindow) {
+    this.isInCommitToolWindow = isInCommitToolWindow;
+  }
+
   public ChangesViewContentProvider getInstance(@NotNull Project project) {
     if (myInstance == null) {
       myInstance = (ChangesViewContentProvider)newClassInstance(project, className);
index 62f6a4306389fa5a12eb1d55f694b83be2c18d1c..a79b9bfb2671a5a4fd4176e293f5ad4ccc0d8392 100644 (file)
@@ -10,8 +10,6 @@ import com.intellij.openapi.util.Key
 import com.intellij.openapi.util.registry.Registry
 import com.intellij.openapi.util.registry.RegistryValue
 import com.intellij.openapi.util.registry.RegistryValueListener
-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.wm.ToolWindow
 import com.intellij.openapi.wm.ToolWindowId
 import com.intellij.openapi.wm.ToolWindowManager
@@ -30,9 +28,6 @@ import kotlin.properties.Delegates.observable
 private val isCommitToolWindowRegistryValue
   get() = Registry.get("vcs.commit.tool.window")
 
-// TODO allow specifying preferred tool window for ChangesViewContentEP
-private val COMMIT_TOOL_WINDOW_CONTENT_FILTER: (String) -> Boolean = { it == LOCAL_CHANGES || it == SHELF || it == "Staging Area" }
-
 internal val Project.isCommitToolWindow: Boolean
   get() = ChangesViewContentManager.getInstanceImpl(this)?.isCommitToolWindow == true
 
@@ -46,14 +41,21 @@ private val LOG = logger<ChangesViewContentManager>()
 class ChangesViewContentManager(private val project: Project) : ChangesViewContentI, Disposable {
   private val toolWindows = mutableSetOf<ToolWindow>()
   private val addedContents = mutableListOf<Content>()
+  private val commitToolWindowTabs = mutableSetOf<String>()
 
   private val contentManagers: Collection<ContentManager> get() = toolWindows.map { it.contentManager }
 
+  internal fun getToolWindowId(shouldUseCommitToolWindow: Boolean): String {
+    return if (isCommitToolWindow && shouldUseCommitToolWindow) COMMIT_TOOLWINDOW_ID else TOOLWINDOW_ID
+  }
+
   private fun getToolWindowIdFor(contentName: String): String {
-    return if (isCommitToolWindow && COMMIT_TOOL_WINDOW_CONTENT_FILTER(contentName)) COMMIT_TOOLWINDOW_ID else TOOLWINDOW_ID
+    return getToolWindowId(commitToolWindowTabs.contains(contentName))
   }
 
-  private fun Content.resolveToolWindowId() = getToolWindowIdFor(tabName)
+  private fun Content.isInCommitToolWindow() = IS_IN_COMMIT_TOOLWINDOW_KEY.get(this) == true
+
+  private fun Content.resolveToolWindowId() = getToolWindowId(isInCommitToolWindow())
 
   private fun Content.resolveToolWindow(): ToolWindow? {
     val toolWindowId = resolveToolWindowId()
@@ -122,11 +124,16 @@ class ChangesViewContentManager(private val project: Project) : ChangesViewConte
     else {
       addIntoCorrectPlace(contentManager, content)
     }
+    if (content.isInCommitToolWindow()) {
+      commitToolWindowTabs.add(content.tabName)
+    }
   }
 
   override fun removeContent(content: Content) = removeContent(content, true)
 
   private fun removeContent(content: Content, dispose: Boolean) {
+    commitToolWindowTabs.remove(content.tabName)
+
     val contentManager = content.manager
     if (contentManager == null || contentManager.isDisposed) {
       addedContents.remove(content)
@@ -210,6 +217,8 @@ class ChangesViewContentManager(private val project: Project) : ChangesViewConte
 
     @JvmField
     val CONTENT_PROVIDER_SUPPLIER_KEY = Key.create<() -> ChangesViewContentProvider>("CONTENT_PROVIDER_SUPPLIER")
+    @JvmField
+    val IS_IN_COMMIT_TOOLWINDOW_KEY = Key.create<Boolean>("IS_IN_COMMIT_TOOLWINDOW_KEY")
 
     @JvmStatic
     fun getInstance(project: Project) = project.service<ChangesViewContentI>()
index 2989a58c2cfe8f54ab6d54ad1c4c69f8599130d7..a7898642171096579ae2842e060f7586c34cfbcf 100644 (file)
@@ -12,7 +12,7 @@ import com.intellij.openapi.vcs.ProjectLevelVcsManager
 import com.intellij.openapi.vcs.ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED
 import com.intellij.openapi.vcs.VcsListener
 import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.CONTENT_PROVIDER_SUPPLIER_KEY
-import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.getToolWindowIdFor
+import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager.Companion.IS_IN_COMMIT_TOOLWINDOW_KEY
 import com.intellij.openapi.wm.ToolWindow
 import com.intellij.openapi.wm.ToolWindowFactory
 import com.intellij.openapi.wm.ex.ToolWindowEx
@@ -102,7 +102,9 @@ abstract class VcsToolWindowFactory : ToolWindowFactory, DumbAware {
   }
 
   private fun getExtensions(project: Project, toolWindow: ToolWindow): Collection<ChangesViewContentEP> {
-    return ChangesViewContentEP.EP_NAME.getExtensions(project).filter { getToolWindowIdFor(project, it.tabName) == toolWindow.id }
+    return ChangesViewContentEP.EP_NAME.getExtensions(project).filter {
+      ChangesViewContentManager.getInstanceImpl(project)?.getToolWindowId(it.isInCommitToolWindow) == toolWindow.id
+    }
   }
 
   private fun createExtensionContent(project: Project, extension: ChangesViewContentEP): Content {
@@ -113,6 +115,7 @@ abstract class VcsToolWindowFactory : ToolWindowFactory, DumbAware {
       tabName = extension.tabName
       putUserData(CHANGES_VIEW_EXTENSION, extension)
       putUserData(CONTENT_PROVIDER_SUPPLIER_KEY) { extension.getInstance(project) }
+      putUserData(IS_IN_COMMIT_TOOLWINDOW_KEY, extension.isInCommitToolWindow)
 
       extension.newPreloaderInstance(project)?.preloadTabContent(this)
     }
index 739425b8fb0033654384778fd49a1ed4fbe61cbf..150d871f622b4a69e288b57fa1d64b840c69cfe9 100644 (file)
     <changesViewContent id="git.stage" tabName="Staging Area" className="git4idea.index.GitStageContentProvider"
                         predicateClassName="git4idea.index.GitStageContentVisibilityPredicate"
                         preloaderClassName="git4idea.index.GitStageContentPreloader"
-                        displayNameSupplierClassName="git4idea.index.GitStageDisplayNameSupplier"/>
+                        displayNameSupplierClassName="git4idea.index.GitStageDisplayNameSupplier"
+                        isInCommitToolWindow="true"/>
     <projectService serviceImplementation="git4idea.index.ui.GitStageUiSettingsImpl"/>
 
     <projectService serviceImplementation="git4idea.index.GitStageTracker"/>