PY-58973 Packaging(fix): add sdk name to installed table header

GitOrigin-RevId: 709574d177ae7a9adad3b89ec83c010301c89853
This commit is contained in:
Nikita.Ashihmin
2024-09-02 12:09:21 +00:00
committed by intellij-monorepo-bot
parent 3c9b04806c
commit 7cf046b781
5 changed files with 25 additions and 13 deletions
@@ -3,6 +3,7 @@ package com.jetbrains.python.packaging.toolwindow
import com.intellij.icons.AllIcons
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.ui.JBColor
import com.jetbrains.python.PyBundle.message
import com.jetbrains.python.packaging.repository.InstalledPyPackagedRepository
@@ -16,9 +17,11 @@ import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JTable
class PyPackagingTablesView(private val project: Project,
private val container: JPanel,
private val controller: PyPackagingToolWindowPanel) {
class PyPackagingTablesView(
private val project: Project,
private val container: JPanel,
private val controller: PyPackagingToolWindowPanel,
) {
private val repositories: MutableList<PyPackagingTableGroup> = mutableListOf()
private val installedPackages = PyPackagingTableGroup(
InstalledPyPackagedRepository(),
@@ -48,11 +51,11 @@ class PyPackagingTablesView(private val project: Project,
?.let { selectPackage(it.second) }
}
fun resetSearch(installed: List<InstalledPackage>, repoData: List<PyPackagesViewData>) {
fun resetSearch(installed: List<InstalledPackage>, repoData: List<PyPackagesViewData>, currentSdk: Sdk?) {
updatePackages(installed, repoData)
installedPackages.expand()
installedPackages.updateHeaderText(null)
installedPackages.setSdkToHeader(currentSdk?.name)
repositories.forEach {
it.collapse()
@@ -150,7 +153,7 @@ class PyPackagingTablesView(private val project: Project,
installedPackages.table -> repositories.firstOrNull()
else -> {
val currentIndex = repositories.indexOfFirst { it.table == currentTable }
if (currentIndex + 1 != repositories.size) repositories[currentIndex + 1]
if (currentIndex + 1 != repositories.size) repositories[currentIndex + 1]
else return
}
}
@@ -11,6 +11,7 @@ import com.intellij.openapi.components.service
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.modules
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.ui.SimpleToolWindowPanel
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.wm.ToolWindowManager
@@ -170,8 +171,8 @@ class PyPackagingToolWindowPanel(private val project: Project) : SimpleToolWindo
packageListController.showSearchResult(installed, repoData)
}
fun resetSearch(installed: List<InstalledPackage>, repos: List<PyPackagesViewData>) {
packageListController.resetSearch(installed, repos)
fun resetSearch(installed: List<InstalledPackage>, repos: List<PyPackagesViewData>, currentSdk: Sdk?) {
packageListController.resetSearch(installed, repos, currentSdk)
}
@@ -98,7 +98,7 @@ class PyPackagingToolWindowService(val project: Project, val serviceScope: Corou
PyPackagesViewData(repository, shownPackages, moreItems = packages.size - PACKAGES_LIMIT)
}.toList()
toolWindowPanel?.resetSearch(installedPackages.values.toList(), packagesByRepository + invalidRepositories)
toolWindowPanel?.resetSearch(installedPackages.values.toList(), packagesByRepository + invalidRepositories, currentSdk)
prevSelected?.name?.let { toolWindowPanel?.selectPackageName(it) }
}
}
@@ -3,6 +3,7 @@ package com.jetbrains.python.packaging.toolwindow.packages
import com.intellij.openapi.Disposable
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.ui.SimpleToolWindowPanel.LEFT_ALIGNMENT
import com.intellij.ui.ScrollPaneFactory
import com.intellij.util.ui.UIUtil
@@ -31,8 +32,8 @@ class PyPackagesListController(val project: Project, val controller: PyPackaging
tablesView.showSearchResult(installed, repoData)
}
fun resetSearch(installed: List<InstalledPackage>, repos: List<PyPackagesViewData>) {
tablesView.resetSearch(installed, repos)
fun resetSearch(installed: List<InstalledPackage>, repos: List<PyPackagesViewData>, currentSdk: Sdk?) {
tablesView.resetSearch(installed, repos, currentSdk)
}
fun selectPackage(name: String) {
@@ -3,12 +3,13 @@ package com.jetbrains.python.packaging.toolwindow.packages
import com.intellij.icons.AllIcons
import com.intellij.openapi.util.NlsSafe
import com.intellij.ui.components.JBLabel
import com.jetbrains.python.PyBundle
import com.jetbrains.python.packaging.repository.PyPackageRepository
import com.jetbrains.python.packaging.toolwindow.model.DisplayablePackage
import com.jetbrains.python.packaging.toolwindow.packages.table.PyPackagesTable
import com.jetbrains.python.packaging.toolwindow.ui.PyPackagesUiComponents
import javax.swing.JLabel
import org.jetbrains.annotations.Nls
import javax.swing.JPanel
internal class PyPackagingTableGroup(val repository: PyPackageRepository, val table: PyPackagesTable) {
@@ -16,7 +17,7 @@ internal class PyPackagingTableGroup(val repository: PyPackageRepository, val ta
val name: String = repository.name!!
private var expanded = false
private val label = JLabel(name).apply { icon = AllIcons.General.ArrowDown }
private val label = JBLabel(name).apply { icon = AllIcons.General.ArrowDown }
private val header: JPanel = PyPackagesUiComponents.headerPanel(label, table)
private var itemsCount: Int? = null
@@ -44,6 +45,12 @@ internal class PyPackagingTableGroup(val repository: PyPackageRepository, val ta
label.text = if (itemsCount == null) name else PyBundle.message("python.toolwindow.packages.custom.repo.searched", name, itemsCount)
}
fun setSdkToHeader(@Nls sdkName: String?) {
itemsCount = null
label.text = name + " (${sdkName})"
}
fun addTo(panel: JPanel) {
panel.add(header)
panel.add(table)