Skip to content

Commit

Permalink
5.9.0: 2024.2
Browse files Browse the repository at this point in the history
  • Loading branch information
smklimenko committed Aug 19, 2024
1 parent 499ef50 commit c8802df
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 38 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/kdb/inside/brains/UIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> action) {
final JBTextField textField = new JBTextField(20);
textField.setText(currentName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TabInfo> TAB_INFO_DATA_KEY = DataKey.create("KdbConsole.TabInfo");

public KdbConsolePanel(Project project, InstanceConnection connection, ConsoleSplitType splitType, Consumer<KdbConsolePanel> panelKillerConsumer) {
Expand All @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +48,7 @@ final class TabsDockingManager implements Disposable {
private final Set<DockContainer> myContainers = new HashSet<>();
private final Map<DockContainer, DockWindow> 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() {
Expand All @@ -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()) {
Expand All @@ -82,7 +81,7 @@ public DragSession createDragSession(MouseEvent mouseEvent, @NotNull DockableCon
}
}

myCurrentDragSession = new MyDragSession(mouseEvent, content);
myCurrentDragSession = new MyTabsDragSession(mouseEvent, content);
return myCurrentDragSession;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -368,22 +366,24 @@ private TabInfo createResultTabInfo(String name, TableResult tableResult, TableM
return createResultTabInfo(name, tableResultView);
}


public static class TableResultContent implements DockableContent<TabInfo> {
private final Image myImg;
private final TabInfo tabInfo;
private final Presentation myPresentation;
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());

myPreferredSize = info.getComponent().getSize();
}


@NotNull
@Override
public TabInfo getKey() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c8802df

Please sign in to comment.