Skip to content

Commit 9c2d842

Browse files
committed
Find/Replace: display on top of the related Editor
If the editor is focused, acquire alwaysOnTop capabilities but drop them as soon as both the editor and the dialog are out of focus try to implement partial transparency As implemented in Notepad++, a partially transparent search/replace window could make it easier to interact with the editor (particularly in fullscreen contexts, when the "always on top" window could hide the search results). Unfortunately, Java can only apply the transparency to undecorated window, so it's a no-go. Java gurus, please come to the rescue :D Fix find/replace focus on Windows Probably this approach could be adopted by all OSes with a little care on the window lifecycle. [Find/Replace][Win] grab focus when just opened Solves #6951 (comment) Use Windows method for all OS
1 parent cda6bb7 commit 9c2d842

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Diff for: app/src/cc/arduino/view/findreplace/FindReplace.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.HashMap;
4444
import java.util.Map;
4545

46+
import static java.awt.GraphicsDevice.WindowTranslucency.*;
4647
import static processing.app.I18n.tr;
4748

4849
public class FindReplace extends javax.swing.JFrame {
@@ -58,6 +59,7 @@ public class FindReplace extends javax.swing.JFrame {
5859
public FindReplace(Editor editor, Map<String, Object> state) {
5960
this.editor = editor;
6061

62+
isTranslucencySupported();
6163
initComponents();
6264

6365
if (OSUtils.isMacOS()) {
@@ -70,16 +72,28 @@ public FindReplace(Editor editor, Map<String, Object> state) {
7072
}
7173

7274
Base.registerWindowCloseKeys(getRootPane(), e -> {
75+
setAutoRequestFocus(true);
7376
setVisible(false);
7477
Base.FIND_DIALOG_STATE = findDialogState();
7578
});
7679

7780
Base.setIcon(this);
7881

82+
editor.addWindowListener(new WindowAdapter() {
83+
public void windowActivated(WindowEvent e) {
84+
toFront();
85+
setAutoRequestFocus(false);
86+
}
87+
public void windowDeactivated(WindowEvent e) {
88+
return;
89+
}
90+
});
91+
7992
addWindowListener(new WindowAdapter() {
8093
public void windowActivated(WindowEvent e) {
81-
findField.requestFocusInWindow();
82-
findField.selectAll();
94+
return;
95+
}
96+
public void windowDeactivated(WindowEvent e) {
8397
}
8498
});
8599

@@ -89,10 +103,20 @@ public void windowActivated(WindowEvent e) {
89103
@Override
90104
public void setVisible(boolean b) {
91105
getRootPane().setDefaultButton(findButton);
92-
106+
// means we are restoring the window visibility
107+
setAutoRequestFocus(true);
93108
super.setVisible(b);
94109
}
95110

111+
private boolean useTranslucency;
112+
113+
private void isTranslucencySupported() {
114+
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
115+
GraphicsDevice gd = ge.getDefaultScreenDevice();
116+
//If translucent windows aren't supported, exit.
117+
useTranslucency = gd.isWindowTranslucencySupported(TRANSLUCENT);
118+
}
119+
96120
private Map<String, Object> findDialogState() {
97121
Map<String, Object> state = new HashMap<>();
98122
state.put(FIND_TEXT, findField.getText());

0 commit comments

Comments
 (0)