Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvement for mod elements list D&D logic #4842

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Path2D;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

class JSelectableListMouseListenerWithDND<T> extends MousePressListener {
class JSelectableListMouseListenerWithDND<T> extends MouseAdapter {

@Nullable private Point srcPoint = new Point(); // when null, we are in dnd

Expand All @@ -60,6 +61,7 @@ public void stopDNDAction() {
list.setCursor(null);
if (list.additionalDNDComponent != null)
list.additionalDNDComponent.setCursor(null);
selection = null;
finalDNDselection = null;
}

Expand Down Expand Up @@ -121,8 +123,6 @@ public void stopDNDAction() {
System.arraycopy(curr, 0, indices, selNew.length, curr.length);
list.setSelectedIndices(indices);
list.repaint();

selection = indices;
}
}

Expand All @@ -146,19 +146,15 @@ public void stopDNDAction() {
}

stopDNDAction();
selection = list.getSelectedIndices();
}
}

@Override public void pressFiltered(MouseEvent e, int clicks) {
if (clicks == 2 && list.dndCustom) {
@Override public void mousePressed(MouseEvent e) {
if (list.dndCustom && selection != null && Arrays.stream(selection)
.anyMatch(i -> list.getCellBounds(i, i).contains(e.getPoint()))) {
srcPoint = null; // Initiate DND action
} else if (clicks == 1 && list.dndCustom) {
if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
selection = list.getSelectedIndices();
} else {
selection = null; // If only one click, reset the DND selection candidates
}
} else if (clicks == 0) {
} else {
int index = list.locationToIndex(e.getPoint());
Rectangle rect = list.getCellBounds(index, index);
if (rect != null && rect.contains(e.getPoint())) {
Expand All @@ -171,7 +167,7 @@ public void stopDNDAction() {
} else {
list.setFocusable(false);
}
srcPoint = new Point();
srcPoint = new Point(); // Enter selection mode
srcPoint.setLocation(e.getPoint());
list.repaint();
}
Expand Down
48 changes: 0 additions & 48 deletions src/main/java/net/mcreator/ui/component/MousePressListener.java

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/java/net/mcreator/ui/workspace/WorkspacePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ public void switchFolder(FolderElement switchTo) {
search.setText(null); // clear the search bar
currentFolder = switchTo;

list.cancelDND();

sectionTabs.get("mods").reloadElements();

// reload breadcrumb
Expand Down