Skip to content

Commit 1e3f631

Browse files
Quick find tool bar (#304)
* use local syntaxpain version convert EnigmaQuickFindDialog to EnigmaQuickFindToolBar add an EnigmaQuickFindToolBar as a child in EditorPanel - EditorPanel keybinds are useable with quickfind open - quickfind doesn't cover any part of EditorPanel's editor * add KeyBinds.QUICK_FIND_DIALOG_CLOSE retranslate EditorPanel's EnigmaQuickFindToolBar implement EnigmaQuickFindToolBar translation (copied from old QuickFindDialog::translate) add QuickFindDialog persistentCheckBox and closeButton * make EnigmaQuickFindToolBar.persistentCheckBox selected state persistent * keep EnigmaQuickFindToolBar.persistentCheckBox in sync with Config.persistentEditorQuickFind * make EDITOR_QUICK_FIND keybind configurable * checkstyle * syntaxpain version 0.2.0 * appease the villainous grammar checker Co-authored-by: ix0rai <[email protected]> --------- Co-authored-by: ix0rai <[email protected]>
1 parent 3c2224e commit 1e3f631

File tree

10 files changed

+209
-86
lines changed

10 files changed

+209
-86
lines changed

enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/Config.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.quiltmc.enigma.gui.config.theme.properties.NoneThemeProperties;
2424
import org.quiltmc.enigma.gui.config.theme.properties.SystemThemeProperties;
2525
import org.quiltmc.enigma.gui.config.theme.properties.composite.SyntaxPaneProperties;
26-
import org.quiltmc.enigma.gui.dialog.EnigmaQuickFindDialog;
2726
import org.quiltmc.enigma.util.I18n;
2827
import org.quiltmc.syntaxpain.SyntaxpainConfiguration;
2928

@@ -78,6 +77,9 @@ public final class Config extends ReflectiveConfig {
7877
@Comment("You shouldn't enable options in this section unless you know what you're doing!")
7978
public final DevSection development = new DevSection();
8079

80+
@Comment("Whether editors' quick find toolbars should remain visible when they lose focus.")
81+
public final TrackedValue<Boolean> persistentEditorQuickFind = this.value(true);
82+
8183
/**
8284
* The look and feel stored in the config: do not use this unless setting! Use {@link #activeThemeChoice} instead,
8385
* since look and feel is final once loaded.
@@ -252,7 +254,8 @@ public static void updateSyntaxpain() {
252254
SyntaxPaneProperties.Colors colors = getCurrentSyntaxPaneColors();
253255

254256
SyntaxpainConfiguration.setEditorFont(fonts.editor.value());
255-
SyntaxpainConfiguration.setQuickFindDialogFactory(EnigmaQuickFindDialog::new);
257+
// disable dialog; EditorPanel uses a tool bar component instead
258+
SyntaxpainConfiguration.setQuickFindDialogFactory(null);
256259

257260
SyntaxpainConfiguration.setLineRulerPrimaryColor(colors.lineNumbersForeground.value());
258261
SyntaxpainConfiguration.setLineRulerSecondaryColor(colors.lineNumbersBackground.value());

enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBind.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void setFrom(KeyBind other) {
4949
}
5050

5151
/**
52-
* Prefer using component's {@link InputMap}s and {@link ActionMap}s to checking this in {@link KeyListener}s.
52+
* Prefer using components' {@link InputMap}s and {@link ActionMap}s to checking this in {@link KeyListener}s.
5353
*
5454
* @see GuiUtil#putKeyBindAction(KeyBind, JComponent, GuiUtil.FocusCondition, ActionListener)
5555
*/

enigma-swing/src/main/java/org/quiltmc/enigma/gui/config/keybind/KeyBinds.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public final class KeyBinds {
2626
public static final KeyBind QUICK_FIND_DIALOG_WRAP = KeyBind.builder("wrap", QUICK_FIND_DIALOG_CATEGORY).key(KeyEvent.VK_W).build();
2727
public static final KeyBind QUICK_FIND_DIALOG_NEXT = KeyBind.builder("next", QUICK_FIND_DIALOG_CATEGORY).key(KeyEvent.VK_ENTER).build();
2828
public static final KeyBind QUICK_FIND_DIALOG_PREVIOUS = KeyBind.builder("previous", QUICK_FIND_DIALOG_CATEGORY).mod(InputEvent.SHIFT_DOWN_MASK).key(KeyEvent.VK_ENTER).build();
29+
public static final KeyBind QUICK_FIND_DIALOG_CLOSE = KeyBind.builder("close_quick_find", QUICK_FIND_DIALOG_CATEGORY).key(KeyEvent.VK_ESCAPE).build();
2930
public static final KeyBind SEARCH_DIALOG_NEXT = KeyBind.builder("next", SEARCH_DIALOG_CATEGORY).key(KeyEvent.VK_DOWN).build();
3031
public static final KeyBind SEARCH_DIALOG_PREVIOUS = KeyBind.builder("previous", SEARCH_DIALOG_CATEGORY).key(KeyEvent.VK_UP).build();
3132

@@ -63,7 +64,7 @@ public final class KeyBinds {
6364
public static final KeyBind SEARCH_FIELD = KeyBind.builder("search_field", MENU_CATEGORY).build();
6465

6566
private static final List<KeyBind> DEFAULT_KEY_BINDS = Stream.of(EXIT, SELECT, DIALOG_SAVE, MULTILINE_DIALOG_SAVE,
66-
QUICK_FIND_DIALOG_NEXT, QUICK_FIND_DIALOG_PREVIOUS, SEARCH_DIALOG_NEXT, SEARCH_DIALOG_PREVIOUS,
67+
QUICK_FIND_DIALOG_NEXT, QUICK_FIND_DIALOG_PREVIOUS, QUICK_FIND_DIALOG_CLOSE, SEARCH_DIALOG_NEXT, SEARCH_DIALOG_PREVIOUS,
6768
EDITOR_RENAME, EDITOR_PASTE, EDITOR_EDIT_JAVADOC, EDITOR_SHOW_INHERITANCE, EDITOR_SHOW_IMPLEMENTATIONS,
6869
EDITOR_SHOW_CALLS, EDITOR_SHOW_CALLS_SPECIFIC, EDITOR_OPEN_ENTRY, EDITOR_OPEN_PREVIOUS, EDITOR_OPEN_NEXT,
6970
EDITOR_TOGGLE_MAPPING, EDITOR_ZOOM_IN, EDITOR_ZOOM_OUT, EDITOR_CLOSE_TAB, EDITOR_RELOAD_CLASS,
@@ -73,9 +74,10 @@ public final class KeyBinds {
7374
private static final List<KeyBind> CONFIGURABLE_KEY_BINDS = List.of(EDITOR_RENAME, EDITOR_PASTE, EDITOR_EDIT_JAVADOC,
7475
EDITOR_SHOW_INHERITANCE, EDITOR_SHOW_IMPLEMENTATIONS, EDITOR_SHOW_CALLS, EDITOR_SHOW_CALLS_SPECIFIC,
7576
EDITOR_OPEN_ENTRY, EDITOR_OPEN_PREVIOUS, EDITOR_OPEN_NEXT, EDITOR_TOGGLE_MAPPING, EDITOR_ZOOM_IN,
76-
EDITOR_ZOOM_OUT, EDITOR_CLOSE_TAB, EDITOR_RELOAD_CLASS, EDITOR_SHOW_STRUCTURE, EDITOR_SEARCH_STRUCTURE,
77-
SAVE_MAPPINGS, DROP_MAPPINGS, RELOAD_MAPPINGS, RELOAD_ALL, MAPPING_STATS, SEARCH, SEARCH_ALL, SEARCH_CLASS,
78-
SEARCH_METHOD, SEARCH_FIELD);
77+
EDITOR_ZOOM_OUT, EDITOR_CLOSE_TAB, EDITOR_RELOAD_CLASS, EDITOR_QUICK_FIND, EDITOR_SHOW_STRUCTURE,
78+
EDITOR_SEARCH_STRUCTURE, SAVE_MAPPINGS, DROP_MAPPINGS, RELOAD_MAPPINGS, RELOAD_ALL, MAPPING_STATS, SEARCH,
79+
SEARCH_ALL, SEARCH_CLASS, SEARCH_METHOD, SEARCH_FIELD
80+
);
7981
// Editing entries in CONFIGURABLE_KEY_BINDS directly wouldn't allow to revert the changes instead of saving
8082
private static List<KeyBind> editableKeyBinds;
8183

enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/EnigmaQuickFindDialog.java

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright 2008 Ayman Al-Sairafi [email protected]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
14+
package org.quiltmc.enigma.gui.dialog;
15+
16+
import org.quiltmc.enigma.gui.config.Config;
17+
import org.quiltmc.enigma.gui.config.keybind.KeyBinds;
18+
import org.quiltmc.enigma.gui.util.GuiUtil;
19+
import org.quiltmc.enigma.gui.util.GuiUtil.FocusCondition;
20+
import org.quiltmc.enigma.util.I18n;
21+
import org.quiltmc.syntaxpain.QuickFindToolBar;
22+
23+
import javax.swing.Box;
24+
import javax.swing.JButton;
25+
import javax.swing.JCheckBox;
26+
import javax.swing.SwingConstants;
27+
28+
import static org.quiltmc.enigma.gui.util.GuiUtil.putKeyBindAction;
29+
30+
/**
31+
* Extension of {@link QuickFindToolBar} to allow using keybindings, and improve UI.
32+
*/
33+
public class EnigmaQuickFindToolBar extends QuickFindToolBar {
34+
protected JCheckBox persistentCheckBox;
35+
protected JButton closeButton;
36+
37+
public EnigmaQuickFindToolBar() {
38+
super();
39+
// keybinding support
40+
this.reloadKeyBinds();
41+
42+
// configure parent components
43+
this.ignoreCaseCheckBox.setMnemonic(KeyBinds.QUICK_FIND_DIALOG_IGNORE_CASE.getKeyCode());
44+
this.regexCheckBox.setMnemonic(KeyBinds.QUICK_FIND_DIALOG_REGEX.getKeyCode());
45+
this.wrapCheckBox.setMnemonic(KeyBinds.QUICK_FIND_DIALOG_WRAP.getKeyCode());
46+
47+
// make buttons icon-only
48+
this.nextButton.setText("");
49+
this.nextButton.setIcon(GuiUtil.getDownChevron());
50+
this.prevButton.setText("");
51+
this.prevButton.setIcon(GuiUtil.getUpChevron());
52+
53+
// add custom components
54+
// push the rest of the components to the right
55+
this.add(Box.createHorizontalGlue());
56+
57+
this.addSeparator();
58+
59+
this.persistentCheckBox = new JCheckBox();
60+
this.persistentCheckBox.setFocusable(false);
61+
this.persistentCheckBox.setOpaque(false);
62+
this.persistentCheckBox.setVerticalTextPosition(SwingConstants.BOTTOM);
63+
this.persistentCheckBox.setHorizontalTextPosition(SwingConstants.LEADING);
64+
this.persistentCheckBox.addActionListener(this);
65+
this.persistentCheckBox.addItemListener(e -> {
66+
final boolean selected = this.persistentCheckBox.isSelected();
67+
if (selected != Config.main().persistentEditorQuickFind.value()) {
68+
Config.main().persistentEditorQuickFind.setValue(selected);
69+
}
70+
71+
// request focus so when it's lost this may be dismissed
72+
this.requestFocus();
73+
});
74+
this.persistentCheckBox.setSelected(Config.main().persistentEditorQuickFind.value());
75+
Config.main().persistentEditorQuickFind.registerCallback(callback -> {
76+
final Boolean configured = callback.value();
77+
if (this.persistentCheckBox.isSelected() != configured) {
78+
this.persistentCheckBox.setSelected(configured);
79+
}
80+
});
81+
this.add(this.persistentCheckBox);
82+
83+
this.addSeparator();
84+
85+
this.closeButton = new JButton();
86+
this.closeButton.setIcon(GuiUtil.getCloseIcon());
87+
this.closeButton.setFocusable(false);
88+
this.closeButton.setOpaque(false);
89+
this.closeButton.addActionListener(e -> this.dismiss());
90+
this.add(this.closeButton);
91+
92+
this.translate();
93+
}
94+
95+
@Override
96+
protected boolean dismissOnFocusLost() {
97+
return !this.persistentCheckBox.isSelected();
98+
}
99+
100+
public void translate() {
101+
this.notFound = I18n.translate("editor.quick_find.not_found");
102+
103+
this.ignoreCaseCheckBox.setText(I18n.translate("editor.quick_find.ignore_case"));
104+
this.regexCheckBox.setText(I18n.translate("editor.quick_find.use_regex"));
105+
this.wrapCheckBox.setText(I18n.translate("editor.quick_find.wrap"));
106+
107+
this.persistentCheckBox.setText(I18n.translate("editor.quick_find.persistent"));
108+
}
109+
110+
public void reloadKeyBinds() {
111+
putKeyBindAction(KeyBinds.QUICK_FIND_DIALOG_PREVIOUS, this.searchField, e -> this.prevButton.doClick());
112+
putKeyBindAction(KeyBinds.QUICK_FIND_DIALOG_NEXT, this.searchField, e -> this.nextButton.doClick());
113+
putKeyBindAction(
114+
KeyBinds.QUICK_FIND_DIALOG_CLOSE, this, FocusCondition.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
115+
e -> this.setVisible(false)
116+
);
117+
}
118+
}

enigma-swing/src/main/java/org/quiltmc/enigma/gui/panel/ClosableTabTitlePane.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import javax.swing.JPanel;
99
import javax.swing.JTabbedPane;
1010
import javax.swing.SwingUtilities;
11-
import javax.swing.UIManager;
1211
import javax.swing.border.EmptyBorder;
1312
import javax.swing.event.ChangeListener;
1413
import java.awt.Component;
@@ -39,7 +38,7 @@ public ClosableTabTitlePane(String title, String tooltip, Runnable onClose) {
3938
this.closeButton.setFocusPainted(false);
4039
this.closeButton.setFocusable(false);
4140
this.closeButton.setOpaque(true);
42-
this.closeButton.setIcon(UIManager.getIcon("InternalFrame.closeIcon"));
41+
this.closeButton.setIcon(GuiUtil.getCloseIcon());
4342
this.closeButton.putClientProperty("paintActive", Boolean.TRUE);
4443
this.closeButton.setBorder(new EmptyBorder(0, 0, 0, 0));
4544
this.closeButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, "Close");

0 commit comments

Comments
 (0)