PY-91833 Set "Python Packages" tool window default anchor to the right and track manual customization.

(cherry picked from commit 74a4e25c2952a032c656207a5ec7213a8a664ccc)

IJ-MR-220113

GitOrigin-RevId: d9d9c25923f4048ab4ea06df9816fbc2fa524990
This commit is contained in:
TimurMalanin
2026-08-26 15:24:08 +00:00
committed by intellij-monorepo-bot
parent f620b6f532
commit 09eb10a855
3 changed files with 57 additions and 2 deletions
@@ -11,7 +11,7 @@ class PyToolWindowLayoutProvider : DefaultToolWindowLayoutExtension {
override fun buildV2Layout(builder: DefaultToolWindowLayoutBuilder) {
builder.right.addOrUpdate("Plots") { weight = 0.1f }
builder.bottom.addOrUpdate("Python Packages") { weight = 0.1f }
builder.right.addOrUpdate("Python Packages") { weight = 0.25f }
builder.bottom.addOrUpdate("Python Console") { weight = 0.1f }
thisLogger().info("Python default layout applied")
}
@@ -766,9 +766,10 @@
<notificationGroup id="Python source root detection" displayType="STICKY_BALLOON" isLogByDefault="true" bundle="messages.PyBundle"
key="python.source.root.detection.confirm.notification.group"/>
<toolWindow id="Python Packages" anchor="bottom" secondary="true"
<toolWindow id="Python Packages" anchor="right" secondary="false"
icon="com.jetbrains.python.icons.PythonIcons.Python.PythonPackages"
factoryClass="com.jetbrains.python.packaging.toolwindow.PyPackagesToolWindowFactory"/>
<postStartupActivity implementation="com.jetbrains.python.packaging.toolwindow.PyPackagesToolWindowMigrationActivity"/>
<toolWindowExtractorMode id="Python Packages" mode="mirror"/>
<toolWindowExtractor implementation="com.jetbrains.python.packaging.toolwindow.PyPackagesToolWindowExtractor"/>
<statistics.counterUsagesCollector
@@ -0,0 +1,54 @@
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.packaging.toolwindow
import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.wm.ToolWindowAnchor
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.toolWindow.ToolWindowDefaultLayoutManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
/**
* PY-89840: put the "Python Packages" tool window on the right stripe by default.
*
* Migrates the application-wide default layout once; new projects (and projects without a saved layout for
* this id) pick up the new anchor from that default. Projects that already persisted a custom placement
* keep it.
*/
internal class PyPackagesToolWindowMigrationActivity : ProjectActivity {
override suspend fun execute(project: Project) {
val appProperties = PropertiesComponent.getInstance()
if (!appProperties.getBoolean(APP_MIGRATION_FLAG_KEY)) {
val manager = ToolWindowDefaultLayoutManager.getInstance()
val layout = manager.getLayoutCopy()
val info = layout.getInfo(PyPackagingToolWindowPanel.PY_PACKAGES_TOOL_WINDOW_ID)
if (info != null && (info.anchor != ToolWindowAnchor.RIGHT || info.isSplit)) {
info.anchor = ToolWindowAnchor.RIGHT
info.isSplit = false
manager.setLayout(layout)
}
appProperties.setValue(APP_MIGRATION_FLAG_KEY, true)
}
val projectProperties = PropertiesComponent.getInstance(project)
if (projectProperties.getBoolean(PROJECT_MIGRATION_FLAG_KEY)) return
withContext(Dispatchers.Main) {
if (project.isDisposed) return@withContext
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow(PyPackagingToolWindowPanel.PY_PACKAGES_TOOL_WINDOW_ID)
?: return@withContext
if (toolWindow.anchor != ToolWindowAnchor.RIGHT || toolWindow.isSplitMode) {
toolWindow.setAnchor(ToolWindowAnchor.RIGHT, null)
toolWindow.setSplitMode(false, null)
}
}
projectProperties.setValue(PROJECT_MIGRATION_FLAG_KEY, true)
}
companion object {
private const val APP_MIGRATION_FLAG_KEY: String = "python.packages.toolwindow.migrated.to.right.top.v2"
private const val PROJECT_MIGRATION_FLAG_KEY: String = "python.packages.toolwindow.project.migrated.to.right.top.v2"
}
}