Skip to content

add a search bar to the structure panel #266

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public final class KeyBinds {
public static final KeyBind EDITOR_RENAME = KeyBind.builder("rename", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_R).build();
public static final KeyBind EDITOR_PASTE = KeyBind.builder("paste", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_V).build();
public static final KeyBind EDITOR_EDIT_JAVADOC = KeyBind.builder("edit_javadoc", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_D).build();
public static final KeyBind EDITOR_SHOW_STRUCTURE = KeyBind.builder("show_structure", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_T).build();
public static final KeyBind EDITOR_SEARCH_STRUCTURE = KeyBind.builder("search_structure", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK).key(KeyEvent.VK_T).build();
public static final KeyBind EDITOR_SHOW_INHERITANCE = KeyBind.builder("show_inheritance", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_I).build();
public static final KeyBind EDITOR_SHOW_IMPLEMENTATIONS = KeyBind.builder("show_implementations", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_M).build();
public static final KeyBind EDITOR_SHOW_CALLS = KeyBind.builder("show_calls", EDITOR_CATEGORY).mod(InputEvent.CTRL_DOWN_MASK).key(KeyEvent.VK_C).build();
Expand Down Expand Up @@ -64,14 +66,15 @@ public final class KeyBinds {
EDITOR_EDIT_JAVADOC, EDITOR_SHOW_INHERITANCE, EDITOR_SHOW_IMPLEMENTATIONS, EDITOR_SHOW_CALLS,
EDITOR_SHOW_CALLS_SPECIFIC, EDITOR_OPEN_ENTRY, EDITOR_OPEN_PREVIOUS, EDITOR_OPEN_NEXT,
EDITOR_TOGGLE_MAPPING, EDITOR_ZOOM_IN, EDITOR_ZOOM_OUT, EDITOR_CLOSE_TAB, EDITOR_RELOAD_CLASS,
EDITOR_QUICK_FIND, SAVE_MAPPINGS, DROP_MAPPINGS, RELOAD_MAPPINGS, RELOAD_ALL, MAPPING_STATS,
SEARCH, SEARCH_ALL, SEARCH_CLASS, SEARCH_METHOD, SEARCH_FIELD).map(KeyBind::toImmutable).toList();
EDITOR_QUICK_FIND, EDITOR_SHOW_STRUCTURE, EDITOR_SEARCH_STRUCTURE, SAVE_MAPPINGS, DROP_MAPPINGS,
RELOAD_MAPPINGS, RELOAD_ALL, MAPPING_STATS, SEARCH, SEARCH_ALL, SEARCH_CLASS, SEARCH_METHOD, SEARCH_FIELD).map(KeyBind::toImmutable).toList();

private static final List<KeyBind> CONFIGURABLE_KEY_BINDS = List.of(EDITOR_RENAME, EDITOR_PASTE, EDITOR_EDIT_JAVADOC,
EDITOR_SHOW_INHERITANCE, EDITOR_SHOW_IMPLEMENTATIONS, EDITOR_SHOW_CALLS, EDITOR_SHOW_CALLS_SPECIFIC,
EDITOR_OPEN_ENTRY, EDITOR_OPEN_PREVIOUS, EDITOR_OPEN_NEXT, EDITOR_TOGGLE_MAPPING, EDITOR_ZOOM_IN,
EDITOR_ZOOM_OUT, EDITOR_CLOSE_TAB, EDITOR_RELOAD_CLASS, SAVE_MAPPINGS, DROP_MAPPINGS, RELOAD_MAPPINGS,
RELOAD_ALL, MAPPING_STATS, SEARCH, SEARCH_ALL, SEARCH_CLASS, SEARCH_METHOD, SEARCH_FIELD);
EDITOR_ZOOM_OUT, EDITOR_CLOSE_TAB, EDITOR_RELOAD_CLASS, EDITOR_SHOW_STRUCTURE, EDITOR_SEARCH_STRUCTURE,
SAVE_MAPPINGS, DROP_MAPPINGS, RELOAD_MAPPINGS, RELOAD_ALL, MAPPING_STATS, SEARCH, SEARCH_ALL, SEARCH_CLASS,
SEARCH_METHOD, SEARCH_FIELD);
// Editing entries in CONFIGURABLE_KEY_BINDS directly wouldn't allow to revert the changes instead of saving
private static List<KeyBind> editableKeyBinds;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.quiltmc.enigma.api.analysis.tree.StructureTreeNode;
import org.quiltmc.enigma.api.analysis.tree.StructureTreeOptions;
import org.quiltmc.enigma.gui.Gui;
import org.quiltmc.enigma.gui.config.Config;
import org.quiltmc.enigma.gui.panel.EditorPanel;
import org.quiltmc.enigma.gui.config.keybind.KeyBinds;
import org.quiltmc.enigma.gui.renderer.StructureOptionListCellRenderer;
Expand All @@ -19,13 +20,16 @@
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.border.LineBorder;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
Expand All @@ -34,10 +38,12 @@
public class StructureDocker extends Docker {
private final JPanel optionsPanel;

private final JLabel searchLabel = new JLabel();
private final JLabel obfuscationVisibilityLabel = new JLabel();
private final JLabel documentationVisibilityLabel = new JLabel();
private final JLabel sortingOrderLabel = new JLabel();

private final JTextArea searchBar;
private final JComboBox<StructureTreeOptions.ObfuscationVisibility> obfuscationVisibility;
private final JComboBox<StructureTreeOptions.DocumentationVisibility> documentationVisibility;
private final JComboBox<StructureTreeOptions.SortingOrder> sortingOrder;
Expand All @@ -51,23 +57,35 @@ public StructureDocker(Gui gui) {

GridBagConstraintsBuilder cb = GridBagConstraintsBuilder.create().insets(5).fill(GridBagConstraints.HORIZONTAL);

this.optionsPanel.add(this.obfuscationVisibilityLabel, cb.pos(0, 0).build());
this.optionsPanel.add(this.searchLabel, cb.pos(0, 0).build());
this.searchBar = new JTextArea();
this.searchBar.setBorder(new LineBorder(Config.currentTheme().getSyntaxPaneColors().delimiter.value()));
this.searchBar.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
super.keyTyped(e);
StructureDocker.this.updateStructure(gui.getActiveEditor());
}
});
this.optionsPanel.add(this.searchBar, cb.pos(1, 0).build());

this.optionsPanel.add(this.obfuscationVisibilityLabel, cb.pos(0, 1).build());
this.obfuscationVisibility = new JComboBox<>(StructureTreeOptions.ObfuscationVisibility.values());
this.obfuscationVisibility.setRenderer(new StructureOptionListCellRenderer());
this.obfuscationVisibility.addActionListener(event -> this.updateStructure(gui.getActiveEditor()));
this.optionsPanel.add(this.obfuscationVisibility, cb.pos(1, 0).build());
this.optionsPanel.add(this.obfuscationVisibility, cb.pos(1, 1).build());

this.optionsPanel.add(this.documentationVisibilityLabel, cb.pos(0, 1).build());
this.optionsPanel.add(this.documentationVisibilityLabel, cb.pos(0, 2).build());
this.documentationVisibility = new JComboBox<>(StructureTreeOptions.DocumentationVisibility.values());
this.documentationVisibility.setRenderer(new StructureOptionListCellRenderer());
this.documentationVisibility.addActionListener(event -> this.updateStructure(gui.getActiveEditor()));
this.optionsPanel.add(this.documentationVisibility, cb.pos(1, 1).build());
this.optionsPanel.add(this.documentationVisibility, cb.pos(1, 2).build());

this.optionsPanel.add(this.sortingOrderLabel, cb.pos(0, 2).build());
this.optionsPanel.add(this.sortingOrderLabel, cb.pos(0, 3).build());
this.sortingOrder = new JComboBox<>(StructureTreeOptions.SortingOrder.values());
this.sortingOrder.setRenderer(new StructureOptionListCellRenderer());
this.sortingOrder.addActionListener(event -> this.updateStructure(gui.getActiveEditor()));
this.optionsPanel.add(this.sortingOrder, cb.pos(1, 2).build());
this.optionsPanel.add(this.sortingOrder, cb.pos(1, 3).build());

this.structureTree = new JTree();
this.structureTree.setModel(null);
Expand Down Expand Up @@ -110,6 +128,14 @@ public void updateStructure(EditorPanel editor) {
this.structureTree.setSelectionRow(this.structureTree.getRowForPath(path));
}

public void focusSearch() {
this.searchBar.requestFocus();
}

public void focusTree() {
this.structureTree.requestFocus();
}

private void onKeyPress(KeyEvent e) {
if (KeyBinds.SELECT.matches(e)) {
this.navigateToSelectedNode();
Expand Down Expand Up @@ -143,13 +169,15 @@ private StructureTreeOptions getOptions() {
return new StructureTreeOptions(
(StructureTreeOptions.ObfuscationVisibility) this.obfuscationVisibility.getSelectedItem(),
(StructureTreeOptions.DocumentationVisibility) this.documentationVisibility.getSelectedItem(),
(StructureTreeOptions.SortingOrder) this.sortingOrder.getSelectedItem()
(StructureTreeOptions.SortingOrder) this.sortingOrder.getSelectedItem(),
this.searchBar.getText()
);
}

@Override
public void retranslateUi() {
super.retranslateUi();
this.searchLabel.setText(I18n.translate("menu.search"));
this.obfuscationVisibilityLabel.setText(I18n.translate("structure.options.obfuscation"));
this.documentationVisibilityLabel.setText(I18n.translate("structure.options.documentation"));
this.sortingOrderLabel.setText(I18n.translate("structure.options.sorting"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.quiltmc.enigma.gui.Gui;
import org.quiltmc.enigma.gui.GuiController;
import org.quiltmc.enigma.gui.config.keybind.KeyBinds;
import org.quiltmc.enigma.gui.docker.StructureDocker;
import org.quiltmc.enigma.gui.panel.EditorPanel;
import org.quiltmc.enigma.gui.util.GuiUtil;
import org.quiltmc.enigma.api.translation.representation.entry.ClassEntry;
Expand All @@ -24,6 +25,8 @@ public class EditorPopupMenu {
private final JMenuItem renameItem = new JMenuItem();
private final JMenuItem pasteItem = new JMenuItem();
private final JMenuItem editJavadocItem = new JMenuItem();
private final JMenuItem showStructureItem = new JMenuItem();
private final JMenuItem searchStructureItem = new JMenuItem();
private final JMenuItem showInheritanceItem = new JMenuItem();
private final JMenuItem showImplementationsItem = new JMenuItem();
private final JMenuItem showCallsItem = new JMenuItem();
Expand Down Expand Up @@ -52,6 +55,8 @@ public EditorPopupMenu(EditorPanel editor, Gui gui) {
this.ui.add(this.showImplementationsItem);
this.ui.add(this.showCallsItem);
this.ui.add(this.showCallsSpecificItem);
this.ui.add(this.showStructureItem);
this.ui.add(this.searchStructureItem);
this.ui.add(this.openEntryItem);
this.ui.add(this.openPreviousItem);
this.ui.add(this.openNextItem);
Expand All @@ -76,6 +81,14 @@ public EditorPopupMenu(EditorPanel editor, Gui gui) {
this.renameItem.addActionListener(event -> gui.startRename(editor));
this.pasteItem.addActionListener(event -> gui.startRename(editor, GuiUtil.getClipboard()));
this.editJavadocItem.addActionListener(event -> gui.startDocChange(editor));
this.showStructureItem.addActionListener(event -> {
gui.openDocker(StructureDocker.class);
gui.getDockerManager().getDocker(StructureDocker.class).focusTree();
});
this.searchStructureItem.addActionListener(event -> {
gui.openDocker(StructureDocker.class);
gui.getDockerManager().getDocker(StructureDocker.class).focusSearch();
});
this.showInheritanceItem.addActionListener(event -> gui.showInheritance(editor));
this.showImplementationsItem.addActionListener(event -> gui.showImplementations(editor));
this.showCallsItem.addActionListener(event -> gui.showCalls(editor, true));
Expand All @@ -93,6 +106,8 @@ public void setKeyBinds() {
this.renameItem.setAccelerator(KeyBinds.EDITOR_RENAME.toKeyStroke());
this.pasteItem.setAccelerator(KeyBinds.EDITOR_PASTE.toKeyStroke());
this.editJavadocItem.setAccelerator(KeyBinds.EDITOR_EDIT_JAVADOC.toKeyStroke());
this.showStructureItem.setAccelerator(KeyBinds.EDITOR_SHOW_STRUCTURE.toKeyStroke());
this.searchStructureItem.setAccelerator(KeyBinds.EDITOR_SEARCH_STRUCTURE.toKeyStroke());
this.showInheritanceItem.setAccelerator(KeyBinds.EDITOR_SHOW_INHERITANCE.toKeyStroke());
this.showImplementationsItem.setAccelerator(KeyBinds.EDITOR_SHOW_IMPLEMENTATIONS.toKeyStroke());
this.showCallsItem.setAccelerator(KeyBinds.EDITOR_SHOW_CALLS.toKeyStroke());
Expand Down Expand Up @@ -142,6 +157,12 @@ public boolean handleKeyEvent(KeyEvent event) {
} else if (KeyBinds.EDITOR_PASTE.matches(event)) {
this.pasteItem.doClick();
return true;
} else if (KeyBinds.EDITOR_SEARCH_STRUCTURE.matches(event)) {
this.searchStructureItem.doClick();
return true;
} else if (KeyBinds.EDITOR_SHOW_STRUCTURE.matches(event)) {
this.showStructureItem.doClick();
return true;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public void load(EnigmaProject project, StructureTreeOptions options) {
childNode.load(project, options);
}

this.add(childNode);
String search = options.searchString().strip().toLowerCase();
if ((child instanceof ClassEntry) || (search.isBlank() || childNode.toString().toLowerCase().contains(search))) {
this.add(childNode);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public record StructureTreeOptions(
ObfuscationVisibility obfuscationVisibility,
DocumentationVisibility documentationVisibility,
SortingOrder sortingOrder) {
SortingOrder sortingOrder,
String searchString) {
public enum ObfuscationVisibility implements Option {
ALL("structure.options.obfuscation.all"),
OBFUSCATED("structure.options.obfuscation.obfuscated"),
Expand Down