[PyCharm] PY-65433 changes to jupyter cells draggable bar:

- visible only on hover/select
- respects disableActions
- respects read only notebook

GitOrigin-RevId: f5cbe89cbfd3e881c663a8edb3a79789da64df05
This commit is contained in:
Bogdan Kirilenko
2025-02-05 20:14:57 +01:00
committed by intellij-monorepo-bot
parent f35c58ef03
commit 287af7be3d
2 changed files with 35 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import com.intellij.ide.DataManager
import com.intellij.ide.actions.DistractionFreeModeController
import com.intellij.ide.ui.UISettings
import com.intellij.notebooks.ui.visualization.NotebookEditorAppearanceUtils.isDiffKind
import com.intellij.notebooks.ui.visualization.NotebookEditorAppearanceUtils.isOrdinaryNotebookEditor
import com.intellij.notebooks.ui.visualization.NotebookUtil.notebookAppearance
import com.intellij.notebooks.ui.visualization.markerRenderers.NotebookCellHighlighterRenderer
import com.intellij.notebooks.ui.visualization.markerRenderers.NotebookCodeCellBackgroundLineMarkerRenderer
@@ -85,6 +86,7 @@ class EditorCellView(
field = value
updateFolding()
updateRunButtonVisibility()
updateDraggableBarVisibility()
updateCellHighlight()
updateCellActionsToolbarVisibility()
myEditorCellFrameManager?.updateCellFrameShow(value, mouseOver)
@@ -100,6 +102,7 @@ class EditorCellView(
if (field == value) return
field = value
updateRunButtonVisibility()
updateDraggableBarVisibility()
}
init {
@@ -120,6 +123,7 @@ class EditorCellView(
}
editor.notebook?.readOnly?.afterChange(this) {
updateRunButtonVisibility()
updateDraggableBarVisibility()
}
recreateControllers()
updateSelection(false)
@@ -270,6 +274,7 @@ class EditorCellView(
mouseOver = false
updateFolding()
updateRunButtonVisibility()
updateDraggableBarVisibility()
myEditorCellFrameManager?.updateCellFrameShow(selected, mouseOver)
updateCellActionsToolbarVisibility()
}
@@ -278,6 +283,7 @@ class EditorCellView(
mouseOver = true
updateFolding()
updateRunButtonVisibility()
updateDraggableBarVisibility()
myEditorCellFrameManager?.updateCellFrameShow(selected, mouseOver)
updateCellActionsToolbarVisibility()
}
@@ -372,7 +378,7 @@ class EditorCellView(
private fun updateRunButtonVisibility() {
input.runCellButton ?: return
val isReadOnlyNotebook = editor.notebook?.readOnly?.get() ?: false
val isReadOnlyNotebook = editor.notebook?.readOnly?.get() == true
val shouldBeVisible = !isReadOnlyNotebook && !disableActions && (mouseOver || selected)
if (input.runCellButton.lastRunButtonVisibility == shouldBeVisible) return
@@ -380,6 +386,19 @@ class EditorCellView(
input.runCellButton.lastRunButtonVisibility = shouldBeVisible
}
private fun updateDraggableBarVisibility() {
val isReadOnlyNotebook = editor.notebook?.readOnly?.get() == true
val shouldBeVisible =
Registry.`is`("jupyter.editor.dnd.cells")
&& !isReadOnlyNotebook
&& !disableActions
&& (mouseOver || selected)
&& editor.isOrdinaryNotebookEditor()
if (input.draggableBar.visible == shouldBeVisible) return
input.draggableBar.visible = shouldBeVisible
}
private fun updateCellActionsToolbarVisibility() {
val toolbarManager = input.cellActionsToolbar ?: return
val targetComponent = _controllers.filterIsInstance<DataProviderComponent>().firstOrNull()?.retrieveDataProvider() ?: return

View File

@@ -1,7 +1,6 @@
package com.intellij.notebooks.visualization.ui.cellsDnD
import com.intellij.icons.AllIcons
import com.intellij.notebooks.ui.visualization.NotebookEditorAppearanceUtils.isOrdinaryNotebookEditor
import com.intellij.notebooks.ui.visualization.NotebookUtil.notebookAppearance
import com.intellij.notebooks.visualization.NotebookCellInlayManager
import com.intellij.notebooks.visualization.getCell
@@ -12,7 +11,6 @@ import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.registry.Registry
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.annotations.Nls
import java.awt.Cursor
@@ -42,9 +40,16 @@ class EditorCellDraggableBar(
private val inlayManager = NotebookCellInlayManager.get(editor)
init {
if (Registry.`is`("jupyter.editor.dnd.cells")) createAndAddDraggableBar()
JupyterBoundsChangeHandler.get(editor).subscribe(boundsChangeListener)
}
var visible: Boolean = false
set(value) {
if (value) createAndAddDraggableBar()
else removeDraggableBar()
field = value
}
fun updateBounds() {
panel?.let {
val inlays = cellInput.getBlockElementsInRange()
@@ -65,15 +70,19 @@ class EditorCellDraggableBar(
}
private fun createAndAddDraggableBar() {
if (!editor.isOrdinaryNotebookEditor()) return
val panel = DraggableBarComponent()
editor.gutterComponentEx.add(panel)
this.panel = panel
JupyterBoundsChangeHandler.get(editor).subscribe(boundsChangeListener)
updateBounds()
}
private fun removeDraggableBar() {
panel?.let {
editor.gutterComponentEx.remove(it)
panel = null
}
}
override fun dispose() {
panel?.let {
editor.gutterComponentEx.apply {