diff --git a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewDialog.java b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewDialog.java index 8ed4b293a12d..e26a81f49428 100644 --- a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewDialog.java +++ b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewDialog.java @@ -31,7 +31,7 @@ public class PyDataViewDialog extends DialogWrapper { myMainPanel = new JPanel(new GridBagLayout()); myDataViewerPanel = new PyDataViewerPanel(project, value.getFrameAccessor()); - myDataViewerPanel.apply(value, false); + myDataViewerPanel.apply(value, false, /* commandSource = */ null); myDataViewerPanel.setPreferredSize(JBUI.size(TABLE_DEFAULT_WIDTH, TABLE_DEFAULT_HEIGHT)); myMainPanel.add(myDataViewerPanel, createDataViewPanelConstraints()); diff --git a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.kt b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.kt index 66be15283be2..d6682750b323 100644 --- a/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.kt +++ b/python/src/com/jetbrains/python/debugger/containerview/PyDataViewerPanel.kt @@ -23,7 +23,6 @@ import com.jetbrains.python.debugger.* import com.jetbrains.python.debugger.array.AbstractDataViewTable import com.jetbrains.python.debugger.array.AsyncArrayTableModel import com.jetbrains.python.debugger.array.JBTableWithRowHeaders -import com.jetbrains.python.debugger.statistics.PyDataViewerCollector import java.awt.BorderLayout import java.awt.event.KeyAdapter import java.awt.event.KeyEvent @@ -35,13 +34,13 @@ import javax.swing.JPanel open class PyDataViewerPanel(@JvmField protected val project: Project, val frameAccessor: PyFrameAccessor) : JPanel(BorderLayout()), Disposable { - val sliceTextField: EditorTextField = createEditorField() + val sliceTextField: EditorTextField = createEditorField(TextFieldCommandSource.SLICING) protected val tablePanel = JPanel(BorderLayout()) protected var table: AbstractDataViewTable? = null - private var formatTextField: EditorTextField = createEditorField() + private var formatTextField: EditorTextField = createEditorField(TextFieldCommandSource.FORMATTING) private var colored: Boolean = PyDataView.isColoringEnabled(project) @@ -160,7 +159,7 @@ open class PyDataViewerPanel(@JvmField protected val project: Project, val frame return mainTable } - private fun createEditorField(): EditorTextField { + private fun createEditorField(commandSource: TextFieldCommandSource): EditorTextField { return object : EditorTextField(EditorFactory.getInstance().createDocument(""), project, PythonFileType.INSTANCE, false, true) { override fun createEditor(): EditorEx { val editor = super.createEditor() @@ -168,7 +167,7 @@ open class PyDataViewerPanel(@JvmField protected val project: Project, val frame editor.getContentComponent().addKeyListener(object : KeyAdapter() { override fun keyPressed(e: KeyEvent) { if (e.keyCode == KeyEvent.VK_ENTER) { - apply(sliceTextField.getText(), false) + apply(sliceTextField.getText(), false, commandSource) } } }) @@ -177,18 +176,14 @@ open class PyDataViewerPanel(@JvmField protected val project: Project, val frame } } - fun apply(name: String?, modifier: Boolean) { + fun apply(name: String?, modifier: Boolean, commandSource: TextFieldCommandSource? = null) { ApplicationManager.getApplication().executeOnPooledThread { val debugValue = getDebugValue(name, true, modifier) - ApplicationManager.getApplication().invokeLater { debugValue?.let { apply(it, modifier) } } - } - - if (!modifier) { - PyDataViewerCollector.SLICING_APPLIED_EVENT.log() + ApplicationManager.getApplication().invokeLater { debugValue?.let { apply(it, modifier, commandSource) } } } } - open fun apply(debugValue: PyDebugValue, modifier: Boolean) { + open fun apply(debugValue: PyDebugValue, modifier: Boolean, commandSource: TextFieldCommandSource? = null) { errorLabel.visible(false) val type = debugValue.type val strategy = DataViewStrategy.getStrategy(type) diff --git a/python/src/com/jetbrains/python/debugger/containerview/TextFieldCommandSource.kt b/python/src/com/jetbrains/python/debugger/containerview/TextFieldCommandSource.kt new file mode 100644 index 000000000000..6b19e6b6abba --- /dev/null +++ b/python/src/com/jetbrains/python/debugger/containerview/TextFieldCommandSource.kt @@ -0,0 +1,7 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.jetbrains.python.debugger.containerview + +enum class TextFieldCommandSource { + SLICING, + FORMATTING +} \ No newline at end of file diff --git a/python/src/com/jetbrains/python/debugger/statistics/PyDataViewerCollector.kt b/python/src/com/jetbrains/python/debugger/statistics/PyDataViewerCollector.kt index dc7743d3871e..4d4a4b5b22c8 100644 --- a/python/src/com/jetbrains/python/debugger/statistics/PyDataViewerCollector.kt +++ b/python/src/com/jetbrains/python/debugger/statistics/PyDataViewerCollector.kt @@ -9,15 +9,24 @@ import com.intellij.openapi.project.Project object PyDataViewerCollector : CounterUsagesCollector() { - private val GROUP = EventLogGroup("python.dataview", 3) + private val GROUP = EventLogGroup("python.dataview", 4) + /* Fields */ private val DATA_TYPE_FIELD = EventFields.Enum("type") private val DIMENSIONS_FIELD = EventFields.Enum("dimensions") private val ROWS_COUNT_FIELD = RoundedIntEventField("rows_count") private val COLUMNS_COUNT_FIELD = RoundedIntEventField("columns_count") + private val IS_NEW_TABLE_FIELD = EventFields.Boolean("is_new_table") - private val DATA_OPENED_EVENT = GROUP.registerVarargEvent("data.opened", DATA_TYPE_FIELD, DIMENSIONS_FIELD, ROWS_COUNT_FIELD, COLUMNS_COUNT_FIELD) - val SLICING_APPLIED_EVENT = GROUP.registerEvent("slicing.applied") + /* Events */ + private val DATA_OPENED_EVENT = GROUP.registerVarargEvent("data.opened", + DATA_TYPE_FIELD, + DIMENSIONS_FIELD, + ROWS_COUNT_FIELD, + COLUMNS_COUNT_FIELD, + IS_NEW_TABLE_FIELD) + val SLICING_APPLIED_EVENT = GROUP.registerEvent("slicing.applied", IS_NEW_TABLE_FIELD) + val FORMATTING_APPLIED_EVENT = GROUP.registerEvent("formatting.applied", IS_NEW_TABLE_FIELD) enum class DataType(private val typeName: String?) { ARRAY("ndarray"), @@ -61,11 +70,27 @@ object PyDataViewerCollector : CounterUsagesCollector() { override fun getGroup() = GROUP - fun logDataOpened(project: Project?, type: String?, dimensions: Int?, rowsCount: Int, columnsCount: Int) { + fun logDataOpened( + project: Project?, + type: String?, + dimensions: Int?, + rowsCount: Int, + columnsCount: Int, + isNewTable: Boolean, + ) { DATA_OPENED_EVENT.log(project, DATA_TYPE_FIELD.with(DataType.getDataType(type)), DIMENSIONS_FIELD.with(DataDimensions.getDataDimensions(dimensions)), ROWS_COUNT_FIELD.with(rowsCount), - COLUMNS_COUNT_FIELD.with(columnsCount)) + COLUMNS_COUNT_FIELD.with(columnsCount), + IS_NEW_TABLE_FIELD.with(isNewTable)) + } + + fun logDataSlicingApplied(isNewTable: Boolean) { + SLICING_APPLIED_EVENT.log(isNewTable) + } + + fun logDataFormattingApplied(isNewTable: Boolean) { + FORMATTING_APPLIED_EVENT.log(isNewTable) } } \ No newline at end of file