mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-13 06:59:44 +07:00
PY-76783 Jupyter(fix): move close before load to notebook plugin
(cherry picked from commit 291d802599c3d828a0585339005f60c716f61889) GitOrigin-RevId: f125e99d9f1356f170e9cadba1cb66f056dc7028
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2f73603c44
commit
4678a000d1
@@ -16,5 +16,7 @@
|
||||
<orderEntry type="library" name="http-client" level="project" />
|
||||
<orderEntry type="library" name="netty-buffer" level="project" />
|
||||
<orderEntry type="library" name="netty-codec-http" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.projectModel" />
|
||||
<orderEntry type="module" module-name="intellij.platform.analysis" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -7,4 +7,10 @@
|
||||
implementationClass="com.intellij.notebooks.jupyter.core.jupyter.JupyterFileType"
|
||||
fieldName="INSTANCE"/>
|
||||
</extensions>
|
||||
|
||||
|
||||
<applicationListeners>
|
||||
<listener class="com.intellij.notebooks.jupyter.core.jupyter.JupyterCorePluginListener"
|
||||
topic="com.intellij.ide.plugins.DynamicPluginListener"/>
|
||||
</applicationListeners>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.intellij.notebooks.jupyter.core.jupyter
|
||||
|
||||
import com.intellij.ide.plugins.DynamicPluginListener
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
|
||||
/**
|
||||
* When .ipynb files was opened before Jupyter plugin installed, we need to reopen them to run all required procedures in
|
||||
* [NotebookFileEditorService#onNotebookFileEditorCreated]
|
||||
*/
|
||||
class JupyterCorePluginListener : DynamicPluginListener {
|
||||
override fun beforePluginLoaded(pluginDescriptor: IdeaPluginDescriptor) {
|
||||
if (pluginDescriptor.pluginId.idString != JUPYTER_PLUGIN_ID)
|
||||
return
|
||||
|
||||
ProjectManager.getInstance().openProjects.forEach { project ->
|
||||
val fileEditorManager = FileEditorManager.getInstance(project)
|
||||
fileEditorManager.openFiles.forEach { file ->
|
||||
file.extension == JupyterFileType.defaultExtension || return@forEach
|
||||
fileEditorManager.closeFile(file)
|
||||
filesToRestore.add(project to file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val filesToRestore = mutableListOf<Pair<Project, VirtualFile>>()
|
||||
|
||||
const val JUPYTER_PLUGIN_ID = "intellij.jupyter"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user