From d8407af5daa0f3ca607fed46e2ab056fb4f5b055 Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Thu, 6 Nov 2014 15:55:48 +0100 Subject: [PATCH] Fix reslice and reformat on enter. --- .../python/debugger/array/ArrayTableForm.java | 27 +++++++++-- .../debugger/array/NumpyArrayTable.java | 45 +++++++------------ 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/python/src/com/jetbrains/python/debugger/array/ArrayTableForm.java b/python/src/com/jetbrains/python/debugger/array/ArrayTableForm.java index 90b6d1c1b75c..f50f0161034f 100644 --- a/python/src/com/jetbrains/python/debugger/array/ArrayTableForm.java +++ b/python/src/com/jetbrains/python/debugger/array/ArrayTableForm.java @@ -15,6 +15,8 @@ */ package com.jetbrains.python.debugger.array; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.project.Project; import com.intellij.ui.EditorTextField; import com.intellij.ui.components.JBScrollPane; @@ -31,6 +33,7 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; import java.awt.*; +import java.awt.event.KeyListener; /** * @author amarch @@ -46,23 +49,41 @@ public class ArrayTableForm { private JTable myTable; private JBTable myBusyTable; private final Project myProject; + private KeyListener myResliceCallback; + private KeyListener myReformatCallback; private static final String DATA_LOADING_IN_PROCESS = "Please wait, load array data."; private static final String NOT_APPLICABLE = "View not applicable for "; - public ArrayTableForm(@NotNull Project project) { + public ArrayTableForm(@NotNull Project project, KeyListener resliceCallback, KeyListener reformatCallback) { myProject = project; + myResliceCallback = resliceCallback; + myReformatCallback = reformatCallback; } private void createUIComponents() { - mySliceTextField = new EditorTextField("", myProject, PythonFileType.INSTANCE); + mySliceTextField = new EditorTextField("", myProject, PythonFileType.INSTANCE) { + @Override + protected EditorEx createEditor() { + EditorEx editor = super.createEditor(); + editor.getContentComponent().addKeyListener(myResliceCallback); + return editor; + } + }; myTable = new JBTableWithRowHeaders(); myScrollPane = ((JBTableWithRowHeaders)myTable).getScrollPane(); - myFormatTextField = new EditorTextField("", myProject, PythonFileType.INSTANCE); + myFormatTextField = new EditorTextField("", myProject, PythonFileType.INSTANCE) { + @Override + protected EditorEx createEditor() { + EditorEx editor = super.createEditor(); + editor.getContentComponent().addKeyListener(myReformatCallback); + return editor; + } + }; myBusyTable = new JBTable(new DefaultTableModel()); myBusyTable.getEmptyText().setText(""); diff --git a/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java b/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java index 230e8c058974..dacf3d51a770 100644 --- a/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java +++ b/python/src/com/jetbrains/python/debugger/array/NumpyArrayTable.java @@ -19,6 +19,7 @@ import com.intellij.codeInsight.hint.HintManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; @@ -76,7 +77,21 @@ public class NumpyArrayTable { @NotNull PyViewArrayAction.ViewArrayDialog dialog, @NotNull PyDebugValue value) { myValue = value; myDialog = dialog; - myComponent = new ArrayTableForm(project); + myComponent = new ArrayTableForm(project, new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + doReslice(getSliceText(), null); + } + } + }, new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + doApplyFormat(); + } + } + }); myTable = myComponent.getTable(); myProject = project; myEvaluator = new PyDebuggerEvaluator(project, getDebugValue().getFrameAccessor()); @@ -127,9 +142,6 @@ public class NumpyArrayTable { }); } - // add slice actions - initSliceFieldActions(); - //make value name read-only myComponent.getSliceTextField().addFocusListener(new FocusListener() { @Override @@ -145,9 +157,6 @@ public class NumpyArrayTable { } } }); - - //add format actions - initFormatFieldActions(); } public void disableColor() { @@ -166,28 +175,6 @@ public class NumpyArrayTable { }); } - private void initSliceFieldActions() { - myComponent.getSliceTextField().addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - doReslice(getSliceText(), null); - } - } - }); - } - - private void initFormatFieldActions() { - myComponent.getFormatTextField().addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - doApplyFormat(); - } - } - }); - } - public PyDebugValue getDebugValue() { return myValue; }