From c8802dfca308f84149335d8abc6abe46b070c0f9 Mon Sep 17 00:00:00 2001 From: smklimenko Date: Mon, 19 Aug 2024 20:10:41 +0100 Subject: [PATCH] 5.9.0: 2024.2 --- CHANGELOG.md | 6 +- .../java/org/kdb/inside/brains/UIUtils.java | 16 +++++ .../brains/view/console/KdbConsolePanel.java | 70 ++++++++++++------- .../console/table/TabsDockingManager.java | 11 ++- .../view/console/table/TabsDragSession.java | 15 ++++ .../view/console/table/TabsTableResult.java | 25 +++++-- 6 files changed, 105 insertions(+), 38 deletions(-) create mode 100644 src/main/java/org/kdb/inside/brains/view/console/table/TabsDragSession.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 053fc31..b66d7a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ ### Changed -- Idea 2024.2 added into the supporting list +- Idea 2024.2 added into the supporting list with deprecated code refactoring + +### Fixed + +- Context menu for TableResult is visible now ## [5.8.3] diff --git a/src/main/java/org/kdb/inside/brains/UIUtils.java b/src/main/java/org/kdb/inside/brains/UIUtils.java index 870d84e..3cc0c4f 100644 --- a/src/main/java/org/kdb/inside/brains/UIUtils.java +++ b/src/main/java/org/kdb/inside/brains/UIUtils.java @@ -17,12 +17,15 @@ import com.intellij.ui.components.JBTextField; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; +import com.intellij.ui.tabs.TabInfo; +import com.intellij.util.ui.ImageUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.event.DocumentEvent; import java.awt.*; import java.awt.event.KeyEvent; +import java.awt.image.BufferedImage; import java.util.function.Consumer; import java.util.function.Predicate; @@ -119,6 +122,19 @@ public static void createNameDialog(Project project, String title, String curren } } + public static Image getTabInfoImage(TabInfo info) { + final JComponent component = info.getComponent(); + if (component.isShowing()) { + var width = component.getWidth(); + var height = component.getHeight(); + var image = ImageUtil.createImage(component.getGraphicsConfiguration(), width > 0 ? width : 500, height > 0 ? height : 500, BufferedImage.TYPE_INT_ARGB); + component.paint(image.createGraphics()); + return image; + } else { + return ImageUtil.createImage(component.getGraphicsConfiguration(), 500, 500, BufferedImage.TYPE_INT_ARGB); + } + } + private static JBPopup createPopupNameDialog(Project project, String title, String currentName, InputValidator validator, Consumer action) { final JBTextField textField = new JBTextField(20); textField.setText(currentName); diff --git a/src/main/java/org/kdb/inside/brains/view/console/KdbConsolePanel.java b/src/main/java/org/kdb/inside/brains/view/console/KdbConsolePanel.java index 81e8007..6f17780 100644 --- a/src/main/java/org/kdb/inside/brains/view/console/KdbConsolePanel.java +++ b/src/main/java/org/kdb/inside/brains/view/console/KdbConsolePanel.java @@ -101,6 +101,7 @@ public class KdbConsolePanel extends KdbToolWindowPanel implements DataProvider, private final KdbSettingsService settingsService; private boolean scrollToTheEnd = true; + private boolean changeSplittingEvent = false; public static final DataKey TAB_INFO_DATA_KEY = DataKey.create("KdbConsole.TabInfo"); public KdbConsolePanel(Project project, InstanceConnection connection, ConsoleSplitType splitType, Consumer panelKillerConsumer) { @@ -125,15 +126,11 @@ public KdbConsolePanel(Project project, InstanceConnection connection, ConsoleSp connectionManager = KdbConnectionManager.getManager(project); connectionManager.addConnectionListener(connectionListener); - consoleTabs = JBTabsFactory.createTabs(project, this); - watchesSplitter = createWatchesSplitter(); - mainSplitter = createTabsSplitter(); - setContent(mainSplitter); -// mainSplitter.setFirstComponent(consoleTabs.getComponent()); - consoleTab = createConsoleTab(); + consoleTabs = JBTabsFactory.createTabs(project, this); + resultTabs = new TabsTableResult(project, this); resultTabs.addListener(new DockContainer.Listener() { @Override @@ -147,8 +144,10 @@ public void contentRemoved(@NotNull Object key) { } }, this); - resultTabs.showConsole(consoleTab); - mainSplitter.setSecondComponent(resultTabs); + mainSplitter = createTabsSplitter(); +// mainSplitter.setSecondComponent(resultTabs); +// mainSplitter.setFirstComponent(consoleTabs.getComponent()); + setContent(mainSplitter); changeSplitting(splitType); @@ -406,27 +405,48 @@ private void invalidateSplitting() { } private void changeSplitting(ConsoleSplitType type) { - if (type == ConsoleSplitType.NO) { - if (mainSplitter.getFirstComponent() != null) { - consoleTabs.removeTab(consoleTab); - resultTabs.showConsole(consoleTab); - mainSplitter.setFirstComponent(null); - } - } else { - if (mainSplitter.getFirstComponent() == null) { - resultTabs.hideConsole(); - consoleTabs.addTab(consoleTab); - mainSplitter.setFirstComponent(consoleTabs.getComponent()); - } + if (changeSplittingEvent) { + return; + } + + changeSplittingEvent = true; + try { + if (type == ConsoleSplitType.NO) { + if (activeSplitType != ConsoleSplitType.NO) { + consoleTabs.removeTab(consoleTab); + resultTabs.showConsole(consoleTab); + + // remove first, when add to the new one + mainSplitter.setFirstComponent(null); + mainSplitter.setSecondComponent(resultTabs); + } + } else { + if (activeSplitType != type) { + resultTabs.hideConsole(); + consoleTabs.addTab(consoleTab); + + final JComponent consoleComponent = consoleTabs.getComponent(); + mainSplitter.setFirstComponent(consoleComponent); + mainSplitter.setSecondComponent(resultTabs.isEmpty() ? null : resultTabs); - mainSplitter.setSecondComponent(resultTabs.getTabCount() == 0 ? null : resultTabs); + final boolean verticalSplit = type == ConsoleSplitType.DOWN; + if (mainSplitter.getOrientation() != verticalSplit) { + mainSplitter.setOrientation(verticalSplit); + } + } - final boolean verticalSplit = type == ConsoleSplitType.DOWN; - if (mainSplitter.getOrientation() != verticalSplit) { - mainSplitter.setOrientation(verticalSplit); + final boolean empty = resultTabs.isEmpty(); + final JComponent secondComponent = mainSplitter.getSecondComponent(); + if (empty && secondComponent != null) { + mainSplitter.setSecondComponent(null); + } else if (!empty && secondComponent == null) { + mainSplitter.setSecondComponent(resultTabs); + } } + activeSplitType = type; + } finally { + changeSplittingEvent = false; } - activeSplitType = type; } private void loadBinaryFile() { diff --git a/src/main/java/org/kdb/inside/brains/view/console/table/TabsDockingManager.java b/src/main/java/org/kdb/inside/brains/view/console/table/TabsDockingManager.java index 79d79cb..d3cdc2c 100644 --- a/src/main/java/org/kdb/inside/brains/view/console/table/TabsDockingManager.java +++ b/src/main/java/org/kdb/inside/brains/view/console/table/TabsDockingManager.java @@ -18,7 +18,6 @@ import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.ui.docking.DockContainer; import com.intellij.ui.docking.DockableContent; -import com.intellij.ui.docking.DragSession; import com.intellij.util.IconUtil; import com.intellij.util.ui.ImageUtil; import com.intellij.util.ui.UIUtil; @@ -49,7 +48,7 @@ final class TabsDockingManager implements Disposable { private final Set myContainers = new HashSet<>(); private final Map containerToWindow = new HashMap<>(); private int myWindowIdCounter = 1; - private MyDragSession myCurrentDragSession; + private MyTabsDragSession myCurrentDragSession; private final BusyObject.Impl myBusyObject = new BusyObject.Impl() { @Override public boolean isReady() { @@ -70,7 +69,7 @@ public void register(@NotNull DockContainer container, @NotNull Disposable paren Disposer.register(parentDisposable, () -> myContainers.remove(container)); } - public DragSession createDragSession(MouseEvent mouseEvent, @NotNull DockableContent content) { + public TabsDragSession createDragSession(MouseEvent mouseEvent, @NotNull DockableContent content) { stopCurrentDragSession(); for (DockContainer each : getContainers()) { @@ -82,7 +81,7 @@ public DragSession createDragSession(MouseEvent mouseEvent, @NotNull DockableCon } } - myCurrentDragSession = new MyDragSession(mouseEvent, content); + myCurrentDragSession = new MyTabsDragSession(mouseEvent, content); return myCurrentDragSession; } @@ -207,7 +206,7 @@ public void dispose() { containerToWindow.clear(); } - private final class MyDragSession implements DragSession { + private final class MyTabsDragSession implements TabsDragSession { private final JDialog myWindow; private final Image myDefaultDragImage; private final DockableContent myContent; @@ -216,7 +215,7 @@ private final class MyDragSession implements DragSession { private Image myDragImage; private DockContainer myCurrentOverContainer; - private MyDragSession(MouseEvent me, @NotNull DockableContent content) { + private MyTabsDragSession(MouseEvent me, @NotNull DockableContent content) { myWindow = new JDialog(UIUtil.getWindow(me.getComponent())); myWindow.setUndecorated(true); myContent = content; diff --git a/src/main/java/org/kdb/inside/brains/view/console/table/TabsDragSession.java b/src/main/java/org/kdb/inside/brains/view/console/table/TabsDragSession.java new file mode 100644 index 0000000..75a713d --- /dev/null +++ b/src/main/java/org/kdb/inside/brains/view/console/table/TabsDragSession.java @@ -0,0 +1,15 @@ +package org.kdb.inside.brains.view.console.table; + +import com.intellij.ui.docking.DockContainer; +import org.jetbrains.annotations.NotNull; + +import java.awt.event.MouseEvent; + +public interface TabsDragSession { + @NotNull + DockContainer.ContentResponse getResponse(MouseEvent e); + + void process(MouseEvent e); + + void cancel(); +} diff --git a/src/main/java/org/kdb/inside/brains/view/console/table/TabsTableResult.java b/src/main/java/org/kdb/inside/brains/view/console/table/TabsTableResult.java index e288b85..3ccf46d 100644 --- a/src/main/java/org/kdb/inside/brains/view/console/table/TabsTableResult.java +++ b/src/main/java/org/kdb/inside/brains/view/console/table/TabsTableResult.java @@ -14,9 +14,7 @@ import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.ui.docking.DockContainer; import com.intellij.ui.docking.DockableContent; -import com.intellij.ui.docking.DragSession; import com.intellij.ui.tabs.*; -import com.intellij.ui.tabs.impl.JBTabsImpl; import com.intellij.util.ui.GraphicsUtil; import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.JBUI; @@ -59,7 +57,7 @@ public TabsTableResult(Project project, Disposable parent) { tabs = (JBTabsEx) JBTabsFactory.createTabs(project, this); // We can't use Supplier here as it's been Getter before and some versions are not compatiable anymore. - tabs.setPopupGroup(createTabsPopup(), "KdbConsoleTabsMenu", true); + tabs.setPopupGroup(this::createTabsPopup, "KdbConsoleTabsMenu", true); renameAction = new RenameTabAction(); @@ -368,6 +366,7 @@ private TabInfo createResultTabInfo(String name, TableResult tableResult, TableM return createResultTabInfo(name, tableResultView); } + public static class TableResultContent implements DockableContent { private final Image myImg; private final TabInfo tabInfo; @@ -375,8 +374,8 @@ public static class TableResultContent implements DockableContent { private final Dimension myPreferredSize; TableResultContent(TabInfo info) { - myImg = JBTabsImpl.getComponentImage(info); tabInfo = info; + myImg = UIUtils.getTabInfoImage(info); myPresentation = new Presentation(info.getText()); myPresentation.setIcon(info.getIcon()); @@ -384,6 +383,7 @@ public static class TableResultContent implements DockableContent { myPreferredSize = info.getComponent().getSize(); } + @NotNull @Override public TabInfo getKey() { @@ -421,9 +421,14 @@ public RenameTabAction() { registerCustomShortcutSet(KeyEvent.VK_R, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK, tabs.getComponent()); } + @Override + public void update(@NotNull AnActionEvent e) { + e.getPresentation().setVisible(tabs.getTargetInfo() != null); + } + @Override public void actionPerformed(@NotNull AnActionEvent e) { - final TabInfo info = tabs.getTargetInfo(); + final TabInfo info = isEnabled(); if (info == null) { return; } @@ -436,6 +441,14 @@ public void actionPerformed(@NotNull AnActionEvent e) { } }); } + + private @Nullable TabInfo isEnabled() { + final TabInfo info = tabs.getTargetInfo(); + if (info == null || info == consoleTab) { + return null; + } + return info; + } } private class MyDropAreaPainter extends AbstractPainter { @@ -495,7 +508,7 @@ private Insets getTabsInsets() { } private class MyDragOutDelegate implements TabInfo.DragOutDelegate { - private DragSession mySession; + private TabsDragSession mySession; @Override public void dragOutStarted(@NotNull MouseEvent mouseEvent, @NotNull TabInfo info) {