From feff5303b7bf82ea7a31a74146f12ab8520254c2 Mon Sep 17 00:00:00 2001 From: dzmipt Date: Fri, 26 Jan 2024 18:20:12 +0100 Subject: [PATCH] Line inspection for table result --- notes.md | 3 +- src/studio/ui/QGrid.java | 17 +++--- src/studio/ui/action/TableUserAction.java | 63 +++++++++++++++++------ 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/notes.md b/notes.md index c2a0e25e..95a8cd1d 100644 --- a/notes.md +++ b/notes.md @@ -1,4 +1,5 @@ -* New setting to disable insert of paired character into the editor +* Added line inspection (new popup menu in the table result) +* New setting to disable insert of paired character in the editor * Implement continuous search * Fixed the bug with sequential replace action in the editor diff --git a/src/studio/ui/QGrid.java b/src/studio/ui/QGrid.java index 1ace74e2..8ab9efd8 100755 --- a/src/studio/ui/QGrid.java +++ b/src/studio/ui/QGrid.java @@ -47,7 +47,8 @@ public int getRowCount() { private final JPopupMenu popupMenu = new JPopupMenu(); private final UserAction copyExcelFormatAction; private final UserAction copyHtmlFormatAction; - private final TableUserAction showSeparateAction; + private final TableUserAction inspectCellAction; + private final TableUserAction inspectLineAction; private long doubleClickTimeout; @@ -172,19 +173,21 @@ public void stateChanged(ChangeEvent ev) { setLayout(new BorderLayout()); add(scrollPane, BorderLayout.CENTER); - copyExcelFormatAction = UserAction.create("Copy (Excel format)", + copyExcelFormatAction = UserAction.create("Copy selection (Excel format)", Util.COPY_ICON,"Copy the selected cells to the clipboard using Excel format", KeyEvent.VK_E,null, new CopyTableSelectionAction(CopyTableSelectionAction.Format.Excel, table)); - copyHtmlFormatAction = UserAction.create("Copy (HTML)", + copyHtmlFormatAction = UserAction.create("Copy selection (HTML)", Util.COPY_ICON, "Copy the selected cells to the clipboard using HTML", KeyEvent.VK_H, null, new CopyTableSelectionAction(CopyTableSelectionAction.Format.Html, table)); - showSeparateAction = new TableUserAction.ShowSeparateAction(studioWindow, table); + inspectCellAction = new TableUserAction.InspectCellAction(studioWindow, table); + inspectLineAction = new TableUserAction.InspectLineAction(studioWindow, table); - popupMenu.add(showSeparateAction); + popupMenu.add(inspectCellAction); + popupMenu.add(inspectLineAction); popupMenu.add(new JMenuItem(copyExcelFormatAction)); popupMenu.add(new JMenuItem(copyHtmlFormatAction)); @@ -246,8 +249,8 @@ private void copy(int row, int col) { formatContextForCell.setShowType(b instanceof K.KBaseVector); Util.copyTextToClipboard(b.toString(formatContextForCell)); } else { - showSeparateAction.setLocation(row, col); - showSeparateAction.actionPerformed(null); + inspectCellAction.setLocation(row, col); + inspectCellAction.actionPerformed(null); } } }); diff --git a/src/studio/ui/action/TableUserAction.java b/src/studio/ui/action/TableUserAction.java index 12d95c20..30417181 100644 --- a/src/studio/ui/action/TableUserAction.java +++ b/src/studio/ui/action/TableUserAction.java @@ -11,11 +11,17 @@ public abstract class TableUserAction extends UserAction { - protected int col = -1; - protected int row = -1; + protected final StudioWindow studioWindow; + protected final JTable table; - public TableUserAction(String text, Icon icon, String desc, Integer mnemonic, KeyStroke key) { + private int col = -1; + private int row = -1; + + public TableUserAction(StudioWindow studioWindow, JTable table, + String text, Icon icon, String desc, Integer mnemonic, KeyStroke key) { super(text, icon, desc, mnemonic, key); + this.studioWindow = studioWindow; + this.table = table; } public void setLocation(int row, int col) { @@ -23,27 +29,50 @@ public void setLocation(int row, int col) { this.col = col; } - public static class ShowSeparateAction extends TableUserAction { + protected int getRow() { + return row == -1 ? table.getSelectedRow() : row; + } + + protected int getColumn() { + return col == -1 ? table.getSelectedColumn() : col; + } - private final StudioWindow studioWindow; - private final JTable table; - public ShowSeparateAction(StudioWindow studioWindow, JTable table) { - super("To separate tab", Util.BLANK_ICON, "Show in a separate tab", + public static class InspectCellAction extends TableUserAction { + public InspectCellAction(StudioWindow studioWindow, JTable table) { + super(studioWindow, table, "Inspect cell", Util.BLANK_ICON, "Show in a separate tab", KeyEvent.VK_S, null); - this.studioWindow = studioWindow; - this.table = table; } @Override public void actionPerformed(ActionEvent e) { - int aRow = row; - int aCol = col; - if (aRow == -1 || aCol == -1) { - aRow = table.getSelectedRow(); - aCol = table.getSelectedColumn(); - } + int aRow = getRow(); + int aCol = getColumn(); if (aRow == -1 || aCol == -1) return; - studioWindow.addResultTab(new QueryResult((K.KBase)table.getValueAt(aRow, aCol)), "an element from previous result"); + studioWindow.addResultTab(new QueryResult((K.KBase)table.getValueAt(aRow, aCol)), "a cell from previous result"); + } + } + + public static class InspectLineAction extends TableUserAction { + public InspectLineAction(StudioWindow studioWindow, JTable table) { + super(studioWindow, table, "Inspect line", Util.BLANK_ICON, "Show line as dictionary in a separate tab", + KeyEvent.VK_S, null); + } + + @Override + public void actionPerformed(ActionEvent e) { + int aRow = getRow(); + if (aRow == -1) return; + + int count = table.getColumnCount(); + String[] names = new String[count]; + K.KBase[] values = new K.KBase[count]; + for (int i = 0; i < count; i++) { + names[i] = table.getColumnName(i); + values[i] = (K.KBase) table.getValueAt(aRow, i); + } + + studioWindow.addResultTab(new QueryResult( + new K.Dict(new K.KSymbolVector(names), new K.KList(values))), "a line from previous result"); } } }