mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
PY-58972 Packages(fix): The attached project stays in the list on the "Python packages" tool window after its dettaching
GitOrigin-RevId: d7231e09a6d1a981536a68e8289a6b731549be92
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7301ef3753
commit
a968c7d095
@@ -99,8 +99,6 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
|
||||
<listener
|
||||
class="com.jetbrains.python.inspections.PyInterpreterInspection$Visitor$CacheCleaner"
|
||||
topic="com.intellij.openapi.projectRoots.ProjectJdkTable$Listener"/>
|
||||
<listener class="com.jetbrains.python.packaging.toolwindow.PyPackagesToolWindowModuleAttachListener"
|
||||
topic="com.intellij.platform.ModuleAttachListener"/>
|
||||
<listener class="com.jetbrains.python.packaging.PyDependencyCollectorListener"
|
||||
topic="com.jetbrains.python.packaging.common.PythonPackageManagementListener"/>
|
||||
<listener class="com.jetbrains.python.statistics.PyPackageDaemonListener"
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright 2000-2023 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.openapi.Disposable
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.platform.ModuleAttachListener
|
||||
import com.jetbrains.python.packaging.utils.PyPackageCoroutine
|
||||
import java.nio.file.Path
|
||||
|
||||
class PyPackagesToolWindowModuleAttachListener : ModuleAttachListener {
|
||||
override fun afterAttach(module: Module, primaryModule: Module?, imlFile: Path, tasks: MutableList<suspend () -> Unit>) {
|
||||
tasks.add {
|
||||
module.project.service<PyPackagingToolWindowService>().moduleAttached()
|
||||
}
|
||||
}
|
||||
|
||||
override fun beforeDetach(module: Module) {
|
||||
@Suppress("IncorrectParentDisposable")
|
||||
//We do not have function after detach so this is small trick
|
||||
Disposer.register(module, Disposable {
|
||||
PyPackageCoroutine.launch(module.project) {
|
||||
module.project.service<PyPackagingToolWindowService>().moduleAttached()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
@@ -112,6 +112,7 @@ class PyPackagingToolWindowPanel(private val project: Project) : SimpleToolWindo
|
||||
|
||||
val actionGroup = DefaultActionGroup()
|
||||
actionGroup.add(DumbAwareAction.create(message("python.toolwindow.packages.reload.repositories.action"), AllIcons.Actions.Refresh) {
|
||||
moduleController.rebuildList()
|
||||
service.reloadPackages()
|
||||
})
|
||||
|
||||
|
||||
@@ -8,12 +8,14 @@ import com.intellij.openapi.fileEditor.FileEditorManagerListener
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.module.ModuleUtilCore
|
||||
import com.intellij.openapi.project.ModuleListener
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.modules
|
||||
import com.intellij.ui.ScrollPaneFactory
|
||||
import com.intellij.ui.SideBorder
|
||||
import com.intellij.ui.components.JBLabel
|
||||
import com.intellij.ui.components.JBList
|
||||
import com.intellij.util.Function
|
||||
import com.intellij.util.ui.JBUI
|
||||
import com.intellij.util.ui.NamedColorUtil
|
||||
import com.jetbrains.python.icons.PythonIcons
|
||||
@@ -43,11 +45,24 @@ class PyPackagesModuleController(val project: Project) : Disposable {
|
||||
addListSelectionListener(ListSelectionListener { e ->
|
||||
if (e.valueIsAdjusting) return@ListSelectionListener
|
||||
val selectedModule = this@apply.selectedValue
|
||||
val sdk = selectedModule.pythonSdk ?: return@ListSelectionListener
|
||||
val sdk = selectedModule?.pythonSdk ?: return@ListSelectionListener
|
||||
packagingScope.launch {
|
||||
service.initForSdk(sdk)
|
||||
}
|
||||
})
|
||||
|
||||
project.messageBus.connect(this@PyPackagesModuleController).subscribe(ModuleListener.TOPIC, object : ModuleListener {
|
||||
override fun modulesAdded(project: Project, modules: MutableList<out Module>) = rebuildList()
|
||||
|
||||
override fun moduleRemoved(project: Project, module: Module) = rebuildList()
|
||||
|
||||
override fun modulesRenamed(
|
||||
project: Project, modules: MutableList<out Module>,
|
||||
oldNameProvider: Function<in Module, String>,
|
||||
) {
|
||||
rebuildList()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -81,4 +96,13 @@ class PyPackagesModuleController(val project: Project) : Disposable {
|
||||
}
|
||||
|
||||
override fun dispose() {}
|
||||
|
||||
fun rebuildList() {
|
||||
val selected = moduleList.selectedValue?.name
|
||||
val modules: List<Module> = ModuleManager.getInstance(project).modules.toList().sortedBy { it.name }
|
||||
val model = moduleList.model as? DefaultListModel
|
||||
model?.removeAllElements()
|
||||
model?.addAll(modules)
|
||||
moduleList.selectedIndex = modules.indexOfFirst { it.name == selected }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user