Skip to content

Commit

Permalink
Line inspection for table result
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Jan 26, 2024
1 parent 404446b commit feff530
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 25 deletions.
3 changes: 2 additions & 1 deletion notes.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
17 changes: 10 additions & 7 deletions src/studio/ui/QGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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);
}
}
});
Expand Down
63 changes: 46 additions & 17 deletions src/studio/ui/action/TableUserAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,68 @@

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) {
this.row = row;
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");
}
}
}

0 comments on commit feff530

Please sign in to comment.