|
| 1 | +package com.shuzijun.leetcode.plugin.listener; |
| 2 | + |
| 3 | +import com.intellij.openapi.progress.ProgressIndicator; |
| 4 | +import com.intellij.openapi.progress.ProgressManager; |
| 5 | +import com.intellij.openapi.progress.Task; |
| 6 | +import com.intellij.openapi.project.Project; |
| 7 | +import com.shuzijun.leetcode.plugin.manager.CodeManager; |
| 8 | +import com.shuzijun.leetcode.plugin.model.PluginConstant; |
| 9 | +import com.shuzijun.leetcode.plugin.model.Question; |
| 10 | +import com.shuzijun.leetcode.plugin.window.NavigatorTable; |
| 11 | +import org.jetbrains.annotations.NotNull; |
| 12 | + |
| 13 | +import java.awt.event.KeyAdapter; |
| 14 | +import java.awt.event.KeyEvent; |
| 15 | + |
| 16 | +/** |
| 17 | + * @author shuzijun |
| 18 | + */ |
| 19 | +public class JTableKeyAdapter extends KeyAdapter { |
| 20 | + |
| 21 | + private NavigatorTable navigatorTable; |
| 22 | + private Project project; |
| 23 | + |
| 24 | + public JTableKeyAdapter(NavigatorTable navigatorTable, Project project) { |
| 25 | + this.navigatorTable = navigatorTable; |
| 26 | + this.project = project; |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public void keyTyped(KeyEvent e) { |
| 31 | + Question question = navigatorTable.getSelectedRowData(); |
| 32 | + if (question != null) { |
| 33 | + if (e.getKeyChar() == KeyEvent.VK_ENTER) { |
| 34 | + ProgressManager.getInstance().run(new Task.Backgroundable(project, PluginConstant.LEETCODE_EDITOR_OPEN_CODE, false) { |
| 35 | + @Override |
| 36 | + public void run(@NotNull ProgressIndicator progressIndicator) { |
| 37 | + CodeManager.openCode(question, project); |
| 38 | + } |
| 39 | + }); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | +} |
0 commit comments