Skip to content

Commit

Permalink
5.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
smklimenko committed Jun 26, 2024
1 parent 41f3d8c commit 9723b19
Show file tree
Hide file tree
Showing 19 changed files with 270 additions and 153 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# KdbInsideBrains Changelog

## [5.8.0]

### Added

- Execute Q File action added (mapped to Ctrl + Alt + F10 by default) that sends and executes content of whole file
till 'exit the script' command (\).

### Changed

- Execute action doesn't block reading thread now and runs in the background instead.

### Removed

- Execute On TP action removed. See no real use-case. Never used.

### Fixed

- Docking deprecation API resolved
- IDEA 2024 @ApiStatus.OverrideOnly issues resolved

## [5.7.1]

### Added
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pluginJavaVersion=17
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html for available build versions
# or https://jb.gg/intellij-platform-builds-list
pluginVerifierVersions=2022.3, 2022.3.3, 2023.1.1, 2023.2.5, 2023.3.6, 2024.1.2
pluginVerifierVersions=2022.3, 2022.3.3, 2023.1.1, 2023.2.5, 2023.3.6, 2024.1.4
platformType=IC
platformVersion=2024.1.2
platformVersion=2024.1.4
platformPlugins=java, PsiViewer:241-SNAPSHOT
#platformVersion=2023.3.6
#platformPlugins=java, PsiViewer:233.2
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/icons/KdbIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public static final class Instance {
public static final @NotNull Icon Execute = AllIcons.Actions.Execute;
public static final @NotNull Icon ExecuteOn = AllIcons.Actions.Expandall;
public static final @NotNull Icon ExecuteContext = load("/org/kdb/inside/brains/icons/executeContext.svg");
public static final @NotNull Icon QuickExecute = AllIcons.Debugger.EvaluateExpression;
public static final @NotNull Icon ExecuteQuick = AllIcons.Debugger.EvaluateExpression;
public static final @NotNull Icon ExecuteFile = load("/org/kdb/inside/brains/icons/executeFile.svg");

public static final @NotNull Icon Connected = load("/org/kdb/inside/brains/icons/connected.svg");
public static final @NotNull Icon Disconnected = load("/org/kdb/inside/brains/icons/disconnected.svg");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package org.kdb.inside.brains.action.execute;

import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.kdb.inside.brains.QFileType;
import org.kdb.inside.brains.action.ActionPlaces;
import org.kdb.inside.brains.action.BgtAction;
import org.kdb.inside.brains.core.InstanceConnection;
import org.kdb.inside.brains.core.KdbConnectionManager;
import org.kdb.inside.brains.view.console.KdbConsoleToolWindow;

public class ExecuteAction extends DumbAwareAction {
public class ExecuteAction extends BgtAction {
private final InstanceConnection myConnection;

public ExecuteAction() {
Expand All @@ -40,11 +43,14 @@ public static boolean isExecutedAllowed(AnActionEvent e) {
@Override
public void update(@NotNull AnActionEvent e) {
final Presentation presentation = e.getPresentation();
if (org.kdb.inside.brains.action.ActionPlaces.KEYBOARD_SHORTCUT.equals(e.getPlace())) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) {
presentation.setEnabled(false);
presentation.setVisible(false);
} else if (org.kdb.inside.brains.action.ActionPlaces.KEYBOARD_SHORTCUT.equals(e.getPlace())) {
presentation.setEnabled(true);
presentation.setVisible(false);
} else {

final boolean allowed = isExecutedAllowed(e);
if (ActionPlaces.MAIN_TOOLBAR.equals(e.getPlace()) || "popup".equals(e.getPlace())) {
presentation.setVisible(true);
Expand All @@ -63,32 +69,41 @@ public void update(@NotNull AnActionEvent e) {

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (editor == null || project == null) {
final DataContext context = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
return;
}

ReadAction.run(() -> {
final InstanceConnection connection = getConnection(project);
if (connection == null) {
return;
}
final String text = ReadAction.compute(() -> getExecutionContent(context));
if (text == null || text.isEmpty()) {
return;
}

final TextRange range = getExecutionRange(editor, dataContext);
if (range != null && !range.isEmpty()) {
execute(project, editor, connection, range);
}
});
final InstanceConnection connection = getConnection(project);
if (connection != null && connection.isConnected()) {
execute(project, connection, text, context);
}
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
protected String getExecutionContent(DataContext context) {
final Editor editor = CommonDataKeys.EDITOR.getData(context);
if (editor == null) {
return null;
}

final TextRange range = getExecutionRange(editor, context);
if (range != null && !range.isEmpty()) {
return editor.getDocument().getText(range);
}
return null;
}

protected TextRange getExecutionRange(Editor editor, DataContext context) {
if (editor == null) {
return null;
}

final CaretModel caretModel = editor.getCaretModel();

final SelectionModel selectionModel = editor.getSelectionModel();
Expand All @@ -108,7 +123,7 @@ protected TextRange getExecutionRange(Editor editor, DataContext context) {
return KdbConnectionManager.getManager(project).getActiveConnection();
}

protected void execute(Project project, Editor editor, InstanceConnection connection, TextRange range) {
KdbConsoleToolWindow.getInstance(project).execute(connection, editor.getDocument().getText(range));
protected void execute(Project project, InstanceConnection connection, String text, DataContext context) {
KdbConsoleToolWindow.getInstance(project).execute(connection, text);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.kdb.inside.brains.action.execute;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.kdb.inside.brains.QFileType;
import org.kdb.inside.brains.core.InstanceConnection;

public class ExecuteFileAction extends ExecuteAction {
public void update(@NotNull AnActionEvent e) {
final PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext());

final Presentation presentation = e.getPresentation();
presentation.setVisible(QFileType.is(file));

final InstanceConnection c = getConnection(e.getProject());
presentation.setEnabled(c != null && c.isConnected());

if (file != null) {
presentation.setText("Execute '" + file.getName() + "'");
}
}

@Override
protected String getExecutionContent(DataContext context) {
final PsiFile data = CommonDataKeys.PSI_FILE.getData(context);
if (!QFileType.is(data)) {
return null;
}
try {

final String text = data.getText();
// end of the file comment that we should exclude as it's parsed by KDB
final int i = getEndOfFileIndex(text);
return i < 0 ? text : text.substring(0, i);
} catch (Exception ex) {
return null;
}
}

private int getEndOfFileIndex(String text) {
final int i = text.indexOf("\\\r");
if (i < 0) {
return text.indexOf("\\\n");
}
return i;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.intellij.codeInsight.hint.HintManager;
import com.intellij.codeInsight.hint.HintManagerImpl;
import com.intellij.ide.TooltipEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.ui.HintHint;
import com.intellij.ui.JBColor;
import com.intellij.ui.LightweightHint;
Expand All @@ -25,7 +25,7 @@
import javax.swing.text.StyledDocument;
import java.awt.*;

public class ExecuteInlineAction extends ExecuteAction implements DumbAware {
public class ExecuteInlineAction extends ExecuteAction {
public static final Dimension MAX_SIZE = new Dimension(800, 500);

private TableResultView createTableHint(Project project, TableResult result) {
Expand Down Expand Up @@ -90,9 +90,10 @@ private void showTypedHint(JComponent c, Editor editor) {
}

@Override
protected void execute(Project project, Editor editor, InstanceConnection connection, TextRange range) {
protected void execute(Project project, InstanceConnection connection, String text, DataContext context) {
final Editor editor = CommonDataKeys.EDITOR.getData(context);
try {
final KdbQuery query = new KdbQuery(editor.getDocument().getText(range));
final KdbQuery query = new KdbQuery(text);
connection.query(query, res -> {
if (res.isError()) {
showTypedHint(createTextHint(((Exception) res.getObject()).getMessage(), true), editor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,16 @@ public InstancesList(JBTextField editor, Consumer<DataContext> selectionCallback
setEmptyText("Type an instance URI or search mask");
}

void setActionGroup(ActionGroup group) {
void setActionGroup(DefaultActionGroup group) {
captionItems.clear();
myLastSelectedIndex = -2;
myLastMouseLocation = null;
setSelectionModel(new SingleSelectionModel()); // clear selection model here

final List<AnAction> items = new ArrayList<>();
for (AnAction action : group.getChildren(null)) {
if (action instanceof ActionGroup actionGroup) {
final AnAction[] children = actionGroup.getChildren(null);
for (AnAction action : group.getChildActionsOrStubs()) {
if (action instanceof DefaultActionGroup actionGroup) {
final AnAction[] children = actionGroup.getChildActionsOrStubs();
if (children.length != 0) {
captionItems.put(children[0], actionGroup.getTemplatePresentation().getText());
for (int i = 0; i < children.length; i++) {
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/org/kdb/inside/brains/view/chart/BaseChartPanel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.kdb.inside.brains.view.chart;

import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.ui.JBColor;
Expand All @@ -23,17 +23,18 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.lang.reflect.Field;
import java.util.List;
import java.util.function.Supplier;

public class BaseChartPanel extends ChartPanel {
private final ChartOptions myOptions;
private boolean defaultCursor = false;

private final Supplier<ActionGroup> popupActionsProvider;
private final Supplier<List<ToolActions>> popupActionsProvider;

private static final JBColor COLOR_GRID = new JBColor(new Color(0xd3d3d4), new Color(0xd3d3d4));

public BaseChartPanel(ChartOptions options, Supplier<ActionGroup> popupActionsProvider) {
public BaseChartPanel(ChartOptions options, Supplier<List<ToolActions>> popupActionsProvider) {
super(null, false, false, false, false, false);
this.popupActionsProvider = popupActionsProvider;
myOptions = options;
Expand Down Expand Up @@ -143,11 +144,19 @@ private void initializeChart(JFreeChart chart) {

@Override
protected void displayPopupMenu(int x, int y) {
final ActionGroup group = popupActionsProvider.get();
if (group == null || group.getChildren(null).length == 0) {
final List<ToolActions> actions = popupActionsProvider.get();
if (actions.isEmpty()) {
return;
}

final DefaultActionGroup group = new DefaultActionGroup();
for (ToolActions action : actions) {
if (action.name() != null) {
group.addSeparator(action.name());
}
group.addAll(action.actions());
}

final ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, group, DataManager.getInstance().getDataContext(this), JBPopupFactory.ActionSelectionAid.MNEMONICS, true);
final Point p = new Point(x, y);
SwingUtilities.convertPointToScreen(p, this);
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/kdb/inside/brains/view/chart/ChartTool.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.kdb.inside.brains.view.chart;

import com.intellij.openapi.actionSystem.ActionGroup;
import org.jfree.chart.JFreeChart;
import org.kdb.inside.brains.KdbType;

Expand All @@ -13,7 +12,7 @@ public interface ChartTool {
void initialize(JFreeChart chart, KdbType domainType);


default ActionGroup getPopupActions() {
return ActionGroup.EMPTY_GROUP;
default ToolActions getToolActions() {
return ToolActions.NO_ACTIONS;
}
}
21 changes: 3 additions & 18 deletions src/main/java/org/kdb/inside/brains/view/chart/ChartingDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.io.OutputStream;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.intellij.util.ui.JBUI.Borders;

Expand Down Expand Up @@ -233,24 +234,8 @@ public void actionPerformed(@NotNull AnActionEvent e) {
return p;
}

private ActionGroup createPopupMenu() {
final DefaultActionGroup g = new DefaultActionGroup();
final List<ChartTool> crosshairTool = List.of(this.crosshairTool, measureTool, valuesTool);
for (ChartTool tool : crosshairTool) {
if (!tool.isEnabled()) {
continue;
}

final ActionGroup popupActions = tool.getPopupActions();
if (popupActions.getChildren(null).length != 0) {
final String templateText = popupActions.getTemplateText();
if (templateText != null) {
g.addSeparator(templateText);
}
g.addAll(popupActions);
}
}
return g;
private List<ToolActions> createPopupMenu() {
return Stream.of(crosshairTool, measureTool, valuesTool).filter(ChartTool::isEnabled).map(ChartTool::getToolActions).filter(ToolActions::hasActions).toList();
}

private JBTabs createTabs(Project project, ChartDataProvider dataProvider) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/kdb/inside/brains/view/chart/ToolActions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.kdb.inside.brains.view.chart;

import com.intellij.openapi.actionSystem.AnAction;

public record ToolActions(String name, AnAction... actions) {
public static final ToolActions NO_ACTIONS = new ToolActions(null);

public boolean hasActions() {
return actions.length != 0;
}
}
Loading

0 comments on commit 9723b19

Please sign in to comment.