From 2f10e835d0e55bbb3d738fb045aa5ce0205299aa Mon Sep 17 00:00:00 2001 From: smklimenko Date: Mon, 25 Mar 2024 22:47:15 +0000 Subject: [PATCH] 5.5.2 --- CHANGELOG.md | 12 ++ gradle.properties | 4 +- .../inside/brains/core/KdbScopesManager.java | 2 +- .../lang/binding/EditorsBindingListener.java | 34 ++++++ .../lang/binding/EditorsBindingService.java | 105 +++++++++++------- .../brains/settings/KdbSettingsService.java | 15 --- .../brains/view/console/ConsoleOptions.java | 15 +-- src/main/resources/META-INF/plugin.xml | 5 + version.properties | 2 +- 9 files changed, 121 insertions(+), 73 deletions(-) create mode 100644 src/main/java/org/kdb/inside/brains/lang/binding/EditorsBindingListener.java diff --git a/CHANGELOG.md b/CHANGELOG.md index f04c0e9..e58ec6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # KdbInsideBrains Changelog +## [5.5.2] + +### Fixed + +- Floating point precision sessions lost at unclear conditions (precision settings will be lost if you are updateding + from any version before 5.4) +- Tabs binding doesn't work in NewUI + +### Added + +- Editors to connection binding stored in settings now + ## [5.5.1] ### Fixed diff --git a/gradle.properties b/gradle.properties index 1909fe4..d7ed27d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,11 +10,11 @@ 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.4 +pluginVerifierVersions=2022.3, 2022.3.3, 2023.1.1, 2023.2.5, 2023.3.6 platformType=IC #platformVersion=241-EAP-SNAPSHOT #platformPlugins=java, PsiViewer:241-SNAPSHOT -platformVersion=2023.3.4 +platformVersion=2023.3.6 platformPlugins=java, PsiViewer:233.2 #platformVersion=2023.2.5 #platformPlugins=java, PsiViewer:232.2 diff --git a/src/main/java/org/kdb/inside/brains/core/KdbScopesManager.java b/src/main/java/org/kdb/inside/brains/core/KdbScopesManager.java index a06e8fb..bd79036 100644 --- a/src/main/java/org/kdb/inside/brains/core/KdbScopesManager.java +++ b/src/main/java/org/kdb/inside/brains/core/KdbScopesManager.java @@ -115,7 +115,7 @@ public KdbInstance lookupInstance(String canonicalName) { } private InstanceItem lookupInstance(String canonicalName, InstanceItem item) { - if (canonicalName.equals(item.getCanonicalName())) { + if (item.getCanonicalName().equals(canonicalName)) { return item; } if (item instanceof StructuralItem si) { diff --git a/src/main/java/org/kdb/inside/brains/lang/binding/EditorsBindingListener.java b/src/main/java/org/kdb/inside/brains/lang/binding/EditorsBindingListener.java new file mode 100644 index 0000000..1e2f6cd --- /dev/null +++ b/src/main/java/org/kdb/inside/brains/lang/binding/EditorsBindingListener.java @@ -0,0 +1,34 @@ +package org.kdb.inside.brains.lang.binding; + +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.FileEditorManagerEvent; +import com.intellij.openapi.fileEditor.FileEditorManagerListener; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; + +public class EditorsBindingListener implements FileEditorManagerListener { + private final EditorsBindingService service; + + public EditorsBindingListener(Project project) { + service = project.getService(EditorsBindingService.class); + } + + @Override + public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile file) { + service.editorOpened(file); + } + + @Override + public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { + service.editorClosed(file); + } + + @Override + public void selectionChanged(@NotNull FileEditorManagerEvent event) { + final VirtualFile newFile = event.getNewFile(); + if (newFile != null) { + service.editorActivated(newFile); + } + } +} diff --git a/src/main/java/org/kdb/inside/brains/lang/binding/EditorsBindingService.java b/src/main/java/org/kdb/inside/brains/lang/binding/EditorsBindingService.java index 39b56eb..69d5140 100644 --- a/src/main/java/org/kdb/inside/brains/lang/binding/EditorsBindingService.java +++ b/src/main/java/org/kdb/inside/brains/lang/binding/EditorsBindingService.java @@ -1,13 +1,15 @@ package org.kdb.inside.brains.lang.binding; import com.intellij.openapi.Disposable; -import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.fileEditor.FileEditorManagerEvent; -import com.intellij.openapi.fileEditor.FileEditorManagerListener; +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.messages.MessageBusConnection; +import com.intellij.openapi.vfs.VirtualFileManager; +import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.kdb.inside.brains.core.*; import org.kdb.inside.brains.settings.KdbSettingsListener; import org.kdb.inside.brains.settings.KdbSettingsService; @@ -17,7 +19,8 @@ import java.util.Map; import java.util.Objects; -public class EditorsBindingService implements Disposable { +@State(name = "EditorsBinding", storages = {@Storage(value = "kdb-settings.xml")}) +public class EditorsBindingService implements Disposable, PersistentStateComponent { private boolean disposed; private VirtualFile activeFile; @@ -25,25 +28,24 @@ public class EditorsBindingService implements Disposable { private EditorsBindingStrategy strategy; + private final Project project; + private final Map connections = new HashMap<>(); + private final KdbSettingsService settingsService; - private final MessageBusConnection busConnection; private final KdbConnectionManager connectionManager; - private final Map connections = new HashMap<>(); - private final TheSettingsListener settingsListener = new TheSettingsListener(); private final TheConnectionListener connectionListener = new TheConnectionListener(); public EditorsBindingService(Project project) { + this.project = project; + connectionManager = KdbConnectionManager.getManager(project); connectionManager.addConnectionListener(connectionListener); settingsService = KdbSettingsService.getInstance(); settingsService.addSettingsListener(settingsListener); strategy = settingsService.getExecutionOptions().getBindingStrategy(); - - busConnection = project.getMessageBus().connect(this); - busConnection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new TheFileEditorManagerListener()); } public void toggleBinding(boolean bind) { @@ -51,11 +53,7 @@ public void toggleBinding(boolean bind) { return; } - if (bind) { - connections.put(activeFile, activeInstance); - } else { - connections.remove(activeFile); - } + changeInstance(activeFile, bind ? activeInstance : null); } public boolean isBindable() { @@ -75,24 +73,30 @@ public void dispose() { disposed = true; settingsService.removeSettingsListener(settingsListener); connectionManager.removeConnectionListener(connectionListener); - busConnection.disconnect(); connections.clear(); } + protected void editorOpened(@NotNull VirtualFile file) { + if (disposed) { + return; + } + + editorActivated(file); + } - private void editorClosed(@NotNull VirtualFile file) { + protected void editorClosed(@NotNull VirtualFile file) { if (disposed) { return; } - connections.remove(file); + changeInstance(file, null); if (Objects.equals(activeFile, file)) { activeFile = null; } } - private void editorActivated(@NotNull VirtualFile file) { + protected void editorActivated(@NotNull VirtualFile file) { if (disposed) { return; } @@ -103,7 +107,7 @@ private void editorActivated(@NotNull VirtualFile file) { if (instance != null) { connectionManager.activate(instance); } else if (activeInstance != null && strategy == EditorsBindingStrategy.TAB_TO_CONNECT) { - connections.put(activeFile, activeInstance); + changeInstance(activeFile, activeInstance); } } @@ -115,14 +119,48 @@ private void instanceActivated(KdbInstance activated) { activeInstance = activated; if (activeFile != null && strategy == EditorsBindingStrategy.CONNECT_TO_TAB) { - if (activated == null) { - connections.remove(activeFile); - } else { - connections.put(activeFile, activeInstance); + changeInstance(activeFile, activeInstance); + } + } + + @Override + public @Nullable Element getState() { + final Element e = new Element("bindings"); + for (Map.Entry entry : connections.entrySet()) { + e.addContent(new Element("binding").setAttribute("url", entry.getKey().getUrl()).setAttribute("instance", entry.getValue().getCanonicalName())); + } + return e; + } + + @Override + public void loadState(@NotNull Element state) { + final KdbScopesManager scopesManager = KdbScopesManager.getManager(project); + final VirtualFileManager fileManager = VirtualFileManager.getInstance(); + for (Element child : state.getChildren()) { + final String url = child.getAttributeValue("url"); + final String inst = child.getAttributeValue("instance"); + if (url == null || inst == null) { + continue; + } + final VirtualFile vf = fileManager.findFileByUrl(url); + if (vf == null || !vf.exists()) { + continue; } + final KdbInstance instance = scopesManager.lookupInstance(inst); + if (instance == null) { + continue; + } + connections.put(vf, instance); } } + private void changeInstance(VirtualFile file, KdbInstance instance) { + if (instance == null) { + connections.remove(file); + } else { + connections.put(file, instance); + } + } private class TheSettingsListener implements KdbSettingsListener { @Override @@ -134,25 +172,10 @@ public void settingsChanged(KdbSettingsService service, SettingsBean bean) { } } - private class TheFileEditorManagerListener implements FileEditorManagerListener { - @Override - public void selectionChanged(@NotNull FileEditorManagerEvent event) { - final VirtualFile newFile = event.getNewFile(); - if (newFile != null) { - editorActivated(newFile); - } - } - - @Override - public void fileClosed(@NotNull FileEditorManager source, @NotNull VirtualFile file) { - editorClosed(file); - } - } - private class TheConnectionListener implements KdbConnectionListener { @Override public void connectionActivated(InstanceConnection deactivated, InstanceConnection activated) { instanceActivated(activated == null ? null : activated.getInstance()); } } -} +} \ No newline at end of file diff --git a/src/main/java/org/kdb/inside/brains/settings/KdbSettingsService.java b/src/main/java/org/kdb/inside/brains/settings/KdbSettingsService.java index 71288f1..0e528cc 100644 --- a/src/main/java/org/kdb/inside/brains/settings/KdbSettingsService.java +++ b/src/main/java/org/kdb/inside/brains/settings/KdbSettingsService.java @@ -6,7 +6,6 @@ import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; -import com.intellij.util.xmlb.annotations.Transient; import org.jetbrains.annotations.Nullable; import org.kdb.inside.brains.core.ExecutionOptions; import org.kdb.inside.brains.core.InstanceOptions; @@ -157,11 +156,6 @@ public void loadState(State state) { myState.setCredentialPlugins(state.credentialPlugins); myState.setInspectorOptions(state.inspectorOptions); myState.setNumericalOptions(state.numericalOptions); - - // Legacy migration. To be removed one day - if (state.legacyConsoleOptions.floatPrecision != -1) { - myState.numericalOptions.setFloatPrecision(state.legacyConsoleOptions.floatPrecision); - } } public static KdbSettingsService getInstance() { @@ -171,10 +165,6 @@ public static KdbSettingsService getInstance() { return instance; } - private static final class LegacyConsoleOptions { - private int floatPrecision; - } - public static class State { private final List credentialPlugins = new ArrayList<>(); private final ChartOptions chartOptions = new ChartOptions(); @@ -185,10 +175,6 @@ public static class State { private final InspectorOptions inspectorOptions = new InspectorOptions(); private final NumericalOptions numericalOptions = new NumericalOptions(); - @Transient - // Collection of all legacy options for migration copied from other options - private final LegacyConsoleOptions legacyConsoleOptions = new LegacyConsoleOptions(); - public List getCredentialPlugins() { return credentialPlugins; } @@ -214,7 +200,6 @@ public ConsoleOptions getConsoleOptions() { public void setConsoleOptions(ConsoleOptions consoleOptions) { this.consoleOptions.copyFrom(consoleOptions); - legacyConsoleOptions.floatPrecision = consoleOptions.getLegacyFloatPrecision(); } public InstanceOptions getInstanceOptions() { diff --git a/src/main/java/org/kdb/inside/brains/view/console/ConsoleOptions.java b/src/main/java/org/kdb/inside/brains/view/console/ConsoleOptions.java index 2b57c09..ab3c801 100644 --- a/src/main/java/org/kdb/inside/brains/view/console/ConsoleOptions.java +++ b/src/main/java/org/kdb/inside/brains/view/console/ConsoleOptions.java @@ -1,6 +1,5 @@ package org.kdb.inside.brains.view.console; -import com.intellij.util.xmlb.annotations.Property; import org.kdb.inside.brains.settings.SettingsBean; import java.util.Objects; @@ -15,16 +14,6 @@ public final class ConsoleOptions implements SettingsBean { private boolean clearTableResult = true; private ConsoleSplitType splitType = ConsoleSplitType.NO; - @Property - @Deprecated(forRemoval = true) - private int floatPrecision = -1; - - public int getLegacyFloatPrecision() { - int asd = floatPrecision; - floatPrecision = -1; - return asd; - } - public boolean isWrapStrings() { return wrapStrings; } @@ -93,12 +82,12 @@ public void setClearTableResult(boolean clearTableResult) { public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ConsoleOptions that)) return false; - return floatPrecision == that.floatPrecision && wrapStrings == that.wrapStrings && prefixSymbols == that.prefixSymbols && enlistArrays == that.enlistArrays && dictAsTable == that.dictAsTable && listAsTable == that.listAsTable && consoleBackground == that.consoleBackground && clearTableResult == that.clearTableResult && splitType == that.splitType; + return wrapStrings == that.wrapStrings && prefixSymbols == that.prefixSymbols && enlistArrays == that.enlistArrays && dictAsTable == that.dictAsTable && listAsTable == that.listAsTable && consoleBackground == that.consoleBackground && clearTableResult == that.clearTableResult && splitType == that.splitType; } @Override public int hashCode() { - return Objects.hash(floatPrecision, wrapStrings, prefixSymbols, enlistArrays, dictAsTable, listAsTable, consoleBackground, clearTableResult, splitType); + return Objects.hash(wrapStrings, prefixSymbols, enlistArrays, dictAsTable, listAsTable, consoleBackground, clearTableResult, splitType); } @Override diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index c41eda5..e2aaed7 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -378,6 +378,11 @@ + + + + diff --git a/version.properties b/version.properties index 5cfc44b..6e40efc 100644 --- a/version.properties +++ b/version.properties @@ -1 +1 @@ -pluginVersion=5.5.1 \ No newline at end of file +pluginVersion=5.5.2 \ No newline at end of file